blob: 09d26883f19a5b95c8690064614c872b27410104 [file] [log] [blame]
David Huangd09f5fe2022-01-25 20:56:37 +05301// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Board specific initialization for J721S2 EVM
4 *
5 * Copyright (C) 2021 Texas Instruments Incorporated - http://www.ti.com/
6 * David Huang <d-huang@ti.com>
7 *
8 */
9
10#include <common.h>
11#include <env.h>
12#include <fdt_support.h>
13#include <generic-phy.h>
14#include <image.h>
15#include <init.h>
16#include <log.h>
17#include <net.h>
David Huangd09f5fe2022-01-25 20:56:37 +053018#include <asm/arch/hardware.h>
19#include <asm/gpio.h>
20#include <asm/io.h>
21#include <spl.h>
David Huangd09f5fe2022-01-25 20:56:37 +053022#include <dm.h>
23#include <dm/uclass-internal.h>
Sinthu Rajae0b4e952023-01-10 21:17:54 +053024#include <dm/root.h>
David Huangd09f5fe2022-01-25 20:56:37 +053025
26#include "../common/board_detect.h"
27
David Huangd09f5fe2022-01-25 20:56:37 +053028DECLARE_GLOBAL_DATA_PTR;
29
30int board_init(void)
31{
32 return 0;
33}
34
35int dram_init(void)
36{
37#ifdef CONFIG_PHYS_64BIT
38 gd->ram_size = 0x100000000;
39#else
40 gd->ram_size = 0x80000000;
41#endif
42
43 return 0;
44}
45
Pali Rohár4f4f5832022-09-09 17:32:40 +020046phys_size_t board_get_usable_ram_top(phys_size_t total_size)
David Huangd09f5fe2022-01-25 20:56:37 +053047{
48#ifdef CONFIG_PHYS_64BIT
49 /* Limit RAM used by U-Boot to the DDR low region */
50 if (gd->ram_top > 0x100000000)
51 return 0x100000000;
52#endif
53
54 return gd->ram_top;
55}
56
57int dram_init_banksize(void)
58{
59 /* Bank 0 declares the memory available in the DDR low region */
Tom Rinibb4dd962022-11-16 13:10:37 -050060 gd->bd->bi_dram[0].start = CFG_SYS_SDRAM_BASE;
David Huangd09f5fe2022-01-25 20:56:37 +053061 gd->bd->bi_dram[0].size = 0x7fffffff;
62 gd->ram_size = 0x80000000;
63
64#ifdef CONFIG_PHYS_64BIT
65 /* Bank 1 declares the memory available in the DDR high region */
Tom Rinibb4dd962022-11-16 13:10:37 -050066 gd->bd->bi_dram[1].start = CFG_SYS_SDRAM_BASE1;
David Huangd09f5fe2022-01-25 20:56:37 +053067 gd->bd->bi_dram[1].size = 0x37fffffff;
68 gd->ram_size = 0x400000000;
69#endif
70
71 return 0;
72}
73
David Huangd09f5fe2022-01-25 20:56:37 +053074#ifdef CONFIG_TI_I2C_BOARD_DETECT
Sinthu Rajac38cbf22023-01-10 21:17:50 +053075/*
76 * Functions specific to EVM and SK designs of J721S2/AM68 family.
77 */
78
79#define board_is_j721s2_som() board_ti_k3_is("J721S2X-PM1-SOM")
80
81#define board_is_am68_sk_som() board_ti_k3_is("AM68-SK-SOM")
82
David Huangd09f5fe2022-01-25 20:56:37 +053083int do_board_detect(void)
84{
85 int ret;
86
Sinthu Raja82407f62023-01-10 21:17:52 +053087 if (board_ti_was_eeprom_read())
88 return 0;
89
David Huangd09f5fe2022-01-25 20:56:37 +053090 ret = ti_i2c_eeprom_am6_get_base(CONFIG_EEPROM_BUS_ADDRESS,
91 CONFIG_EEPROM_CHIP_ADDRESS);
Sinthu Raja149ce992023-01-10 21:17:51 +053092 if (ret) {
93 printf("EEPROM not available at 0x%02x, trying to read at 0x%02x\n",
94 CONFIG_EEPROM_CHIP_ADDRESS, CONFIG_EEPROM_CHIP_ADDRESS + 1);
95 ret = ti_i2c_eeprom_am6_get_base(CONFIG_EEPROM_BUS_ADDRESS,
96 CONFIG_EEPROM_CHIP_ADDRESS + 1);
97 if (ret)
98 pr_err("Reading on-board EEPROM at 0x%02x failed %d\n",
99 CONFIG_EEPROM_CHIP_ADDRESS + 1, ret);
100 }
David Huangd09f5fe2022-01-25 20:56:37 +0530101
102 return ret;
103}
104
105int checkboard(void)
106{
107 struct ti_am6_eeprom *ep = TI_AM6_EEPROM_DATA;
108
109 if (do_board_detect())
110 /* EEPROM not populated */
111 printf("Board: %s rev %s\n", "J721S2X-PM1-SOM", "E1");
112 else
113 printf("Board: %s rev %s\n", ep->name, ep->version);
114
115 return 0;
116}
117
118static void setup_board_eeprom_env(void)
119{
120 char *name = "j721s2";
121
122 if (do_board_detect())
123 goto invalid_eeprom;
124
125 if (board_is_j721s2_som())
126 name = "j721s2";
Sinthu Rajac38cbf22023-01-10 21:17:50 +0530127 else if (board_is_am68_sk_som())
128 name = "am68-sk";
David Huangd09f5fe2022-01-25 20:56:37 +0530129 else
130 printf("Unidentified board claims %s in eeprom header\n",
131 board_ti_get_name());
132
133invalid_eeprom:
134 set_board_info_env_am6(name);
135}
136
137static void setup_serial(void)
138{
139 struct ti_am6_eeprom *ep = TI_AM6_EEPROM_DATA;
140 unsigned long board_serial;
141 char *endp;
142 char serial_string[17] = { 0 };
143
144 if (env_get("serial#"))
145 return;
146
147 board_serial = simple_strtoul(ep->serial, &endp, 16);
148 if (*endp != '\0') {
149 pr_err("Error: Can't set serial# to %s\n", ep->serial);
150 return;
151 }
152
153 snprintf(serial_string, sizeof(serial_string), "%016lx", board_serial);
154 env_set("serial#", serial_string);
155}
156#endif
157
Sinthu Raja82407f62023-01-10 21:17:52 +0530158/*
159 * This function chooses the right dtb based on the board name read from
160 * EEPROM if the EEPROM is programmed. Also, by default the boot chooses
161 * the EVM DTB if there is no EEPROM is programmed or not detected.
162 */
163#ifdef CONFIG_SPL_LOAD_FIT
164int board_fit_config_name_match(const char *name)
165{
166 bool eeprom_read = board_ti_was_eeprom_read();
167
168 if (!eeprom_read || board_is_j721s2_som()) {
169 if (!strcmp(name, "k3-j721s2-common-proc-board"))
170 return 0;
171 } else if (!eeprom_read || board_is_am68_sk_som()) {
172 if (!strcmp(name, "k3-am68-sk-base-board"))
173 return 0;
174 }
175
176 return -1;
177}
178#endif
179
David Huangd09f5fe2022-01-25 20:56:37 +0530180int board_late_init(void)
181{
182 if (IS_ENABLED(CONFIG_TI_I2C_BOARD_DETECT)) {
183 setup_board_eeprom_env();
184 setup_serial();
185 }
186
187 return 0;
188}
189
190void spl_board_init(void)
191{
192}