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> |
Shiji Yang | bb11234 | 2023-08-03 09:47:16 +0800 | [diff] [blame^] | 19 | #include <asm/sections.h> |
Igor Opaniuk | 309e65b | 2020-01-28 14:42:25 +0100 | [diff] [blame] | 20 | #include <cpu_func.h> |
| 21 | #include <dm/device.h> |
| 22 | #include <dm/device-internal.h> |
| 23 | #include <dm/uclass.h> |
| 24 | #include <dm/uclass-internal.h> |
| 25 | #include <hang.h> |
Max Krummenacher | 22c0133 | 2020-10-28 11:58:12 +0200 | [diff] [blame] | 26 | #include <i2c.h> |
Max Krummenacher | 22c0133 | 2020-10-28 11:58:12 +0200 | [diff] [blame] | 27 | #include <power/pca9450.h> |
Igor Opaniuk | 309e65b | 2020-01-28 14:42:25 +0100 | [diff] [blame] | 28 | #include <power/pmic.h> |
| 29 | #include <spl.h> |
| 30 | |
| 31 | DECLARE_GLOBAL_DATA_PTR; |
| 32 | |
Max Krummenacher | 22c0133 | 2020-10-28 11:58:12 +0200 | [diff] [blame] | 33 | #define I2C_PMIC_BUS_ID 1 |
| 34 | |
Igor Opaniuk | 309e65b | 2020-01-28 14:42:25 +0100 | [diff] [blame] | 35 | int spl_board_boot_device(enum boot_device boot_dev_spl) |
| 36 | { |
| 37 | switch (boot_dev_spl) { |
Marcel Ziswiler | 2b910a2 | 2022-08-22 15:06:02 +0200 | [diff] [blame] | 38 | case MMC1_BOOT: /* eMMC */ |
Igor Opaniuk | 309e65b | 2020-01-28 14:42:25 +0100 | [diff] [blame] | 39 | return BOOT_DEVICE_MMC1; |
Marcel Ziswiler | 2b910a2 | 2022-08-22 15:06:02 +0200 | [diff] [blame] | 40 | case SD2_BOOT: /* SD card */ |
Igor Opaniuk | 309e65b | 2020-01-28 14:42:25 +0100 | [diff] [blame] | 41 | case MMC2_BOOT: |
| 42 | return BOOT_DEVICE_MMC2; |
Igor Opaniuk | 309e65b | 2020-01-28 14:42:25 +0100 | [diff] [blame] | 43 | case USB_BOOT: |
| 44 | return BOOT_DEVICE_BOARD; |
| 45 | default: |
| 46 | return BOOT_DEVICE_NONE; |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | void spl_dram_init(void) |
| 51 | { |
| 52 | ddr_init(&dram_timing); |
| 53 | } |
| 54 | |
| 55 | void spl_board_init(void) |
| 56 | { |
Marek Vasut | 085555f | 2022-09-19 21:41:15 +0200 | [diff] [blame] | 57 | arch_misc_init(); |
Igor Opaniuk | 309e65b | 2020-01-28 14:42:25 +0100 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | #ifdef CONFIG_SPL_LOAD_FIT |
| 61 | int board_fit_config_name_match(const char *name) |
| 62 | { |
| 63 | /* Just empty function now - can't decide what to choose */ |
| 64 | debug("%s: %s\n", __func__, name); |
| 65 | |
| 66 | return 0; |
| 67 | } |
| 68 | #endif |
| 69 | |
Marek Vasut | 483350a | 2022-04-08 02:15:00 +0200 | [diff] [blame] | 70 | __weak void board_early_init(void) |
Igor Opaniuk | 309e65b | 2020-01-28 14:42:25 +0100 | [diff] [blame] | 71 | { |
Marek Vasut | 483350a | 2022-04-08 02:15:00 +0200 | [diff] [blame] | 72 | init_uart_clk(0); |
Igor Opaniuk | 309e65b | 2020-01-28 14:42:25 +0100 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | int power_init_board(void) |
| 76 | { |
| 77 | struct udevice *dev; |
| 78 | int ret; |
| 79 | |
Max Krummenacher | 22c0133 | 2020-10-28 11:58:12 +0200 | [diff] [blame] | 80 | if (IS_ENABLED(CONFIG_SPL_DM_PMIC_PCA9450)) { |
Marcel Ziswiler | 2712c78 | 2022-07-21 15:41:23 +0200 | [diff] [blame] | 81 | ret = pmic_get("pmic@25", &dev); |
Max Krummenacher | 22c0133 | 2020-10-28 11:58:12 +0200 | [diff] [blame] | 82 | if (ret == -ENODEV) { |
| 83 | puts("No pmic found\n"); |
| 84 | return ret; |
| 85 | } |
Igor Opaniuk | 309e65b | 2020-01-28 14:42:25 +0100 | [diff] [blame] | 86 | |
Max Krummenacher | 22c0133 | 2020-10-28 11:58:12 +0200 | [diff] [blame] | 87 | if (ret != 0) |
| 88 | return ret; |
Igor Opaniuk | 309e65b | 2020-01-28 14:42:25 +0100 | [diff] [blame] | 89 | |
Max Krummenacher | 22c0133 | 2020-10-28 11:58:12 +0200 | [diff] [blame] | 90 | /* BUCKxOUT_DVS0/1 control BUCK123 output, clear PRESET_EN */ |
| 91 | pmic_reg_write(dev, PCA9450_BUCK123_DVS, 0x29); |
Igor Opaniuk | 309e65b | 2020-01-28 14:42:25 +0100 | [diff] [blame] | 92 | |
Max Krummenacher | 22c0133 | 2020-10-28 11:58:12 +0200 | [diff] [blame] | 93 | /* increase VDD_DRAM to 0.975v for 1.5Ghz DDR */ |
| 94 | pmic_reg_write(dev, PCA9450_BUCK3OUT_DVS0, 0x1c); |
Igor Opaniuk | 309e65b | 2020-01-28 14:42:25 +0100 | [diff] [blame] | 95 | |
Max Krummenacher | 49793d2 | 2020-10-28 11:58:14 +0200 | [diff] [blame] | 96 | pmic_reg_write(dev, PCA9450_CONFIG2, 0x1); |
| 97 | |
Max Krummenacher | 22c0133 | 2020-10-28 11:58:12 +0200 | [diff] [blame] | 98 | return 0; |
| 99 | } |
Igor Opaniuk | 309e65b | 2020-01-28 14:42:25 +0100 | [diff] [blame] | 100 | |
| 101 | return 0; |
| 102 | } |
| 103 | |
| 104 | void board_init_f(ulong dummy) |
| 105 | { |
| 106 | struct udevice *dev; |
| 107 | int ret; |
| 108 | |
| 109 | arch_cpu_init(); |
| 110 | |
Marek Vasut | 483350a | 2022-04-08 02:15:00 +0200 | [diff] [blame] | 111 | board_early_init(); |
Igor Opaniuk | 309e65b | 2020-01-28 14:42:25 +0100 | [diff] [blame] | 112 | |
| 113 | timer_init(); |
| 114 | |
Igor Opaniuk | 309e65b | 2020-01-28 14:42:25 +0100 | [diff] [blame] | 115 | /* Clear the BSS. */ |
| 116 | memset(__bss_start, 0, __bss_end - __bss_start); |
| 117 | |
| 118 | ret = spl_early_init(); |
| 119 | if (ret) { |
| 120 | debug("spl_early_init() failed: %d\n", ret); |
| 121 | hang(); |
| 122 | } |
| 123 | |
| 124 | ret = uclass_get_device_by_name(UCLASS_CLK, |
| 125 | "clock-controller@30380000", |
| 126 | &dev); |
| 127 | if (ret < 0) { |
| 128 | printf("Failed to find clock node. Check device tree\n"); |
| 129 | hang(); |
| 130 | } |
| 131 | |
Marcel Ziswiler | 5d29c4d | 2022-05-17 00:21:45 +0200 | [diff] [blame] | 132 | preloader_console_init(); |
| 133 | |
Igor Opaniuk | 309e65b | 2020-01-28 14:42:25 +0100 | [diff] [blame] | 134 | enable_tzc380(); |
| 135 | |
| 136 | power_init_board(); |
| 137 | |
| 138 | /* DDR initialization */ |
| 139 | spl_dram_init(); |
| 140 | |
| 141 | board_init_r(NULL, 0); |
| 142 | } |