Igor Opaniuk | 309e65b | 2020-01-28 14:42:25 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright 2020 Toradex |
| 4 | */ |
| 5 | |
| 6 | #include <common.h> |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 7 | #include <command.h> |
Simon Glass | 2dc9c34 | 2020-05-10 11:40:01 -0600 | [diff] [blame] | 8 | #include <image.h> |
Simon Glass | 9758973 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 9 | #include <init.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 10 | #include <log.h> |
Igor Opaniuk | 309e65b | 2020-01-28 14:42:25 +0100 | [diff] [blame] | 11 | #include <asm/arch/clock.h> |
| 12 | #include <asm/arch/ddr.h> |
| 13 | #include <asm/arch/imx8mm_pins.h> |
| 14 | #include <asm/arch/sys_proto.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 15 | #include <asm/global_data.h> |
Igor Opaniuk | 309e65b | 2020-01-28 14:42:25 +0100 | [diff] [blame] | 16 | #include <asm/io.h> |
| 17 | #include <asm/mach-imx/boot_mode.h> |
| 18 | #include <asm/mach-imx/iomux-v3.h> |
| 19 | #include <cpu_func.h> |
| 20 | #include <dm/device.h> |
| 21 | #include <dm/device-internal.h> |
| 22 | #include <dm/uclass.h> |
| 23 | #include <dm/uclass-internal.h> |
| 24 | #include <hang.h> |
Max Krummenacher | 22c0133 | 2020-10-28 11:58:12 +0200 | [diff] [blame] | 25 | #include <i2c.h> |
Max Krummenacher | 22c0133 | 2020-10-28 11:58:12 +0200 | [diff] [blame] | 26 | #include <power/pca9450.h> |
Igor Opaniuk | 309e65b | 2020-01-28 14:42:25 +0100 | [diff] [blame] | 27 | #include <power/pmic.h> |
| 28 | #include <spl.h> |
| 29 | |
| 30 | DECLARE_GLOBAL_DATA_PTR; |
| 31 | |
Max Krummenacher | 22c0133 | 2020-10-28 11:58:12 +0200 | [diff] [blame] | 32 | #define I2C_PMIC_BUS_ID 1 |
| 33 | |
Igor Opaniuk | 309e65b | 2020-01-28 14:42:25 +0100 | [diff] [blame] | 34 | int spl_board_boot_device(enum boot_device boot_dev_spl) |
| 35 | { |
| 36 | switch (boot_dev_spl) { |
Marcel Ziswiler | 2b910a2 | 2022-08-22 15:06:02 +0200 | [diff] [blame^] | 37 | case MMC1_BOOT: /* eMMC */ |
Igor Opaniuk | 309e65b | 2020-01-28 14:42:25 +0100 | [diff] [blame] | 38 | return BOOT_DEVICE_MMC1; |
Marcel Ziswiler | 2b910a2 | 2022-08-22 15:06:02 +0200 | [diff] [blame^] | 39 | case SD2_BOOT: /* SD card */ |
Igor Opaniuk | 309e65b | 2020-01-28 14:42:25 +0100 | [diff] [blame] | 40 | case MMC2_BOOT: |
| 41 | return BOOT_DEVICE_MMC2; |
Igor Opaniuk | 309e65b | 2020-01-28 14:42:25 +0100 | [diff] [blame] | 42 | case USB_BOOT: |
| 43 | return BOOT_DEVICE_BOARD; |
| 44 | default: |
| 45 | return BOOT_DEVICE_NONE; |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | void spl_dram_init(void) |
| 50 | { |
| 51 | ddr_init(&dram_timing); |
| 52 | } |
| 53 | |
| 54 | void spl_board_init(void) |
| 55 | { |
Marcel Ziswiler | 295528b | 2022-08-22 15:06:01 +0200 | [diff] [blame] | 56 | if (IS_ENABLED(CONFIG_FSL_CAAM)) { |
| 57 | struct udevice *dev; |
| 58 | int ret; |
| 59 | |
| 60 | ret = uclass_get_device_by_driver(UCLASS_MISC, DM_DRIVER_GET(caam_jr), &dev); |
| 61 | if (ret) |
| 62 | printf("Failed to initialize %s: %d\n", dev->name, ret); |
| 63 | } |
| 64 | |
Igor Opaniuk | 309e65b | 2020-01-28 14:42:25 +0100 | [diff] [blame] | 65 | /* Serial download mode */ |
| 66 | if (is_usb_boot()) { |
| 67 | puts("Back to ROM, SDP\n"); |
| 68 | restore_boot_params(); |
| 69 | } |
| 70 | puts("Normal Boot\n"); |
| 71 | } |
| 72 | |
| 73 | #ifdef CONFIG_SPL_LOAD_FIT |
| 74 | int board_fit_config_name_match(const char *name) |
| 75 | { |
| 76 | /* Just empty function now - can't decide what to choose */ |
| 77 | debug("%s: %s\n", __func__, name); |
| 78 | |
| 79 | return 0; |
| 80 | } |
| 81 | #endif |
| 82 | |
Marek Vasut | 483350a | 2022-04-08 02:15:00 +0200 | [diff] [blame] | 83 | __weak void board_early_init(void) |
Igor Opaniuk | 309e65b | 2020-01-28 14:42:25 +0100 | [diff] [blame] | 84 | { |
Marek Vasut | 483350a | 2022-04-08 02:15:00 +0200 | [diff] [blame] | 85 | init_uart_clk(0); |
Igor Opaniuk | 309e65b | 2020-01-28 14:42:25 +0100 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | int power_init_board(void) |
| 89 | { |
| 90 | struct udevice *dev; |
| 91 | int ret; |
| 92 | |
Max Krummenacher | 22c0133 | 2020-10-28 11:58:12 +0200 | [diff] [blame] | 93 | if (IS_ENABLED(CONFIG_SPL_DM_PMIC_PCA9450)) { |
Marcel Ziswiler | 2712c78 | 2022-07-21 15:41:23 +0200 | [diff] [blame] | 94 | ret = pmic_get("pmic@25", &dev); |
Max Krummenacher | 22c0133 | 2020-10-28 11:58:12 +0200 | [diff] [blame] | 95 | if (ret == -ENODEV) { |
| 96 | puts("No pmic found\n"); |
| 97 | return ret; |
| 98 | } |
Igor Opaniuk | 309e65b | 2020-01-28 14:42:25 +0100 | [diff] [blame] | 99 | |
Max Krummenacher | 22c0133 | 2020-10-28 11:58:12 +0200 | [diff] [blame] | 100 | if (ret != 0) |
| 101 | return ret; |
Igor Opaniuk | 309e65b | 2020-01-28 14:42:25 +0100 | [diff] [blame] | 102 | |
Max Krummenacher | 22c0133 | 2020-10-28 11:58:12 +0200 | [diff] [blame] | 103 | /* BUCKxOUT_DVS0/1 control BUCK123 output, clear PRESET_EN */ |
| 104 | pmic_reg_write(dev, PCA9450_BUCK123_DVS, 0x29); |
Igor Opaniuk | 309e65b | 2020-01-28 14:42:25 +0100 | [diff] [blame] | 105 | |
Max Krummenacher | 22c0133 | 2020-10-28 11:58:12 +0200 | [diff] [blame] | 106 | /* increase VDD_DRAM to 0.975v for 1.5Ghz DDR */ |
| 107 | pmic_reg_write(dev, PCA9450_BUCK3OUT_DVS0, 0x1c); |
Igor Opaniuk | 309e65b | 2020-01-28 14:42:25 +0100 | [diff] [blame] | 108 | |
Max Krummenacher | 22c0133 | 2020-10-28 11:58:12 +0200 | [diff] [blame] | 109 | /* set WDOG_B_CFG to cold reset */ |
| 110 | pmic_reg_write(dev, PCA9450_RESET_CTRL, 0xA1); |
Igor Opaniuk | 309e65b | 2020-01-28 14:42:25 +0100 | [diff] [blame] | 111 | |
Max Krummenacher | 49793d2 | 2020-10-28 11:58:14 +0200 | [diff] [blame] | 112 | pmic_reg_write(dev, PCA9450_CONFIG2, 0x1); |
| 113 | |
Max Krummenacher | 22c0133 | 2020-10-28 11:58:12 +0200 | [diff] [blame] | 114 | return 0; |
| 115 | } |
Igor Opaniuk | 309e65b | 2020-01-28 14:42:25 +0100 | [diff] [blame] | 116 | |
| 117 | return 0; |
| 118 | } |
| 119 | |
| 120 | void board_init_f(ulong dummy) |
| 121 | { |
| 122 | struct udevice *dev; |
| 123 | int ret; |
| 124 | |
| 125 | arch_cpu_init(); |
| 126 | |
Marek Vasut | 483350a | 2022-04-08 02:15:00 +0200 | [diff] [blame] | 127 | board_early_init(); |
Igor Opaniuk | 309e65b | 2020-01-28 14:42:25 +0100 | [diff] [blame] | 128 | |
| 129 | timer_init(); |
| 130 | |
Igor Opaniuk | 309e65b | 2020-01-28 14:42:25 +0100 | [diff] [blame] | 131 | /* Clear the BSS. */ |
| 132 | memset(__bss_start, 0, __bss_end - __bss_start); |
| 133 | |
| 134 | ret = spl_early_init(); |
| 135 | if (ret) { |
| 136 | debug("spl_early_init() failed: %d\n", ret); |
| 137 | hang(); |
| 138 | } |
| 139 | |
| 140 | ret = uclass_get_device_by_name(UCLASS_CLK, |
| 141 | "clock-controller@30380000", |
| 142 | &dev); |
| 143 | if (ret < 0) { |
| 144 | printf("Failed to find clock node. Check device tree\n"); |
| 145 | hang(); |
| 146 | } |
| 147 | |
Marcel Ziswiler | 5d29c4d | 2022-05-17 00:21:45 +0200 | [diff] [blame] | 148 | preloader_console_init(); |
| 149 | |
Igor Opaniuk | 309e65b | 2020-01-28 14:42:25 +0100 | [diff] [blame] | 150 | enable_tzc380(); |
| 151 | |
| 152 | power_init_board(); |
| 153 | |
| 154 | /* DDR initialization */ |
| 155 | spl_dram_init(); |
| 156 | |
| 157 | board_init_r(NULL, 0); |
| 158 | } |