blob: 21c58c76d67aeb9069aff4cbc2743462691551e3 [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{
Lokesh Vutla8af2b692021-05-06 16:44:51 +053049 bool eeprom_read = board_ti_was_eeprom_read();
50
51 if (!eeprom_read || board_is_am64x_gpevm()) {
52 if (!strcmp(name, "k3-am642-r5-evm") || !strcmp(name, "k3-am642-evm"))
53 return 0;
54 } else if (board_is_am64x_skevm()) {
55 if (!strcmp(name, "k3-am642-r5-sk") || !strcmp(name, "k3-am642-sk"))
56 return 0;
57 }
Dave Gerlach3dc33f12021-04-23 11:27:42 -050058
59 return -1;
60}
61#endif
Lokesh Vutla01032a42021-05-06 16:44:49 +053062
63#ifdef CONFIG_TI_I2C_BOARD_DETECT
64int do_board_detect(void)
65{
66 int ret;
67
68 ret = ti_i2c_eeprom_am6_get_base(CONFIG_EEPROM_BUS_ADDRESS,
69 CONFIG_EEPROM_CHIP_ADDRESS);
70 if (ret) {
71 printf("EEPROM not available at 0x%02x, trying to read at 0x%02x\n",
72 CONFIG_EEPROM_CHIP_ADDRESS, CONFIG_EEPROM_CHIP_ADDRESS + 1);
73 ret = ti_i2c_eeprom_am6_get_base(CONFIG_EEPROM_BUS_ADDRESS,
74 CONFIG_EEPROM_CHIP_ADDRESS + 1);
75 if (ret)
76 pr_err("Reading on-board EEPROM at 0x%02x failed %d\n",
77 CONFIG_EEPROM_CHIP_ADDRESS + 1, ret);
78 }
79
80 return ret;
81}
82
83int checkboard(void)
84{
85 struct ti_am6_eeprom *ep = TI_AM6_EEPROM_DATA;
86
87 if (!do_board_detect())
88 printf("Board: %s rev %s\n", ep->name, ep->version);
89
90 return 0;
91}
92
93#ifdef CONFIG_BOARD_LATE_INIT
94static void setup_board_eeprom_env(void)
95{
96 char *name = "am64x_gpevm";
97
98 if (do_board_detect())
99 goto invalid_eeprom;
100
101 if (board_is_am64x_gpevm())
102 name = "am64x_gpevm";
103 else if (board_is_am64x_skevm())
104 name = "am64x_skevm";
105 else
106 printf("Unidentified board claims %s in eeprom header\n",
107 board_ti_get_name());
108
109invalid_eeprom:
110 set_board_info_env_am6(name);
111}
112
113static void setup_serial(void)
114{
115 struct ti_am6_eeprom *ep = TI_AM6_EEPROM_DATA;
116 unsigned long board_serial;
117 char *endp;
118 char serial_string[17] = { 0 };
119
120 if (env_get("serial#"))
121 return;
122
Simon Glass3ff49ec2021-07-24 09:03:29 -0600123 board_serial = hextoul(ep->serial, &endp);
Lokesh Vutla01032a42021-05-06 16:44:49 +0530124 if (*endp != '\0') {
125 pr_err("Error: Can't set serial# to %s\n", ep->serial);
126 return;
127 }
128
129 snprintf(serial_string, sizeof(serial_string), "%016lx", board_serial);
130 env_set("serial#", serial_string);
131}
132#endif
133#endif
134
135#ifdef CONFIG_BOARD_LATE_INIT
136int board_late_init(void)
137{
138 if (IS_ENABLED(CONFIG_TI_I2C_BOARD_DETECT)) {
Vignesh Raghavendra3349e212021-05-10 23:44:22 +0530139 struct ti_am6_eeprom *ep = TI_AM6_EEPROM_DATA;
140
Lokesh Vutla01032a42021-05-06 16:44:49 +0530141 setup_board_eeprom_env();
142 setup_serial();
Vignesh Raghavendra3349e212021-05-10 23:44:22 +0530143 /*
144 * The first MAC address for ethernet a.k.a. ethernet0 comes from
145 * efuse populated via the am654 gigabit eth switch subsystem driver.
146 * All the other ones are populated via EEPROM, hence continue with
147 * an index of 1.
148 */
149 board_ti_am6_set_ethaddr(1, ep->mac_addr_cnt);
Lokesh Vutla01032a42021-05-06 16:44:49 +0530150 }
151
152 return 0;
153}
154#endif
Aswath Govindrajucb962f92021-06-04 22:00:34 +0530155
156#define CTRLMMR_USB0_PHY_CTRL 0x43004008
157#define CORE_VOLTAGE 0x80000000
158
159#ifdef CONFIG_SPL_BOARD_INIT
160void spl_board_init(void)
161{
162 u32 val;
163 /* Set USB PHY core voltage to 0.85V */
164 val = readl(CTRLMMR_USB0_PHY_CTRL);
165 val &= ~(CORE_VOLTAGE);
166 writel(val, CTRLMMR_USB0_PHY_CTRL);
167}
168#endif