blob: af36439e2e229cd0feef843a2c1a233864db637a [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
9#include <cpu_func.h>
10#include <env.h>
11#include <fdt_support.h>
12#include <spl.h>
13
Nishanth Menon1af76902024-02-20 12:39:48 -060014#include <asm/arch/hardware.h>
15
Nishanth Menon9dd6bdc2023-11-04 03:01:35 -050016DECLARE_GLOBAL_DATA_PTR;
17
18int board_init(void)
19{
20 return 0;
21}
22
23int dram_init(void)
24{
25 return fdtdec_setup_mem_size_base();
26}
27
28int dram_init_banksize(void)
29{
30 return fdtdec_setup_memory_banksize();
31}
Nishanth Menonaeded2b2024-02-12 13:47:25 -060032
33#ifdef CONFIG_BOARD_LATE_INIT
34int board_late_init(void)
35{
36 char fdtfile[50];
37
38 snprintf(fdtfile, sizeof(fdtfile), "%s/%s.dtb",
39 CONFIG_TI_FDT_FOLDER_PATH, CONFIG_DEFAULT_DEVICE_TREE);
40
41 env_set("fdtfile", fdtfile);
42
43 return 0;
44}
45#endif
Tom Rini67303bd2024-03-04 11:50:26 -050046
Nishanth Menon1af76902024-02-20 12:39:48 -060047#ifdef CONFIG_SPL_BOARD_INIT
48
49/*
50 * Enable the 32k Crystal: needed for accurate 32k clock
51 * and external clock sources such as wlan 32k input clock
52 * supplied from the SoC to the wlan chip.
53 *
54 * The trim setup can be very highly board type specific choice of the crystal
55 * So this is done in the board file, though, in this case, no specific trim
56 * is necessary.
57 */
58static void crystal_32k_enable(void)
59{
60 /* Only mess with 32k at the start of boot from R5 */
61 if (IS_ENABLED(CONFIG_CPU_V7R)) {
62 /*
63 * We have external 32k crystal, so lets enable it (0x0)
64 * and disable bypass (0x0)
65 */
66 writel(0x0, MCU_CTRL_LFXOSC_CTRL);
67
68 /* Add any crystal specific TRIM needed here.. */
69
70 /* Make sure to mux the SoC 32k from the crystal */
71 writel(MCU_CTRL_DEVICE_CLKOUT_LFOSC_SELECT_VAL,
72 MCU_CTRL_DEVICE_CLKOUT_32K_CTRL);
73 }
74}
75
Nishanth Menona7de13b2024-02-20 12:39:51 -060076static void debounce_configure(void)
77{
78 /* Configure debounce one time from R5 */
79 if (IS_ENABLED(CONFIG_CPU_V7R)) {
80 /*
81 * Setup debounce time registers.
82 * arbitrary values. Times are approx
83 */
84 /* 1.9ms debounce @ 32k */
85 writel(0x1, CTRLMMR_DBOUNCE_CFG(1));
86 /* 5ms debounce @ 32k */
87 writel(0x5, CTRLMMR_DBOUNCE_CFG(2));
88 /* 20ms debounce @ 32k */
89 writel(0x14, CTRLMMR_DBOUNCE_CFG(3));
90 /* 46ms debounce @ 32k */
91 writel(0x18, CTRLMMR_DBOUNCE_CFG(4));
92 /* 100ms debounce @ 32k */
93 writel(0x1c, CTRLMMR_DBOUNCE_CFG(5));
94 /* 156ms debounce @ 32k */
95 writel(0x1f, CTRLMMR_DBOUNCE_CFG(6));
96 }
97}
98
Nishanth Menon1af76902024-02-20 12:39:48 -060099void spl_board_init(void)
100{
101 crystal_32k_enable();
Nishanth Menona7de13b2024-02-20 12:39:51 -0600102 debounce_configure();
Nishanth Menon1af76902024-02-20 12:39:48 -0600103}
104#endif