blob: 54719cc01c81546eb78a47ee60b4d46593699026 [file] [log] [blame]
Michael Walle4ceb5c62020-10-15 23:08:57 +02001// SPDX-License-Identifier: GPL-2.0+
2
3#include <common.h>
Michael Walled36b6832021-11-15 23:45:46 +01004#include <dm.h>
Michael Walle4ceb5c62020-10-15 23:08:57 +02005#include <malloc.h>
Sughosh Ganu741ef862022-04-15 11:29:34 +05306#include <efi.h>
7#include <efi_loader.h>
Michael Walle4ceb5c62020-10-15 23:08:57 +02008#include <errno.h>
9#include <fsl_ddr.h>
10#include <fdt_support.h>
Simon Glass401d1c42020-10-30 21:38:53 -060011#include <asm/global_data.h>
Michael Walle4ceb5c62020-10-15 23:08:57 +020012#include <linux/libfdt.h>
Sughosh Ganu741ef862022-04-15 11:29:34 +053013#include <linux/kernel.h>
Michael Walle4ceb5c62020-10-15 23:08:57 +020014#include <env_internal.h>
15#include <asm/arch-fsl-layerscape/soc.h>
16#include <asm/arch-fsl-layerscape/fsl_icid.h>
17#include <i2c.h>
18#include <asm/arch/soc.h>
19#include <fsl_immap.h>
20#include <netdev.h>
Michael Walle453d1712021-11-15 23:45:49 +010021#include <wdt.h>
Michael Walle4ceb5c62020-10-15 23:08:57 +020022
Michael Walled36b6832021-11-15 23:45:46 +010023#include <sl28cpld.h>
Michael Walle4ceb5c62020-10-15 23:08:57 +020024#include <fdtdec.h>
25#include <miiphy.h>
26
Michael Walle67b5dab2022-08-23 11:30:15 +020027#include "sl28.h"
28
Michael Walle4ceb5c62020-10-15 23:08:57 +020029DECLARE_GLOBAL_DATA_PTR;
30
Sughosh Ganu741ef862022-04-15 11:29:34 +053031#if CONFIG_IS_ENABLED(EFI_HAVE_CAPSULE_SUPPORT)
32struct efi_fw_image fw_images[] = {
33 {
34 .image_type_id = KONTRON_SL28_FIT_IMAGE_GUID,
35 .fw_name = u"KONTRON-SL28-FIT",
36 .image_index = 1,
37 },
38};
39
40struct efi_capsule_update_info update_info = {
41 .dfu_string = "sf 0:0=u-boot-bin raw 0x210000 0x1d0000;"
42 "u-boot-env raw 0x3e0000 0x20000",
43 .images = fw_images,
44};
45
46u8 num_image_type_guids = ARRAY_SIZE(fw_images);
47#endif /* EFI_HAVE_CAPSULE_SUPPORT */
48
Michael Walle805b2422021-01-08 00:08:59 +010049int board_early_init_f(void)
50{
51 fsl_lsch3_early_init_f();
52 return 0;
53}
54
Michael Walle4ceb5c62020-10-15 23:08:57 +020055int board_init(void)
56{
Michael Walle4ceb5c62020-10-15 23:08:57 +020057 return 0;
58}
59
60int board_eth_init(struct bd_info *bis)
61{
62 return pci_eth_init(bis);
63}
64
Michael Walle67b5dab2022-08-23 11:30:15 +020065enum env_location env_get_location(enum env_operation op, int prio)
66{
67 enum boot_source src = sl28_boot_source();
68
69 if (prio)
70 return ENVL_UNKNOWN;
71
72 if (!CONFIG_IS_ENABLED(ENV_IS_IN_SPI_FLASH))
73 return ENVL_NOWHERE;
74
75 /* write and erase always operate on the environment */
76 if (op == ENVOP_SAVE || op == ENVOP_ERASE)
77 return ENVL_SPI_FLASH;
78
79 /* failsafe boot will always use the compiled-in default environment */
80 if (src == BOOT_SOURCE_SPI)
81 return ENVL_NOWHERE;
82
83 return ENVL_SPI_FLASH;
84}
85
Michael Walled36b6832021-11-15 23:45:46 +010086static int __sl28cpld_read(uint reg)
87{
88 struct udevice *dev;
89 int ret;
90
91 ret = uclass_get_device_by_driver(UCLASS_NOP,
92 DM_DRIVER_GET(sl28cpld), &dev);
93 if (ret)
94 return ret;
95
96 return sl28cpld_read(dev, reg);
97}
98
99static void print_cpld_version(void)
100{
101 int version = __sl28cpld_read(SL28CPLD_VERSION);
102
103 if (version < 0)
104 printf("CPLD: error reading version (%d)\n", version);
105 else
106 printf("CPLD: v%d\n", version);
107}
108
Michael Walle4ceb5c62020-10-15 23:08:57 +0200109int checkboard(void)
110{
111 printf("EL: %d\n", current_el());
Michael Walled36b6832021-11-15 23:45:46 +0100112 if (CONFIG_IS_ENABLED(SL28CPLD))
113 print_cpld_version();
114
Michael Walle4ceb5c62020-10-15 23:08:57 +0200115 return 0;
116}
117
Michael Walle453d1712021-11-15 23:45:49 +0100118static void stop_recovery_watchdog(void)
119{
120 struct udevice *dev;
121 int ret;
122
123 ret = uclass_get_device_by_driver(UCLASS_WDT,
124 DM_DRIVER_GET(sl28cpld_wdt), &dev);
125 if (!ret)
126 wdt_stop(dev);
127}
128
129int fsl_board_late_init(void)
130{
131 /*
132 * Usually, the after a board reset, the watchdog is enabled by
133 * default. This is to supervise the bootloader boot-up. Therefore,
134 * to prevent a watchdog reset if we don't actively kick it, we have
135 * to disable it.
136 *
137 * If the watchdog isn't enabled at reset (which is a configuration
138 * option) disabling it doesn't hurt either.
139 */
140 if (!CONFIG_IS_ENABLED(WATCHDOG_AUTOSTART))
141 stop_recovery_watchdog();
142
143 return 0;
144}
145
Michael Walle4ceb5c62020-10-15 23:08:57 +0200146void detail_board_ddr_info(void)
147{
Michael Walle4ceb5c62020-10-15 23:08:57 +0200148 print_ddr_info(0);
149}
150
151int ft_board_setup(void *blob, struct bd_info *bd)
152{
153 u64 base[CONFIG_NR_DRAM_BANKS];
154 u64 size[CONFIG_NR_DRAM_BANKS];
155 int nbanks = CONFIG_NR_DRAM_BANKS;
Michael Walle4c450da2020-11-18 17:46:02 +0100156 int node;
Michael Walle4ceb5c62020-10-15 23:08:57 +0200157 int i;
158
159 ft_cpu_setup(blob, bd);
160
161 /* fixup DT for the two GPP DDR banks */
162 for (i = 0; i < nbanks; i++) {
163 base[i] = gd->bd->bi_dram[i].start;
164 size[i] = gd->bd->bi_dram[i].size;
165 }
166
167 fdt_fixup_memory_banks(blob, base, size, nbanks);
168
169 fdt_fixup_icid(blob);
170
Michael Walle4c450da2020-11-18 17:46:02 +0100171 if (CONFIG_IS_ENABLED(SL28_SPL_LOADS_OPTEE_BL32)) {
172 node = fdt_node_offset_by_compatible(blob, -1, "linaro,optee-tz");
173 if (node)
Marek BehĂșn2105cd02021-11-26 14:57:08 +0100174 fdt_set_node_status(blob, node, FDT_STATUS_OKAY);
Michael Walle4c450da2020-11-18 17:46:02 +0100175 }
176
Michael Walle4ceb5c62020-10-15 23:08:57 +0200177 return 0;
178}