Giulio Benetti | 6986d6b | 2020-01-10 15:51:48 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright (C) 2019 |
| 4 | * Author(s): Giulio Benetti <giulio.benetti@benettiengineering.com> |
| 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <dm.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> |
Giulio Benetti | 6986d6b | 2020-01-10 15:51:48 +0100 | [diff] [blame] | 11 | #include <ram.h> |
| 12 | #include <spl.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 13 | #include <asm/global_data.h> |
Giulio Benetti | 6986d6b | 2020-01-10 15:51:48 +0100 | [diff] [blame] | 14 | #include <asm/io.h> |
| 15 | #include <asm/armv7m.h> |
Jesse Taube | 9782663 | 2022-03-17 14:33:21 -0400 | [diff] [blame] | 16 | #include <serial.h> |
Giulio Benetti | 6986d6b | 2020-01-10 15:51:48 +0100 | [diff] [blame] | 17 | |
| 18 | DECLARE_GLOBAL_DATA_PTR; |
| 19 | |
| 20 | int dram_init(void) |
| 21 | { |
| 22 | #ifndef CONFIG_SUPPORT_SPL |
| 23 | int rv; |
| 24 | struct udevice *dev; |
| 25 | |
| 26 | rv = uclass_get_device(UCLASS_RAM, 0, &dev); |
| 27 | if (rv) { |
| 28 | debug("DRAM init failed: %d\n", rv); |
| 29 | return rv; |
| 30 | } |
| 31 | |
| 32 | #endif |
| 33 | return fdtdec_setup_mem_size_base(); |
| 34 | } |
| 35 | |
| 36 | int dram_init_banksize(void) |
| 37 | { |
| 38 | return fdtdec_setup_memory_banksize(); |
| 39 | } |
| 40 | |
| 41 | #ifdef CONFIG_SPL_BUILD |
| 42 | #ifdef CONFIG_SPL_OS_BOOT |
| 43 | int spl_start_uboot(void) |
| 44 | { |
| 45 | debug("SPL: booting kernel\n"); |
| 46 | /* break into full u-boot on 'c' */ |
| 47 | return serial_tstc() && serial_getc() == 'c'; |
| 48 | } |
| 49 | #endif |
| 50 | |
| 51 | int spl_dram_init(void) |
| 52 | { |
| 53 | struct udevice *dev; |
| 54 | int rv; |
| 55 | |
| 56 | rv = uclass_get_device(UCLASS_RAM, 0, &dev); |
| 57 | if (rv) |
| 58 | debug("DRAM init failed: %d\n", rv); |
| 59 | return rv; |
| 60 | } |
| 61 | |
| 62 | void spl_board_init(void) |
| 63 | { |
Giulio Benetti | 6986d6b | 2020-01-10 15:51:48 +0100 | [diff] [blame] | 64 | preloader_console_init(); |
Giulio Benetti | 79fef47 | 2021-04-04 20:21:34 +0200 | [diff] [blame] | 65 | spl_dram_init(); |
Giulio Benetti | 6986d6b | 2020-01-10 15:51:48 +0100 | [diff] [blame] | 66 | arch_cpu_init(); /* to configure mpu for sdram rw permissions */ |
| 67 | } |
| 68 | |
| 69 | u32 spl_boot_device(void) |
| 70 | { |
Jesse Taube | 9fcbb55 | 2024-02-19 18:00:59 -0500 | [diff] [blame^] | 71 | /* There is no way to find the boot device so look if there is a valid IVT in RAM for MMC */ |
| 72 | u32 nor_ivt = *(u32 *)(CONFIG_SYS_LOAD_ADDR - 0xC00); |
| 73 | |
| 74 | if (nor_ivt == 0x402000d1) |
| 75 | return BOOT_DEVICE_MMC1; |
| 76 | return BOOT_DEVICE_NOR; |
Giulio Benetti | 6986d6b | 2020-01-10 15:51:48 +0100 | [diff] [blame] | 77 | } |
| 78 | #endif |
| 79 | |
Giulio Benetti | 6986d6b | 2020-01-10 15:51:48 +0100 | [diff] [blame] | 80 | int board_init(void) |
| 81 | { |
| 82 | gd->bd->bi_boot_params = gd->bd->bi_dram[0].start + 0x100; |
| 83 | |
| 84 | return 0; |
| 85 | } |