blob: fae69b37585433a1431636df83e3f8f1e7c65129 [file] [log] [blame]
Nishanth Menon9dd6bdc2023-11-04 03:01:35 -05001// 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 Humphreys963b7002024-06-14 11:35:37 -05009#include <efi_loader.h>
Nishanth Menon9dd6bdc2023-11-04 03:01:35 -050010#include <cpu_func.h>
11#include <env.h>
12#include <fdt_support.h>
13#include <spl.h>
14
Nishanth Menon1af76902024-02-20 12:39:48 -060015#include <asm/arch/hardware.h>
16
Nishanth Menon9dd6bdc2023-11-04 03:01:35 -050017DECLARE_GLOBAL_DATA_PTR;
18
Jonathan Humphreys963b7002024-06-14 11:35:37 -050019struct 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
37struct 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)
45void 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 Menon9dd6bdc2023-11-04 03:01:35 -050052int board_init(void)
53{
54 return 0;
55}
56
57int dram_init(void)
58{
59 return fdtdec_setup_mem_size_base();
60}
61
62int dram_init_banksize(void)
63{
64 return fdtdec_setup_memory_banksize();
65}
Nishanth Menonaeded2b2024-02-12 13:47:25 -060066
67#ifdef CONFIG_BOARD_LATE_INIT
68int board_late_init(void)
69{
70 char fdtfile[50];
71
Aashvij Shenai73e4cbe2025-01-20 14:20:42 +053072 snprintf(fdtfile, sizeof(fdtfile), "%s.dtb", CONFIG_DEFAULT_DEVICE_TREE);
Nishanth Menonaeded2b2024-02-12 13:47:25 -060073
74 env_set("fdtfile", fdtfile);
75
76 return 0;
77}
78#endif
Tom Rini67303bd2024-03-04 11:50:26 -050079
Nishanth Menon1af76902024-02-20 12:39:48 -060080#ifdef CONFIG_SPL_BOARD_INIT
81
82/*
83 * Enable the 32k Crystal: needed for accurate 32k clock
84 * and external clock sources such as wlan 32k input clock
85 * supplied from the SoC to the wlan chip.
86 *
87 * The trim setup can be very highly board type specific choice of the crystal
88 * So this is done in the board file, though, in this case, no specific trim
89 * is necessary.
90 */
91static void crystal_32k_enable(void)
92{
93 /* Only mess with 32k at the start of boot from R5 */
94 if (IS_ENABLED(CONFIG_CPU_V7R)) {
95 /*
96 * We have external 32k crystal, so lets enable it (0x0)
97 * and disable bypass (0x0)
98 */
99 writel(0x0, MCU_CTRL_LFXOSC_CTRL);
100
101 /* Add any crystal specific TRIM needed here.. */
102
103 /* Make sure to mux the SoC 32k from the crystal */
104 writel(MCU_CTRL_DEVICE_CLKOUT_LFOSC_SELECT_VAL,
105 MCU_CTRL_DEVICE_CLKOUT_32K_CTRL);
106 }
107}
108
Nishanth Menona7de13b2024-02-20 12:39:51 -0600109static void debounce_configure(void)
110{
111 /* Configure debounce one time from R5 */
112 if (IS_ENABLED(CONFIG_CPU_V7R)) {
113 /*
114 * Setup debounce time registers.
115 * arbitrary values. Times are approx
116 */
117 /* 1.9ms debounce @ 32k */
118 writel(0x1, CTRLMMR_DBOUNCE_CFG(1));
119 /* 5ms debounce @ 32k */
120 writel(0x5, CTRLMMR_DBOUNCE_CFG(2));
121 /* 20ms debounce @ 32k */
122 writel(0x14, CTRLMMR_DBOUNCE_CFG(3));
123 /* 46ms debounce @ 32k */
124 writel(0x18, CTRLMMR_DBOUNCE_CFG(4));
125 /* 100ms debounce @ 32k */
126 writel(0x1c, CTRLMMR_DBOUNCE_CFG(5));
127 /* 156ms debounce @ 32k */
128 writel(0x1f, CTRLMMR_DBOUNCE_CFG(6));
129 }
130}
131
Nishanth Menon1af76902024-02-20 12:39:48 -0600132void spl_board_init(void)
133{
134 crystal_32k_enable();
Nishanth Menona7de13b2024-02-20 12:39:51 -0600135 debounce_configure();
Nishanth Menon1af76902024-02-20 12:39:48 -0600136}
137#endif