blob: 18e49112ac3c9450cab8abba2c2dbc57a4aa72be [file] [log] [blame]
Dave Gerlach3dc33f12021-04-23 11:27:42 -05001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Board specific initialization for AM642 EVM
4 *
5 * Copyright (C) 2020-2021 Texas Instruments Incorporated - https://www.ti.com/
6 * Keerthy <j-keerthy@ti.com>
7 *
8 */
9
10#include <common.h>
11#include <asm/io.h>
12#include <spl.h>
Lokesh Vutla01032a42021-05-06 16:44:49 +053013#include <asm/arch/hardware.h>
14#include <asm/arch/sys_proto.h>
15#include <env.h>
16
17#include "../common/board_detect.h"
18
19#define board_is_am64x_gpevm() board_ti_k3_is("AM64-GPEVM")
20#define board_is_am64x_skevm() board_ti_k3_is("AM64-SKEVM")
Dave Gerlach3dc33f12021-04-23 11:27:42 -050021
22DECLARE_GLOBAL_DATA_PTR;
23
24int board_init(void)
25{
26 return 0;
27}
28
29int dram_init(void)
30{
31 gd->ram_size = 0x80000000;
32
33 return 0;
34}
35
36int dram_init_banksize(void)
37{
38 /* Bank 0 declares the memory available in the DDR low region */
39 gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
40 gd->bd->bi_dram[0].size = 0x80000000;
41 gd->ram_size = 0x80000000;
42
43 return 0;
44}
45
46#if defined(CONFIG_SPL_LOAD_FIT)
47int board_fit_config_name_match(const char *name)
48{
49#if defined(CONFIG_TARGET_AM642_A53_EVM)
50 if (!strcmp(name, "k3-am642-evm"))
51 return 0;
52#endif
53
54 return -1;
55}
56#endif
Lokesh Vutla01032a42021-05-06 16:44:49 +053057
58#ifdef CONFIG_TI_I2C_BOARD_DETECT
59int do_board_detect(void)
60{
61 int ret;
62
63 ret = ti_i2c_eeprom_am6_get_base(CONFIG_EEPROM_BUS_ADDRESS,
64 CONFIG_EEPROM_CHIP_ADDRESS);
65 if (ret) {
66 printf("EEPROM not available at 0x%02x, trying to read at 0x%02x\n",
67 CONFIG_EEPROM_CHIP_ADDRESS, CONFIG_EEPROM_CHIP_ADDRESS + 1);
68 ret = ti_i2c_eeprom_am6_get_base(CONFIG_EEPROM_BUS_ADDRESS,
69 CONFIG_EEPROM_CHIP_ADDRESS + 1);
70 if (ret)
71 pr_err("Reading on-board EEPROM at 0x%02x failed %d\n",
72 CONFIG_EEPROM_CHIP_ADDRESS + 1, ret);
73 }
74
75 return ret;
76}
77
78int checkboard(void)
79{
80 struct ti_am6_eeprom *ep = TI_AM6_EEPROM_DATA;
81
82 if (!do_board_detect())
83 printf("Board: %s rev %s\n", ep->name, ep->version);
84
85 return 0;
86}
87
88#ifdef CONFIG_BOARD_LATE_INIT
89static void setup_board_eeprom_env(void)
90{
91 char *name = "am64x_gpevm";
92
93 if (do_board_detect())
94 goto invalid_eeprom;
95
96 if (board_is_am64x_gpevm())
97 name = "am64x_gpevm";
98 else if (board_is_am64x_skevm())
99 name = "am64x_skevm";
100 else
101 printf("Unidentified board claims %s in eeprom header\n",
102 board_ti_get_name());
103
104invalid_eeprom:
105 set_board_info_env_am6(name);
106}
107
108static void setup_serial(void)
109{
110 struct ti_am6_eeprom *ep = TI_AM6_EEPROM_DATA;
111 unsigned long board_serial;
112 char *endp;
113 char serial_string[17] = { 0 };
114
115 if (env_get("serial#"))
116 return;
117
118 board_serial = simple_strtoul(ep->serial, &endp, 16);
119 if (*endp != '\0') {
120 pr_err("Error: Can't set serial# to %s\n", ep->serial);
121 return;
122 }
123
124 snprintf(serial_string, sizeof(serial_string), "%016lx", board_serial);
125 env_set("serial#", serial_string);
126}
127#endif
128#endif
129
130#ifdef CONFIG_BOARD_LATE_INIT
131int board_late_init(void)
132{
133 if (IS_ENABLED(CONFIG_TI_I2C_BOARD_DETECT)) {
134 setup_board_eeprom_env();
135 setup_serial();
136 }
137
138 return 0;
139}
140#endif