Adam Ford | d42247d | 2020-12-11 06:01:46 -0600 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright 2020 Compass Electronics Group, LLC |
| 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <hang.h> |
| 8 | #include <image.h> |
| 9 | #include <init.h> |
| 10 | #include <log.h> |
| 11 | #include <asm/io.h> |
| 12 | #include <errno.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 13 | #include <asm/global_data.h> |
Adam Ford | d42247d | 2020-12-11 06:01:46 -0600 | [diff] [blame] | 14 | #include <asm/io.h> |
| 15 | #include <asm/arch/ddr.h> |
| 16 | #include <asm/arch/imx8mn_pins.h> |
| 17 | #include <asm/mach-imx/boot_mode.h> |
| 18 | #include <asm/arch/sys_proto.h> |
| 19 | #include <asm/arch/clock.h> |
| 20 | #include <asm/mach-imx/iomux-v3.h> |
| 21 | #include <asm/mach-imx/gpio.h> |
| 22 | #include <asm/mach-imx/mxc_i2c.h> |
Shiji Yang | bb11234 | 2023-08-03 09:47:16 +0800 | [diff] [blame] | 23 | #include <asm/sections.h> |
Adam Ford | d42247d | 2020-12-11 06:01:46 -0600 | [diff] [blame] | 24 | #include <fsl_esdhc_imx.h> |
| 25 | #include <mmc.h> |
| 26 | #include <linux/delay.h> |
| 27 | #include <power/pmic.h> |
| 28 | #include <power/bd71837.h> |
| 29 | #include <spl.h> |
| 30 | |
| 31 | #include <dm/uclass.h> |
| 32 | #include <dm/device.h> |
| 33 | #include <dm/uclass-internal.h> |
| 34 | #include <dm/device-internal.h> |
| 35 | |
| 36 | DECLARE_GLOBAL_DATA_PTR; |
| 37 | |
| 38 | int spl_board_boot_device(enum boot_device boot_dev_spl) |
| 39 | { |
| 40 | return BOOT_DEVICE_BOOTROM; |
| 41 | } |
| 42 | |
| 43 | void spl_dram_init(void) |
| 44 | { |
| 45 | ddr_init(&dram_timing); |
| 46 | } |
| 47 | |
| 48 | void spl_board_init(void) |
| 49 | { |
| 50 | struct udevice *dev; |
| 51 | int ret; |
| 52 | |
| 53 | debug("Normal Boot\n"); |
| 54 | |
| 55 | ret = uclass_get_device_by_name(UCLASS_CLK, |
| 56 | "clock-controller@30380000", |
| 57 | &dev); |
| 58 | if (ret < 0) |
| 59 | puts("Failed to find clock node. Check device tree\n"); |
| 60 | } |
| 61 | |
| 62 | #ifdef CONFIG_SPL_LOAD_FIT |
| 63 | int board_fit_config_name_match(const char *name) |
| 64 | { |
| 65 | /* Just empty function now - can't decide what to choose */ |
| 66 | debug("%s: %s\n", __func__, name); |
| 67 | |
| 68 | return 0; |
| 69 | } |
| 70 | #endif |
| 71 | |
Adam Ford | d42247d | 2020-12-11 06:01:46 -0600 | [diff] [blame] | 72 | #define PWM1_PAD_CTRL (PAD_CTL_FSEL2 | PAD_CTL_DSE6) |
| 73 | |
| 74 | static iomux_v3_cfg_t const pwm_pads[] = { |
| 75 | IMX8MN_PAD_GPIO1_IO01__PWM1_OUT | MUX_PAD_CTRL(PWM1_PAD_CTRL), |
| 76 | }; |
| 77 | |
Adam Ford | 02448f5 | 2022-10-22 08:43:44 -0500 | [diff] [blame] | 78 | static int power_init_board(void) |
| 79 | { |
| 80 | struct udevice *dev; |
| 81 | int ret; |
| 82 | |
| 83 | ret = pmic_get("pmic@4b", &dev); |
| 84 | if (ret == -ENODEV) { |
| 85 | puts("No pmic\n"); |
| 86 | return 0; |
| 87 | } |
| 88 | |
| 89 | if (ret != 0) |
| 90 | return ret; |
| 91 | |
| 92 | /* decrease RESET key long push time from the default 10s to 10ms */ |
| 93 | pmic_reg_write(dev, BD718XX_PWRONCONFIG1, 0x0); |
| 94 | |
| 95 | /* unlock the PMIC regs */ |
| 96 | pmic_reg_write(dev, BD718XX_REGLOCK, 0x1); |
| 97 | |
| 98 | /* increase VDD_SOC to typical value 0.85v before first DRAM access */ |
| 99 | pmic_reg_write(dev, BD718XX_BUCK1_VOLT_RUN, 0x0f); |
| 100 | |
| 101 | /* increase VDD_DRAM to 0.975v for 3Ghz DDR */ |
| 102 | pmic_reg_write(dev, BD718XX_1ST_NODVS_BUCK_VOLT, 0x83); |
| 103 | |
| 104 | /* lock the PMIC regs */ |
| 105 | pmic_reg_write(dev, BD718XX_REGLOCK, 0x11); |
| 106 | |
| 107 | return 0; |
| 108 | } |
| 109 | |
Adam Ford | d42247d | 2020-12-11 06:01:46 -0600 | [diff] [blame] | 110 | int board_early_init_f(void) |
| 111 | { |
Adam Ford | d42247d | 2020-12-11 06:01:46 -0600 | [diff] [blame] | 112 | /* Claiming pwm pins prevents LCD flicker during startup*/ |
| 113 | imx_iomux_v3_setup_multiple_pads(pwm_pads, ARRAY_SIZE(pwm_pads)); |
| 114 | |
Adam Ford | d42247d | 2020-12-11 06:01:46 -0600 | [diff] [blame] | 115 | init_uart_clk(1); |
| 116 | |
| 117 | return 0; |
| 118 | } |
| 119 | |
| 120 | void board_init_f(ulong dummy) |
| 121 | { |
| 122 | int ret; |
| 123 | |
| 124 | /* Clear the BSS. */ |
| 125 | memset(__bss_start, 0, __bss_end - __bss_start); |
| 126 | |
| 127 | arch_cpu_init(); |
| 128 | |
| 129 | board_early_init_f(); |
| 130 | |
| 131 | timer_init(); |
| 132 | |
Adam Ford | d42247d | 2020-12-11 06:01:46 -0600 | [diff] [blame] | 133 | ret = spl_init(); |
| 134 | if (ret) { |
| 135 | debug("spl_init() failed: %d\n", ret); |
| 136 | hang(); |
| 137 | } |
| 138 | |
Peng Fan | a9ed59c | 2022-06-11 20:20:55 +0800 | [diff] [blame] | 139 | preloader_console_init(); |
| 140 | |
Adam Ford | f026e13 | 2022-01-24 09:24:17 -0600 | [diff] [blame] | 141 | enable_tzc380(); |
| 142 | |
Adam Ford | 02448f5 | 2022-10-22 08:43:44 -0500 | [diff] [blame] | 143 | /* LPDDR4 at 1.6GHz requires a voltage adjustment on the PMIC */ |
| 144 | power_init_board(); |
| 145 | |
Adam Ford | d42247d | 2020-12-11 06:01:46 -0600 | [diff] [blame] | 146 | /* DDR initialization */ |
| 147 | spl_dram_init(); |
| 148 | |
| 149 | board_init_r(NULL, 0); |
| 150 | } |