blob: 89948e087f1024817ad2e15d3a12194e3e82faaf [file] [log] [blame]
Michael Walle36ba7642020-10-15 23:08:57 +02001// SPDX-License-Identifier: GPL-2.0+
2
3#include <common.h>
Michael Walle3b185bc2021-11-15 23:45:46 +01004#include <dm.h>
Michael Walle36ba7642020-10-15 23:08:57 +02005#include <malloc.h>
Sughosh Ganuccb36462022-04-15 11:29:34 +05306#include <efi.h>
7#include <efi_loader.h>
Michael Walle36ba7642020-10-15 23:08:57 +02008#include <errno.h>
9#include <fsl_ddr.h>
10#include <fdt_support.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060011#include <asm/global_data.h>
Michael Walle36ba7642020-10-15 23:08:57 +020012#include <linux/libfdt.h>
Sughosh Ganuccb36462022-04-15 11:29:34 +053013#include <linux/kernel.h>
Michael Walle36ba7642020-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 Walle324b7b42021-11-15 23:45:49 +010021#include <wdt.h>
Michael Walle36ba7642020-10-15 23:08:57 +020022
Michael Walle3b185bc2021-11-15 23:45:46 +010023#include <sl28cpld.h>
Michael Walle36ba7642020-10-15 23:08:57 +020024#include <fdtdec.h>
25#include <miiphy.h>
26
Michael Wallebf9c73c2022-08-23 11:30:15 +020027#include "sl28.h"
28
Michael Walle36ba7642020-10-15 23:08:57 +020029DECLARE_GLOBAL_DATA_PTR;
30
Simon Glassb8196212023-02-05 15:39:42 -070031#if IS_ENABLED(CONFIG_EFI_HAVE_CAPSULE_SUPPORT)
Sughosh Ganuccb36462022-04-15 11:29:34 +053032struct 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 Walle101410e2021-01-08 00:08:59 +010049int board_early_init_f(void)
50{
51 fsl_lsch3_early_init_f();
52 return 0;
53}
54
Michael Walle36ba7642020-10-15 23:08:57 +020055int board_init(void)
56{
Michael Walle36ba7642020-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 Wallebf9c73c2022-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 Walle3b185bc2021-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 Walle36ba7642020-10-15 23:08:57 +0200109int checkboard(void)
110{
111 printf("EL: %d\n", current_el());
Simon Glass9d9b4e52023-02-05 15:40:48 -0700112 if (IS_ENABLED(CONFIG_SL28CPLD))
Michael Walle3b185bc2021-11-15 23:45:46 +0100113 print_cpld_version();
114
Michael Walle36ba7642020-10-15 23:08:57 +0200115 return 0;
116}
117
Michael Walle324b7b42021-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
Michael Walle9b146062022-08-23 11:30:17 +0200129static void sl28_set_prompt(void)
130{
131 enum boot_source src = sl28_boot_source();
132
133 switch (src) {
134 case BOOT_SOURCE_SPI:
135 env_set("PS1", "[FAILSAFE] => ");
136 break;
137 case BOOT_SOURCE_SDHC:
138 env_set("PS1", "[SDHC] => ");
139 break;
140 default:
141 env_set("PS1", NULL);
142 break;
143 }
144}
145
Michael Walle324b7b42021-11-15 23:45:49 +0100146int fsl_board_late_init(void)
147{
Michael Walle9b146062022-08-23 11:30:17 +0200148 if (IS_ENABLED(CONFIG_CMDLINE_PS_SUPPORT))
149 sl28_set_prompt();
150
Michael Walle324b7b42021-11-15 23:45:49 +0100151 /*
152 * Usually, the after a board reset, the watchdog is enabled by
153 * default. This is to supervise the bootloader boot-up. Therefore,
154 * to prevent a watchdog reset if we don't actively kick it, we have
155 * to disable it.
156 *
157 * If the watchdog isn't enabled at reset (which is a configuration
158 * option) disabling it doesn't hurt either.
159 */
Simon Glass00b41cb2023-02-05 15:44:31 -0700160 if (!IS_ENABLED(CONFIG_WATCHDOG_AUTOSTART))
Michael Walle324b7b42021-11-15 23:45:49 +0100161 stop_recovery_watchdog();
162
163 return 0;
164}
165
Michael Walle36ba7642020-10-15 23:08:57 +0200166void detail_board_ddr_info(void)
167{
Michael Walle36ba7642020-10-15 23:08:57 +0200168 print_ddr_info(0);
169}
170
171int ft_board_setup(void *blob, struct bd_info *bd)
172{
173 u64 base[CONFIG_NR_DRAM_BANKS];
174 u64 size[CONFIG_NR_DRAM_BANKS];
175 int nbanks = CONFIG_NR_DRAM_BANKS;
Michael Walle76427fb2020-11-18 17:46:02 +0100176 int node;
Michael Walle36ba7642020-10-15 23:08:57 +0200177 int i;
178
179 ft_cpu_setup(blob, bd);
180
181 /* fixup DT for the two GPP DDR banks */
182 for (i = 0; i < nbanks; i++) {
183 base[i] = gd->bd->bi_dram[i].start;
184 size[i] = gd->bd->bi_dram[i].size;
185 }
186
187 fdt_fixup_memory_banks(blob, base, size, nbanks);
188
189 fdt_fixup_icid(blob);
190
Simon Glass1540e722023-02-05 15:40:49 -0700191 if (IS_ENABLED(CONFIG_SL28_SPL_LOADS_OPTEE_BL32)) {
Michael Walle76427fb2020-11-18 17:46:02 +0100192 node = fdt_node_offset_by_compatible(blob, -1, "linaro,optee-tz");
193 if (node)
Marek BehĂșnf872e832021-11-26 14:57:08 +0100194 fdt_set_node_status(blob, node, FDT_STATUS_OKAY);
Michael Walle76427fb2020-11-18 17:46:02 +0100195 }
196
Michael Walle36ba7642020-10-15 23:08:57 +0200197 return 0;
198}