Adam Ford | 8e95883 | 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> |
| 13 | #include <asm/io.h> |
| 14 | #include <asm/arch/ddr.h> |
| 15 | #include <asm/arch/imx8mn_pins.h> |
| 16 | #include <asm/mach-imx/boot_mode.h> |
| 17 | #include <asm/arch/sys_proto.h> |
| 18 | #include <asm/arch/clock.h> |
| 19 | #include <asm/mach-imx/iomux-v3.h> |
| 20 | #include <asm/mach-imx/gpio.h> |
| 21 | #include <asm/mach-imx/mxc_i2c.h> |
| 22 | #include <fsl_esdhc_imx.h> |
| 23 | #include <mmc.h> |
| 24 | #include <linux/delay.h> |
| 25 | #include <power/pmic.h> |
| 26 | #include <power/bd71837.h> |
| 27 | #include <spl.h> |
| 28 | |
| 29 | #include <dm/uclass.h> |
| 30 | #include <dm/device.h> |
| 31 | #include <dm/uclass-internal.h> |
| 32 | #include <dm/device-internal.h> |
| 33 | |
| 34 | DECLARE_GLOBAL_DATA_PTR; |
| 35 | |
| 36 | int spl_board_boot_device(enum boot_device boot_dev_spl) |
| 37 | { |
| 38 | return BOOT_DEVICE_BOOTROM; |
| 39 | } |
| 40 | |
| 41 | void spl_dram_init(void) |
| 42 | { |
| 43 | ddr_init(&dram_timing); |
| 44 | } |
| 45 | |
| 46 | void spl_board_init(void) |
| 47 | { |
| 48 | struct udevice *dev; |
| 49 | int ret; |
| 50 | |
| 51 | debug("Normal Boot\n"); |
| 52 | |
| 53 | ret = uclass_get_device_by_name(UCLASS_CLK, |
| 54 | "clock-controller@30380000", |
| 55 | &dev); |
| 56 | if (ret < 0) |
| 57 | puts("Failed to find clock node. Check device tree\n"); |
| 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 | |
| 70 | #define UART_PAD_CTRL (PAD_CTL_DSE6 | PAD_CTL_FSEL1) |
| 71 | #define WDOG_PAD_CTRL (PAD_CTL_DSE6 | PAD_CTL_ODE | PAD_CTL_PUE | PAD_CTL_PE) |
| 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 | |
| 78 | static iomux_v3_cfg_t const uart_pads[] = { |
| 79 | IMX8MN_PAD_UART2_RXD__UART2_DCE_RX | MUX_PAD_CTRL(UART_PAD_CTRL), |
| 80 | IMX8MN_PAD_UART2_TXD__UART2_DCE_TX | MUX_PAD_CTRL(UART_PAD_CTRL), |
| 81 | }; |
| 82 | |
| 83 | static iomux_v3_cfg_t const wdog_pads[] = { |
| 84 | IMX8MN_PAD_GPIO1_IO02__WDOG1_WDOG_B | MUX_PAD_CTRL(WDOG_PAD_CTRL), |
| 85 | }; |
| 86 | |
| 87 | int board_early_init_f(void) |
| 88 | { |
| 89 | struct wdog_regs *wdog = (struct wdog_regs *)WDOG1_BASE_ADDR; |
| 90 | |
| 91 | /* Claiming pwm pins prevents LCD flicker during startup*/ |
| 92 | imx_iomux_v3_setup_multiple_pads(pwm_pads, ARRAY_SIZE(pwm_pads)); |
| 93 | |
| 94 | imx_iomux_v3_setup_multiple_pads(wdog_pads, ARRAY_SIZE(wdog_pads)); |
| 95 | set_wdog_reset(wdog); |
| 96 | |
| 97 | imx_iomux_v3_setup_multiple_pads(uart_pads, ARRAY_SIZE(uart_pads)); |
| 98 | init_uart_clk(1); |
| 99 | |
| 100 | return 0; |
| 101 | } |
| 102 | |
| 103 | void board_init_f(ulong dummy) |
| 104 | { |
| 105 | int ret; |
| 106 | |
| 107 | /* Clear the BSS. */ |
| 108 | memset(__bss_start, 0, __bss_end - __bss_start); |
| 109 | |
| 110 | arch_cpu_init(); |
| 111 | |
| 112 | board_early_init_f(); |
| 113 | |
| 114 | timer_init(); |
| 115 | |
| 116 | preloader_console_init(); |
| 117 | |
| 118 | ret = spl_init(); |
| 119 | if (ret) { |
| 120 | debug("spl_init() failed: %d\n", ret); |
| 121 | hang(); |
| 122 | } |
| 123 | |
| 124 | /* DDR initialization */ |
| 125 | spl_dram_init(); |
| 126 | |
| 127 | board_init_r(NULL, 0); |
| 128 | } |