blob: 17bb45773639b0215734dc40c2fc6219fd5d3cce [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>
6#include <errno.h>
7#include <fsl_ddr.h>
8#include <fdt_support.h>
Simon Glass3ba929a2020-10-30 21:38:53 -06009#include <asm/global_data.h>
Michael Walle36ba7642020-10-15 23:08:57 +020010#include <linux/libfdt.h>
11#include <env_internal.h>
12#include <asm/arch-fsl-layerscape/soc.h>
13#include <asm/arch-fsl-layerscape/fsl_icid.h>
14#include <i2c.h>
15#include <asm/arch/soc.h>
16#include <fsl_immap.h>
17#include <netdev.h>
Michael Walle324b7b42021-11-15 23:45:49 +010018#include <wdt.h>
Michael Walle36ba7642020-10-15 23:08:57 +020019
Michael Walle3b185bc2021-11-15 23:45:46 +010020#include <sl28cpld.h>
Michael Walle36ba7642020-10-15 23:08:57 +020021#include <fdtdec.h>
22#include <miiphy.h>
23
24DECLARE_GLOBAL_DATA_PTR;
25
Michael Walle101410e2021-01-08 00:08:59 +010026int board_early_init_f(void)
27{
28 fsl_lsch3_early_init_f();
29 return 0;
30}
31
Michael Walle36ba7642020-10-15 23:08:57 +020032int board_init(void)
33{
Michael Walle36ba7642020-10-15 23:08:57 +020034 return 0;
35}
36
37int board_eth_init(struct bd_info *bis)
38{
39 return pci_eth_init(bis);
40}
41
Michael Walle3b185bc2021-11-15 23:45:46 +010042static int __sl28cpld_read(uint reg)
43{
44 struct udevice *dev;
45 int ret;
46
47 ret = uclass_get_device_by_driver(UCLASS_NOP,
48 DM_DRIVER_GET(sl28cpld), &dev);
49 if (ret)
50 return ret;
51
52 return sl28cpld_read(dev, reg);
53}
54
55static void print_cpld_version(void)
56{
57 int version = __sl28cpld_read(SL28CPLD_VERSION);
58
59 if (version < 0)
60 printf("CPLD: error reading version (%d)\n", version);
61 else
62 printf("CPLD: v%d\n", version);
63}
64
Michael Walle36ba7642020-10-15 23:08:57 +020065int checkboard(void)
66{
67 printf("EL: %d\n", current_el());
Michael Walle3b185bc2021-11-15 23:45:46 +010068 if (CONFIG_IS_ENABLED(SL28CPLD))
69 print_cpld_version();
70
Michael Walle36ba7642020-10-15 23:08:57 +020071 return 0;
72}
73
Michael Walle324b7b42021-11-15 23:45:49 +010074static void stop_recovery_watchdog(void)
75{
76 struct udevice *dev;
77 int ret;
78
79 ret = uclass_get_device_by_driver(UCLASS_WDT,
80 DM_DRIVER_GET(sl28cpld_wdt), &dev);
81 if (!ret)
82 wdt_stop(dev);
83}
84
85int fsl_board_late_init(void)
86{
87 /*
88 * Usually, the after a board reset, the watchdog is enabled by
89 * default. This is to supervise the bootloader boot-up. Therefore,
90 * to prevent a watchdog reset if we don't actively kick it, we have
91 * to disable it.
92 *
93 * If the watchdog isn't enabled at reset (which is a configuration
94 * option) disabling it doesn't hurt either.
95 */
96 if (!CONFIG_IS_ENABLED(WATCHDOG_AUTOSTART))
97 stop_recovery_watchdog();
98
99 return 0;
100}
101
Michael Walle36ba7642020-10-15 23:08:57 +0200102void detail_board_ddr_info(void)
103{
Michael Walle36ba7642020-10-15 23:08:57 +0200104 print_ddr_info(0);
105}
106
107int ft_board_setup(void *blob, struct bd_info *bd)
108{
109 u64 base[CONFIG_NR_DRAM_BANKS];
110 u64 size[CONFIG_NR_DRAM_BANKS];
111 int nbanks = CONFIG_NR_DRAM_BANKS;
Michael Walle76427fb2020-11-18 17:46:02 +0100112 int node;
Michael Walle36ba7642020-10-15 23:08:57 +0200113 int i;
114
115 ft_cpu_setup(blob, bd);
116
117 /* fixup DT for the two GPP DDR banks */
118 for (i = 0; i < nbanks; i++) {
119 base[i] = gd->bd->bi_dram[i].start;
120 size[i] = gd->bd->bi_dram[i].size;
121 }
122
123 fdt_fixup_memory_banks(blob, base, size, nbanks);
124
125 fdt_fixup_icid(blob);
126
Michael Walle76427fb2020-11-18 17:46:02 +0100127 if (CONFIG_IS_ENABLED(SL28_SPL_LOADS_OPTEE_BL32)) {
128 node = fdt_node_offset_by_compatible(blob, -1, "linaro,optee-tz");
129 if (node)
Marek BehĂșnf872e832021-11-26 14:57:08 +0100130 fdt_set_node_status(blob, node, FDT_STATUS_OKAY);
Michael Walle76427fb2020-11-18 17:46:02 +0100131 }
132
Michael Walle36ba7642020-10-15 23:08:57 +0200133 return 0;
134}