blob: 786358105854582d9c43868d5e6e1668a3dca78b [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
Nishanth Menon9dd6bdc2023-11-04 03:01:35 -050044int board_init(void)
45{
46 return 0;
47}
48
49int dram_init(void)
50{
51 return fdtdec_setup_mem_size_base();
52}
53
54int dram_init_banksize(void)
55{
56 return fdtdec_setup_memory_banksize();
57}
Nishanth Menonaeded2b2024-02-12 13:47:25 -060058
59#ifdef CONFIG_BOARD_LATE_INIT
60int board_late_init(void)
61{
62 char fdtfile[50];
63
Aashvij Shenai73e4cbe2025-01-20 14:20:42 +053064 snprintf(fdtfile, sizeof(fdtfile), "%s.dtb", CONFIG_DEFAULT_DEVICE_TREE);
Nishanth Menonaeded2b2024-02-12 13:47:25 -060065
66 env_set("fdtfile", fdtfile);
67
68 return 0;
69}
70#endif
Tom Rini67303bd2024-03-04 11:50:26 -050071
Nishanth Menon1af76902024-02-20 12:39:48 -060072#ifdef CONFIG_SPL_BOARD_INIT
73
74/*
75 * Enable the 32k Crystal: needed for accurate 32k clock
76 * and external clock sources such as wlan 32k input clock
77 * supplied from the SoC to the wlan chip.
78 *
79 * The trim setup can be very highly board type specific choice of the crystal
80 * So this is done in the board file, though, in this case, no specific trim
81 * is necessary.
82 */
83static void crystal_32k_enable(void)
84{
85 /* Only mess with 32k at the start of boot from R5 */
86 if (IS_ENABLED(CONFIG_CPU_V7R)) {
87 /*
88 * We have external 32k crystal, so lets enable it (0x0)
89 * and disable bypass (0x0)
90 */
91 writel(0x0, MCU_CTRL_LFXOSC_CTRL);
92
93 /* Add any crystal specific TRIM needed here.. */
94
95 /* Make sure to mux the SoC 32k from the crystal */
96 writel(MCU_CTRL_DEVICE_CLKOUT_LFOSC_SELECT_VAL,
97 MCU_CTRL_DEVICE_CLKOUT_32K_CTRL);
98 }
99}
100
Nishanth Menona7de13b2024-02-20 12:39:51 -0600101static void debounce_configure(void)
102{
103 /* Configure debounce one time from R5 */
104 if (IS_ENABLED(CONFIG_CPU_V7R)) {
105 /*
106 * Setup debounce time registers.
107 * arbitrary values. Times are approx
108 */
109 /* 1.9ms debounce @ 32k */
110 writel(0x1, CTRLMMR_DBOUNCE_CFG(1));
111 /* 5ms debounce @ 32k */
112 writel(0x5, CTRLMMR_DBOUNCE_CFG(2));
113 /* 20ms debounce @ 32k */
114 writel(0x14, CTRLMMR_DBOUNCE_CFG(3));
115 /* 46ms debounce @ 32k */
116 writel(0x18, CTRLMMR_DBOUNCE_CFG(4));
117 /* 100ms debounce @ 32k */
118 writel(0x1c, CTRLMMR_DBOUNCE_CFG(5));
119 /* 156ms debounce @ 32k */
120 writel(0x1f, CTRLMMR_DBOUNCE_CFG(6));
121 }
122}
123
Nishanth Menon1af76902024-02-20 12:39:48 -0600124void spl_board_init(void)
125{
126 crystal_32k_enable();
Nishanth Menona7de13b2024-02-20 12:39:51 -0600127 debounce_configure();
Nishanth Menon1af76902024-02-20 12:39:48 -0600128}
129#endif