Nishanth Menon | 9dd6bdc | 2023-11-04 03:01:35 -0500 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | /* |
| 3 | * https://beagleplay.org/ |
| 4 | * |
| 5 | * Copyright (C) 2022-2023 Texas Instruments Incorporated - https://www.ti.com/ |
| 6 | * Copyright (C) 2022-2023 Robert Nelson, BeagleBoard.org Foundation |
| 7 | */ |
| 8 | |
Jonathan Humphreys | 963b700 | 2024-06-14 11:35:37 -0500 | [diff] [blame] | 9 | #include <efi_loader.h> |
Nishanth Menon | 9dd6bdc | 2023-11-04 03:01:35 -0500 | [diff] [blame] | 10 | #include <cpu_func.h> |
| 11 | #include <env.h> |
| 12 | #include <fdt_support.h> |
| 13 | #include <spl.h> |
| 14 | |
Nishanth Menon | 1af7690 | 2024-02-20 12:39:48 -0600 | [diff] [blame] | 15 | #include <asm/arch/hardware.h> |
| 16 | |
Nishanth Menon | 9dd6bdc | 2023-11-04 03:01:35 -0500 | [diff] [blame] | 17 | DECLARE_GLOBAL_DATA_PTR; |
| 18 | |
Jonathan Humphreys | 963b700 | 2024-06-14 11:35:37 -0500 | [diff] [blame] | 19 | struct efi_fw_image fw_images[] = { |
| 20 | { |
| 21 | .image_type_id = BEAGLEPLAY_TIBOOT3_IMAGE_GUID, |
| 22 | .fw_name = u"BEAGLEPLAY_TIBOOT3", |
| 23 | .image_index = 1, |
| 24 | }, |
| 25 | { |
| 26 | .image_type_id = BEAGLEPLAY_SPL_IMAGE_GUID, |
| 27 | .fw_name = u"BEAGLEPLAY_SPL", |
| 28 | .image_index = 2, |
| 29 | }, |
| 30 | { |
| 31 | .image_type_id = BEAGLEPLAY_UBOOT_IMAGE_GUID, |
| 32 | .fw_name = u"BEAGLEPLAY_UBOOT", |
| 33 | .image_index = 3, |
| 34 | } |
| 35 | }; |
| 36 | |
| 37 | struct efi_capsule_update_info update_info = { |
| 38 | .dfu_string = "mmc 0=tiboot3.bin raw 0 2000 mmcpart 1;" |
| 39 | "tispl.bin fat 0 1;u-boot.img fat 0 1", |
| 40 | .num_images = ARRAY_SIZE(fw_images), |
| 41 | .images = fw_images, |
| 42 | }; |
| 43 | |
| 44 | #if IS_ENABLED(CONFIG_SET_DFU_ALT_INFO) |
| 45 | void set_dfu_alt_info(char *interface, char *devstr) |
| 46 | { |
| 47 | if (IS_ENABLED(CONFIG_EFI_HAVE_CAPSULE_SUPPORT)) |
| 48 | env_set("dfu_alt_info", update_info.dfu_string); |
| 49 | } |
| 50 | #endif |
| 51 | |
Nishanth Menon | 9dd6bdc | 2023-11-04 03:01:35 -0500 | [diff] [blame] | 52 | int board_init(void) |
| 53 | { |
| 54 | return 0; |
| 55 | } |
| 56 | |
| 57 | int dram_init(void) |
| 58 | { |
| 59 | return fdtdec_setup_mem_size_base(); |
| 60 | } |
| 61 | |
| 62 | int dram_init_banksize(void) |
| 63 | { |
| 64 | return fdtdec_setup_memory_banksize(); |
| 65 | } |
Nishanth Menon | aeded2b | 2024-02-12 13:47:25 -0600 | [diff] [blame] | 66 | |
| 67 | #ifdef CONFIG_BOARD_LATE_INIT |
| 68 | int board_late_init(void) |
| 69 | { |
| 70 | char fdtfile[50]; |
| 71 | |
| 72 | snprintf(fdtfile, sizeof(fdtfile), "%s/%s.dtb", |
| 73 | CONFIG_TI_FDT_FOLDER_PATH, CONFIG_DEFAULT_DEVICE_TREE); |
| 74 | |
| 75 | env_set("fdtfile", fdtfile); |
| 76 | |
| 77 | return 0; |
| 78 | } |
| 79 | #endif |
Tom Rini | 67303bd | 2024-03-04 11:50:26 -0500 | [diff] [blame] | 80 | |
Nishanth Menon | 1af7690 | 2024-02-20 12:39:48 -0600 | [diff] [blame] | 81 | #ifdef CONFIG_SPL_BOARD_INIT |
| 82 | |
| 83 | /* |
| 84 | * Enable the 32k Crystal: needed for accurate 32k clock |
| 85 | * and external clock sources such as wlan 32k input clock |
| 86 | * supplied from the SoC to the wlan chip. |
| 87 | * |
| 88 | * The trim setup can be very highly board type specific choice of the crystal |
| 89 | * So this is done in the board file, though, in this case, no specific trim |
| 90 | * is necessary. |
| 91 | */ |
| 92 | static void crystal_32k_enable(void) |
| 93 | { |
| 94 | /* Only mess with 32k at the start of boot from R5 */ |
| 95 | if (IS_ENABLED(CONFIG_CPU_V7R)) { |
| 96 | /* |
| 97 | * We have external 32k crystal, so lets enable it (0x0) |
| 98 | * and disable bypass (0x0) |
| 99 | */ |
| 100 | writel(0x0, MCU_CTRL_LFXOSC_CTRL); |
| 101 | |
| 102 | /* Add any crystal specific TRIM needed here.. */ |
| 103 | |
| 104 | /* Make sure to mux the SoC 32k from the crystal */ |
| 105 | writel(MCU_CTRL_DEVICE_CLKOUT_LFOSC_SELECT_VAL, |
| 106 | MCU_CTRL_DEVICE_CLKOUT_32K_CTRL); |
| 107 | } |
| 108 | } |
| 109 | |
Nishanth Menon | a7de13b | 2024-02-20 12:39:51 -0600 | [diff] [blame] | 110 | static void debounce_configure(void) |
| 111 | { |
| 112 | /* Configure debounce one time from R5 */ |
| 113 | if (IS_ENABLED(CONFIG_CPU_V7R)) { |
| 114 | /* |
| 115 | * Setup debounce time registers. |
| 116 | * arbitrary values. Times are approx |
| 117 | */ |
| 118 | /* 1.9ms debounce @ 32k */ |
| 119 | writel(0x1, CTRLMMR_DBOUNCE_CFG(1)); |
| 120 | /* 5ms debounce @ 32k */ |
| 121 | writel(0x5, CTRLMMR_DBOUNCE_CFG(2)); |
| 122 | /* 20ms debounce @ 32k */ |
| 123 | writel(0x14, CTRLMMR_DBOUNCE_CFG(3)); |
| 124 | /* 46ms debounce @ 32k */ |
| 125 | writel(0x18, CTRLMMR_DBOUNCE_CFG(4)); |
| 126 | /* 100ms debounce @ 32k */ |
| 127 | writel(0x1c, CTRLMMR_DBOUNCE_CFG(5)); |
| 128 | /* 156ms debounce @ 32k */ |
| 129 | writel(0x1f, CTRLMMR_DBOUNCE_CFG(6)); |
| 130 | } |
| 131 | } |
| 132 | |
Nishanth Menon | 1af7690 | 2024-02-20 12:39:48 -0600 | [diff] [blame] | 133 | void spl_board_init(void) |
| 134 | { |
| 135 | crystal_32k_enable(); |
Nishanth Menon | a7de13b | 2024-02-20 12:39:51 -0600 | [diff] [blame] | 136 | debounce_configure(); |
Nishanth Menon | 1af7690 | 2024-02-20 12:39:48 -0600 | [diff] [blame] | 137 | } |
| 138 | #endif |