blob: 34ca3ec9b02782fdd968fea90b69ed7d76fc936e [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Felipe Balbi4750eb62014-11-10 14:02:44 -06002/*
3 * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com
4 *
5 * Author: Felipe Balbi <balbi@ti.com>
6 *
7 * Based on board/ti/dra7xx/evm.c
Felipe Balbi4750eb62014-11-10 14:02:44 -06008 */
9
10#include <common.h>
Simon Glass79fd2142019-08-01 09:46:43 -060011#include <env.h>
Simon Glass3bbe70c2019-12-28 10:44:54 -070012#include <fdt_support.h>
Simon Glassa7b51302019-11-14 12:57:46 -070013#include <init.h>
Simon Glass9bc15642020-02-03 07:36:16 -070014#include <malloc.h>
Felipe Balbi4750eb62014-11-10 14:02:44 -060015#include <palmas.h>
16#include <sata.h>
Simon Glass36736182019-11-14 12:57:24 -070017#include <serial.h>
Felipe Balbi4750eb62014-11-10 14:02:44 -060018#include <usb.h>
Caleb Robey0dfcc932020-01-02 08:17:25 -060019#include <errno.h>
Felipe Balbi4750eb62014-11-10 14:02:44 -060020#include <asm/omap_common.h>
Andreas Dannenberg5cf344b2016-06-27 09:19:22 -050021#include <asm/omap_sec_common.h>
Felipe Balbi4750eb62014-11-10 14:02:44 -060022#include <asm/emif.h>
Lokesh Vutla9f150672015-06-16 20:36:05 +053023#include <asm/gpio.h>
24#include <asm/arch/gpio.h>
Felipe Balbi4750eb62014-11-10 14:02:44 -060025#include <asm/arch/clock.h>
Lokesh Vutlac3d39f92015-06-04 16:42:41 +053026#include <asm/arch/dra7xx_iodelay.h>
Felipe Balbi4750eb62014-11-10 14:02:44 -060027#include <asm/arch/sys_proto.h>
28#include <asm/arch/mmc_host_def.h>
29#include <asm/arch/sata.h>
30#include <asm/arch/gpio.h>
Kishon Vijay Abraham I5f19b2d2015-08-19 14:13:19 +053031#include <asm/arch/omap.h>
Kishon Vijay Abraham I5f19b2d2015-08-19 14:13:19 +053032#include <usb.h>
33#include <linux/usb/gadget.h>
34#include <dwc3-uboot.h>
35#include <dwc3-omap-uboot.h>
36#include <ti-usb-phy-uboot.h>
Kishon Vijay Abraham I110ed012018-01-30 16:01:52 +010037#include <mmc.h>
Tero Kristodfbc6b82019-09-27 19:14:27 +030038#include <dm/uclass.h>
Roger Quadros8835eee2020-02-10 11:59:24 +020039#include <hang.h>
Felipe Balbi4750eb62014-11-10 14:02:44 -060040
Kipisz, Steven161f1382016-02-24 12:30:58 -060041#include "../common/board_detect.h"
Felipe Balbi4750eb62014-11-10 14:02:44 -060042#include "mux_data.h"
43
Caleb Robey0dfcc932020-01-02 08:17:25 -060044#ifdef CONFIG_SUPPORT_EMMC_BOOT
45static int board_bootmode_has_emmc(void);
46#endif
47
Kipisz, Steven161f1382016-02-24 12:30:58 -060048#define board_is_x15() board_ti_is("BBRDX15_")
Lokesh Vutla638e1c02016-11-25 11:14:20 +053049#define board_is_x15_revb1() (board_ti_is("BBRDX15_") && \
Lokesh Vutlaab4f71e2017-07-16 19:59:18 +053050 !strncmp("B.10", board_ti_get_rev(), 3))
Lokesh Vutla816178b2017-07-16 19:59:19 +053051#define board_is_x15_revc() (board_ti_is("BBRDX15_") && \
52 !strncmp("C.00", board_ti_get_rev(), 3))
Kipisz, Steven161f1382016-02-24 12:30:58 -060053#define board_is_am572x_evm() board_ti_is("AM572PM_")
Nishanth Menona2aea1c2016-11-25 11:14:19 +053054#define board_is_am572x_evm_reva3() \
55 (board_ti_is("AM572PM_") && \
Lokesh Vutlaab4f71e2017-07-16 19:59:18 +053056 !strncmp("A.30", board_ti_get_rev(), 3))
Lokesh Vutla374aea02017-12-29 11:47:52 +053057#define board_is_am574x_idk() board_ti_is("AM574IDK")
Steve Kipisz0ac8cea2016-04-08 17:01:29 -050058#define board_is_am572x_idk() board_ti_is("AM572IDK")
Steve Kipiszc95cddd2016-11-25 11:14:24 +053059#define board_is_am571x_idk() board_ti_is("AM571IDK")
Caleb Robey940d6372020-01-02 08:17:27 -060060#define board_is_bbai() board_ti_is("BBONE-AI")
Kipisz, Steven161f1382016-02-24 12:30:58 -060061
Felipe Balbi4750eb62014-11-10 14:02:44 -060062#ifdef CONFIG_DRIVER_TI_CPSW
63#include <cpsw.h>
64#endif
65
66DECLARE_GLOBAL_DATA_PTR;
67
Roger Quadros26130592017-03-13 15:04:28 +020068#define GPIO_ETH_LCD GPIO_TO_PIN(2, 22)
Lokesh Vutla9f150672015-06-16 20:36:05 +053069/* GPIO 7_11 */
70#define GPIO_DDR_VTT_EN 203
71
Nishanth Menond0f399c2017-03-13 15:04:30 +020072/* Touch screen controller to identify the LCD */
73#define OSD_TS_FT_BUS_ADDRESS 0
74#define OSD_TS_FT_CHIP_ADDRESS 0x38
75#define OSD_TS_FT_REG_ID 0xA3
76/*
77 * Touchscreen IDs for various OSD panels
78 * Ref: http://www.osddisplays.com/TI/OSD101T2587-53TS_A.1.pdf
79 */
80/* Used on newer osd101t2587 Panels */
81#define OSD_TS_FT_ID_5x46 0x54
82/* Used on older osd101t2045 Panels */
83#define OSD_TS_FT_ID_5606 0x08
84
Kipisz, Steven161f1382016-02-24 12:30:58 -060085#define SYSINFO_BOARD_NAME_MAX_LEN 45
86
Keerthyee85ebe2016-11-30 15:02:53 +053087#define TPS65903X_PRIMARY_SECONDARY_PAD2 0xFB
88#define TPS65903X_PAD2_POWERHOLD_MASK 0x20
89
Felipe Balbi4750eb62014-11-10 14:02:44 -060090const struct omap_sysinfo sysinfo = {
Kipisz, Steven161f1382016-02-24 12:30:58 -060091 "Board: UNKNOWN(BeagleBoard X15?) REV UNKNOWN\n"
Felipe Balbi4750eb62014-11-10 14:02:44 -060092};
93
94static const struct dmm_lisa_map_regs beagle_x15_lisa_regs = {
95 .dmm_lisa_map_3 = 0x80740300,
96 .is_ma_present = 0x1
97};
98
Steve Kipiszc95cddd2016-11-25 11:14:24 +053099static const struct dmm_lisa_map_regs am571x_idk_lisa_regs = {
100 .dmm_lisa_map_3 = 0x80640100,
101 .is_ma_present = 0x1
102};
103
Lokesh Vutlacbd70db2017-12-29 11:47:54 +0530104static const struct dmm_lisa_map_regs am574x_idk_lisa_regs = {
105 .dmm_lisa_map_2 = 0xc0600200,
106 .dmm_lisa_map_3 = 0x80600100,
107 .is_ma_present = 0x1
108};
109
Caleb Robey940d6372020-01-02 08:17:27 -0600110static const struct dmm_lisa_map_regs bbai_lisa_regs = {
111 .dmm_lisa_map_3 = 0x80640100,
112 .is_ma_present = 0x1
113};
114
Felipe Balbi4750eb62014-11-10 14:02:44 -0600115void emif_get_dmm_regs(const struct dmm_lisa_map_regs **dmm_lisa_regs)
116{
Steve Kipiszc95cddd2016-11-25 11:14:24 +0530117 if (board_is_am571x_idk())
118 *dmm_lisa_regs = &am571x_idk_lisa_regs;
Lokesh Vutlacbd70db2017-12-29 11:47:54 +0530119 else if (board_is_am574x_idk())
120 *dmm_lisa_regs = &am574x_idk_lisa_regs;
Caleb Robey940d6372020-01-02 08:17:27 -0600121 else if (board_is_bbai())
122 *dmm_lisa_regs = &bbai_lisa_regs;
Steve Kipiszc95cddd2016-11-25 11:14:24 +0530123 else
124 *dmm_lisa_regs = &beagle_x15_lisa_regs;
Felipe Balbi4750eb62014-11-10 14:02:44 -0600125}
126
127static const struct emif_regs beagle_x15_emif1_ddr3_532mhz_emif_regs = {
Keerthy66dd8062016-05-24 11:45:07 +0530128 .sdram_config_init = 0x61851b32,
129 .sdram_config = 0x61851b32,
130 .sdram_config2 = 0x08000000,
131 .ref_ctrl = 0x000040F1,
132 .ref_ctrl_final = 0x00001035,
133 .sdram_tim1 = 0xcccf36ab,
134 .sdram_tim2 = 0x308f7fda,
135 .sdram_tim3 = 0x409f88a8,
136 .read_idle_ctrl = 0x00050000,
137 .zq_config = 0x5007190b,
138 .temp_alert_config = 0x00000000,
139 .emif_ddr_phy_ctlr_1_init = 0x0024400b,
140 .emif_ddr_phy_ctlr_1 = 0x0e24400b,
141 .emif_ddr_ext_phy_ctrl_1 = 0x10040100,
142 .emif_ddr_ext_phy_ctrl_2 = 0x00910091,
143 .emif_ddr_ext_phy_ctrl_3 = 0x00950095,
144 .emif_ddr_ext_phy_ctrl_4 = 0x009b009b,
145 .emif_ddr_ext_phy_ctrl_5 = 0x009e009e,
146 .emif_rd_wr_lvl_rmp_win = 0x00000000,
147 .emif_rd_wr_lvl_rmp_ctl = 0x80000000,
148 .emif_rd_wr_lvl_ctl = 0x00000000,
149 .emif_rd_wr_exec_thresh = 0x00000305
Felipe Balbi4750eb62014-11-10 14:02:44 -0600150};
151
Lokesh Vutla979d2c32015-06-03 14:43:21 +0530152/* Ext phy ctrl regs 1-35 */
Felipe Balbi4750eb62014-11-10 14:02:44 -0600153static const u32 beagle_x15_emif1_ddr3_ext_phy_ctrl_const_regs[] = {
Lokesh Vutla979d2c32015-06-03 14:43:21 +0530154 0x10040100,
Lokesh Vutla306b5972016-03-08 09:11:35 +0530155 0x00910091,
156 0x00950095,
157 0x009B009B,
158 0x009E009E,
159 0x00980098,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600160 0x00340034,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600161 0x00350035,
Lokesh Vutla306b5972016-03-08 09:11:35 +0530162 0x00340034,
163 0x00310031,
164 0x00340034,
165 0x007F007F,
166 0x007F007F,
167 0x007F007F,
168 0x007F007F,
169 0x007F007F,
170 0x00480048,
171 0x004A004A,
172 0x00520052,
173 0x00550055,
174 0x00500050,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600175 0x00000000,
176 0x00600020,
Lokesh Vutla979d2c32015-06-03 14:43:21 +0530177 0x40011080,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600178 0x08102040,
Lokesh Vutla306b5972016-03-08 09:11:35 +0530179 0x0,
180 0x0,
181 0x0,
182 0x0,
Lokesh Vutla51a0f1f2015-06-03 14:43:22 +0530183 0x0,
184 0x0,
185 0x0,
186 0x0,
Lokesh Vutla306b5972016-03-08 09:11:35 +0530187 0x0,
Lokesh Vutla51a0f1f2015-06-03 14:43:22 +0530188 0x0
Felipe Balbi4750eb62014-11-10 14:02:44 -0600189};
190
191static const struct emif_regs beagle_x15_emif2_ddr3_532mhz_emif_regs = {
Keerthy66dd8062016-05-24 11:45:07 +0530192 .sdram_config_init = 0x61851b32,
193 .sdram_config = 0x61851b32,
194 .sdram_config2 = 0x08000000,
195 .ref_ctrl = 0x000040F1,
196 .ref_ctrl_final = 0x00001035,
197 .sdram_tim1 = 0xcccf36b3,
198 .sdram_tim2 = 0x308f7fda,
199 .sdram_tim3 = 0x407f88a8,
200 .read_idle_ctrl = 0x00050000,
201 .zq_config = 0x5007190b,
202 .temp_alert_config = 0x00000000,
203 .emif_ddr_phy_ctlr_1_init = 0x0024400b,
204 .emif_ddr_phy_ctlr_1 = 0x0e24400b,
205 .emif_ddr_ext_phy_ctrl_1 = 0x10040100,
206 .emif_ddr_ext_phy_ctrl_2 = 0x00910091,
207 .emif_ddr_ext_phy_ctrl_3 = 0x00950095,
208 .emif_ddr_ext_phy_ctrl_4 = 0x009b009b,
209 .emif_ddr_ext_phy_ctrl_5 = 0x009e009e,
210 .emif_rd_wr_lvl_rmp_win = 0x00000000,
211 .emif_rd_wr_lvl_rmp_ctl = 0x80000000,
212 .emif_rd_wr_lvl_ctl = 0x00000000,
213 .emif_rd_wr_exec_thresh = 0x00000305
Felipe Balbi4750eb62014-11-10 14:02:44 -0600214};
215
216static const u32 beagle_x15_emif2_ddr3_ext_phy_ctrl_const_regs[] = {
Lokesh Vutla979d2c32015-06-03 14:43:21 +0530217 0x10040100,
Lokesh Vutla306b5972016-03-08 09:11:35 +0530218 0x00910091,
219 0x00950095,
220 0x009B009B,
221 0x009E009E,
222 0x00980098,
223 0x00340034,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600224 0x00350035,
Lokesh Vutla306b5972016-03-08 09:11:35 +0530225 0x00340034,
226 0x00310031,
227 0x00340034,
228 0x007F007F,
229 0x007F007F,
230 0x007F007F,
231 0x007F007F,
232 0x007F007F,
233 0x00480048,
234 0x004A004A,
235 0x00520052,
236 0x00550055,
237 0x00500050,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600238 0x00000000,
239 0x00600020,
Lokesh Vutla979d2c32015-06-03 14:43:21 +0530240 0x40011080,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600241 0x08102040,
Lokesh Vutla306b5972016-03-08 09:11:35 +0530242 0x0,
243 0x0,
244 0x0,
245 0x0,
246 0x0,
Lokesh Vutla51a0f1f2015-06-03 14:43:22 +0530247 0x0,
248 0x0,
249 0x0,
250 0x0,
251 0x0
Felipe Balbi4750eb62014-11-10 14:02:44 -0600252};
253
Steve Kipisz81c46742017-08-22 13:52:58 +0530254static const struct emif_regs am571x_emif1_ddr3_666mhz_emif_regs = {
255 .sdram_config_init = 0x61863332,
256 .sdram_config = 0x61863332,
257 .sdram_config2 = 0x08000000,
258 .ref_ctrl = 0x0000514d,
259 .ref_ctrl_final = 0x0000144a,
260 .sdram_tim1 = 0xd333887c,
Lokesh Vutlacbd70db2017-12-29 11:47:54 +0530261 .sdram_tim2 = 0x30b37fe3,
262 .sdram_tim3 = 0x409f8ad8,
Steve Kipisz81c46742017-08-22 13:52:58 +0530263 .read_idle_ctrl = 0x00050000,
264 .zq_config = 0x5007190b,
265 .temp_alert_config = 0x00000000,
266 .emif_ddr_phy_ctlr_1_init = 0x0024400f,
267 .emif_ddr_phy_ctlr_1 = 0x0e24400f,
268 .emif_ddr_ext_phy_ctrl_1 = 0x10040100,
269 .emif_ddr_ext_phy_ctrl_2 = 0x00910091,
270 .emif_ddr_ext_phy_ctrl_3 = 0x00950095,
271 .emif_ddr_ext_phy_ctrl_4 = 0x009b009b,
272 .emif_ddr_ext_phy_ctrl_5 = 0x009e009e,
273 .emif_rd_wr_lvl_rmp_win = 0x00000000,
274 .emif_rd_wr_lvl_rmp_ctl = 0x80000000,
275 .emif_rd_wr_lvl_ctl = 0x00000000,
276 .emif_rd_wr_exec_thresh = 0x00000305
277};
278
Lokesh Vutlacbd70db2017-12-29 11:47:54 +0530279static const struct emif_regs am574x_emif1_ddr3_666mhz_emif_ecc_regs = {
280 .sdram_config_init = 0x61863332,
281 .sdram_config = 0x61863332,
282 .sdram_config2 = 0x08000000,
283 .ref_ctrl = 0x0000514d,
284 .ref_ctrl_final = 0x0000144a,
285 .sdram_tim1 = 0xd333887c,
286 .sdram_tim2 = 0x30b37fe3,
287 .sdram_tim3 = 0x409f8ad8,
288 .read_idle_ctrl = 0x00050000,
289 .zq_config = 0x5007190b,
290 .temp_alert_config = 0x00000000,
291 .emif_ddr_phy_ctlr_1_init = 0x0024400f,
292 .emif_ddr_phy_ctlr_1 = 0x0e24400f,
293 .emif_ddr_ext_phy_ctrl_1 = 0x10040100,
294 .emif_ddr_ext_phy_ctrl_2 = 0x00910091,
295 .emif_ddr_ext_phy_ctrl_3 = 0x00950095,
296 .emif_ddr_ext_phy_ctrl_4 = 0x009b009b,
297 .emif_ddr_ext_phy_ctrl_5 = 0x009e009e,
298 .emif_rd_wr_lvl_rmp_win = 0x00000000,
299 .emif_rd_wr_lvl_rmp_ctl = 0x80000000,
300 .emif_rd_wr_lvl_ctl = 0x00000000,
301 .emif_rd_wr_exec_thresh = 0x00000305,
302 .emif_ecc_ctrl_reg = 0xD0000001,
303 .emif_ecc_address_range_1 = 0x3FFF0000,
304 .emif_ecc_address_range_2 = 0x00000000
305};
306
Felipe Balbi4750eb62014-11-10 14:02:44 -0600307void emif_get_reg_dump(u32 emif_nr, const struct emif_regs **regs)
308{
309 switch (emif_nr) {
310 case 1:
Steve Kipisz81c46742017-08-22 13:52:58 +0530311 if (board_is_am571x_idk())
312 *regs = &am571x_emif1_ddr3_666mhz_emif_regs;
Lokesh Vutlacbd70db2017-12-29 11:47:54 +0530313 else if (board_is_am574x_idk())
314 *regs = &am574x_emif1_ddr3_666mhz_emif_ecc_regs;
Steve Kipisz81c46742017-08-22 13:52:58 +0530315 else
316 *regs = &beagle_x15_emif1_ddr3_532mhz_emif_regs;
Felipe Balbi4750eb62014-11-10 14:02:44 -0600317 break;
318 case 2:
Lokesh Vutlacbd70db2017-12-29 11:47:54 +0530319 if (board_is_am574x_idk())
320 *regs = &am571x_emif1_ddr3_666mhz_emif_regs;
321 else
322 *regs = &beagle_x15_emif2_ddr3_532mhz_emif_regs;
Felipe Balbi4750eb62014-11-10 14:02:44 -0600323 break;
324 }
325}
326
327void emif_get_ext_phy_ctrl_const_regs(u32 emif_nr, const u32 **regs, u32 *size)
328{
329 switch (emif_nr) {
330 case 1:
331 *regs = beagle_x15_emif1_ddr3_ext_phy_ctrl_const_regs;
332 *size = ARRAY_SIZE(beagle_x15_emif1_ddr3_ext_phy_ctrl_const_regs);
333 break;
334 case 2:
335 *regs = beagle_x15_emif2_ddr3_ext_phy_ctrl_const_regs;
336 *size = ARRAY_SIZE(beagle_x15_emif2_ddr3_ext_phy_ctrl_const_regs);
337 break;
338 }
339}
340
341struct vcores_data beagle_x15_volts = {
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530342 .mpu.value[OPP_NOM] = VDD_MPU_DRA7_NOM,
343 .mpu.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_MPU_NOM,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600344 .mpu.efuse.reg_bits = DRA752_EFUSE_REGBITS,
345 .mpu.addr = TPS659038_REG_ADDR_SMPS12,
346 .mpu.pmic = &tps659038,
Keerthy66dd8062016-05-24 11:45:07 +0530347 .mpu.abb_tx_done_mask = OMAP_ABB_MPU_TXDONE_MASK,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600348
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530349 .eve.value[OPP_NOM] = VDD_EVE_DRA7_NOM,
350 .eve.value[OPP_OD] = VDD_EVE_DRA7_OD,
351 .eve.value[OPP_HIGH] = VDD_EVE_DRA7_HIGH,
352 .eve.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_DSPEVE_NOM,
353 .eve.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_DSPEVE_OD,
354 .eve.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_DSPEVE_HIGH,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600355 .eve.efuse.reg_bits = DRA752_EFUSE_REGBITS,
356 .eve.addr = TPS659038_REG_ADDR_SMPS45,
357 .eve.pmic = &tps659038,
Nishanth Menon59b92af2016-04-21 14:34:25 -0500358 .eve.abb_tx_done_mask = OMAP_ABB_EVE_TXDONE_MASK,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600359
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530360 .gpu.value[OPP_NOM] = VDD_GPU_DRA7_NOM,
361 .gpu.value[OPP_OD] = VDD_GPU_DRA7_OD,
362 .gpu.value[OPP_HIGH] = VDD_GPU_DRA7_HIGH,
363 .gpu.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_GPU_NOM,
364 .gpu.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_GPU_OD,
365 .gpu.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_GPU_HIGH,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600366 .gpu.efuse.reg_bits = DRA752_EFUSE_REGBITS,
367 .gpu.addr = TPS659038_REG_ADDR_SMPS45,
368 .gpu.pmic = &tps659038,
Nishanth Menon59b92af2016-04-21 14:34:25 -0500369 .gpu.abb_tx_done_mask = OMAP_ABB_GPU_TXDONE_MASK,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600370
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530371 .core.value[OPP_NOM] = VDD_CORE_DRA7_NOM,
372 .core.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_CORE_NOM,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600373 .core.efuse.reg_bits = DRA752_EFUSE_REGBITS,
374 .core.addr = TPS659038_REG_ADDR_SMPS6,
375 .core.pmic = &tps659038,
376
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530377 .iva.value[OPP_NOM] = VDD_IVA_DRA7_NOM,
378 .iva.value[OPP_OD] = VDD_IVA_DRA7_OD,
379 .iva.value[OPP_HIGH] = VDD_IVA_DRA7_HIGH,
380 .iva.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_IVA_NOM,
381 .iva.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_IVA_OD,
382 .iva.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_IVA_HIGH,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600383 .iva.efuse.reg_bits = DRA752_EFUSE_REGBITS,
384 .iva.addr = TPS659038_REG_ADDR_SMPS45,
385 .iva.pmic = &tps659038,
Nishanth Menon59b92af2016-04-21 14:34:25 -0500386 .iva.abb_tx_done_mask = OMAP_ABB_IVA_TXDONE_MASK,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600387};
388
Keerthy152e9932016-05-24 11:45:06 +0530389struct vcores_data am572x_idk_volts = {
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530390 .mpu.value[OPP_NOM] = VDD_MPU_DRA7_NOM,
391 .mpu.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_MPU_NOM,
Keerthy152e9932016-05-24 11:45:06 +0530392 .mpu.efuse.reg_bits = DRA752_EFUSE_REGBITS,
393 .mpu.addr = TPS659038_REG_ADDR_SMPS12,
394 .mpu.pmic = &tps659038,
395 .mpu.abb_tx_done_mask = OMAP_ABB_MPU_TXDONE_MASK,
396
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530397 .eve.value[OPP_NOM] = VDD_EVE_DRA7_NOM,
398 .eve.value[OPP_OD] = VDD_EVE_DRA7_OD,
399 .eve.value[OPP_HIGH] = VDD_EVE_DRA7_HIGH,
400 .eve.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_DSPEVE_NOM,
401 .eve.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_DSPEVE_OD,
402 .eve.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_DSPEVE_HIGH,
Keerthy152e9932016-05-24 11:45:06 +0530403 .eve.efuse.reg_bits = DRA752_EFUSE_REGBITS,
404 .eve.addr = TPS659038_REG_ADDR_SMPS45,
405 .eve.pmic = &tps659038,
406 .eve.abb_tx_done_mask = OMAP_ABB_EVE_TXDONE_MASK,
407
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530408 .gpu.value[OPP_NOM] = VDD_GPU_DRA7_NOM,
409 .gpu.value[OPP_OD] = VDD_GPU_DRA7_OD,
410 .gpu.value[OPP_HIGH] = VDD_GPU_DRA7_HIGH,
411 .gpu.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_GPU_NOM,
412 .gpu.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_GPU_OD,
413 .gpu.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_GPU_HIGH,
Keerthy152e9932016-05-24 11:45:06 +0530414 .gpu.efuse.reg_bits = DRA752_EFUSE_REGBITS,
415 .gpu.addr = TPS659038_REG_ADDR_SMPS6,
416 .gpu.pmic = &tps659038,
417 .gpu.abb_tx_done_mask = OMAP_ABB_GPU_TXDONE_MASK,
418
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530419 .core.value[OPP_NOM] = VDD_CORE_DRA7_NOM,
420 .core.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_CORE_NOM,
Keerthy152e9932016-05-24 11:45:06 +0530421 .core.efuse.reg_bits = DRA752_EFUSE_REGBITS,
422 .core.addr = TPS659038_REG_ADDR_SMPS7,
423 .core.pmic = &tps659038,
424
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530425 .iva.value[OPP_NOM] = VDD_IVA_DRA7_NOM,
426 .iva.value[OPP_OD] = VDD_IVA_DRA7_OD,
427 .iva.value[OPP_HIGH] = VDD_IVA_DRA7_HIGH,
428 .iva.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_IVA_NOM,
429 .iva.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_IVA_OD,
430 .iva.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_IVA_HIGH,
Keerthy152e9932016-05-24 11:45:06 +0530431 .iva.efuse.reg_bits = DRA752_EFUSE_REGBITS,
432 .iva.addr = TPS659038_REG_ADDR_SMPS8,
433 .iva.pmic = &tps659038,
434 .iva.abb_tx_done_mask = OMAP_ABB_IVA_TXDONE_MASK,
435};
436
Keerthy9cc2aee2017-05-25 15:37:34 +0530437struct vcores_data am571x_idk_volts = {
438 .mpu.value[OPP_NOM] = VDD_MPU_DRA7_NOM,
439 .mpu.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_MPU_NOM,
440 .mpu.efuse.reg_bits = DRA752_EFUSE_REGBITS,
441 .mpu.addr = TPS659038_REG_ADDR_SMPS12,
442 .mpu.pmic = &tps659038,
443 .mpu.abb_tx_done_mask = OMAP_ABB_MPU_TXDONE_MASK,
444
445 .eve.value[OPP_NOM] = VDD_EVE_DRA7_NOM,
446 .eve.value[OPP_OD] = VDD_EVE_DRA7_OD,
447 .eve.value[OPP_HIGH] = VDD_EVE_DRA7_HIGH,
448 .eve.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_DSPEVE_NOM,
449 .eve.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_DSPEVE_OD,
450 .eve.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_DSPEVE_HIGH,
451 .eve.efuse.reg_bits = DRA752_EFUSE_REGBITS,
452 .eve.addr = TPS659038_REG_ADDR_SMPS45,
453 .eve.pmic = &tps659038,
454 .eve.abb_tx_done_mask = OMAP_ABB_EVE_TXDONE_MASK,
455
456 .gpu.value[OPP_NOM] = VDD_GPU_DRA7_NOM,
457 .gpu.value[OPP_OD] = VDD_GPU_DRA7_OD,
458 .gpu.value[OPP_HIGH] = VDD_GPU_DRA7_HIGH,
459 .gpu.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_GPU_NOM,
460 .gpu.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_GPU_OD,
461 .gpu.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_GPU_HIGH,
462 .gpu.efuse.reg_bits = DRA752_EFUSE_REGBITS,
463 .gpu.addr = TPS659038_REG_ADDR_SMPS6,
464 .gpu.pmic = &tps659038,
465 .gpu.abb_tx_done_mask = OMAP_ABB_GPU_TXDONE_MASK,
466
467 .core.value[OPP_NOM] = VDD_CORE_DRA7_NOM,
468 .core.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_CORE_NOM,
469 .core.efuse.reg_bits = DRA752_EFUSE_REGBITS,
470 .core.addr = TPS659038_REG_ADDR_SMPS7,
471 .core.pmic = &tps659038,
472
473 .iva.value[OPP_NOM] = VDD_IVA_DRA7_NOM,
474 .iva.value[OPP_OD] = VDD_IVA_DRA7_OD,
475 .iva.value[OPP_HIGH] = VDD_IVA_DRA7_HIGH,
476 .iva.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_IVA_NOM,
477 .iva.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_IVA_OD,
478 .iva.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_IVA_HIGH,
479 .iva.efuse.reg_bits = DRA752_EFUSE_REGBITS,
480 .iva.addr = TPS659038_REG_ADDR_SMPS45,
481 .iva.pmic = &tps659038,
482 .iva.abb_tx_done_mask = OMAP_ABB_IVA_TXDONE_MASK,
483};
484
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530485int get_voltrail_opp(int rail_offset)
486{
487 int opp;
488
489 switch (rail_offset) {
490 case VOLT_MPU:
491 opp = DRA7_MPU_OPP;
492 break;
493 case VOLT_CORE:
494 opp = DRA7_CORE_OPP;
495 break;
496 case VOLT_GPU:
497 opp = DRA7_GPU_OPP;
498 break;
499 case VOLT_EVE:
500 opp = DRA7_DSPEVE_OPP;
501 break;
502 case VOLT_IVA:
503 opp = DRA7_IVA_OPP;
504 break;
505 default:
506 opp = OPP_NOM;
507 }
508
509 return opp;
510}
511
512
Kipisz, Steven161f1382016-02-24 12:30:58 -0600513#ifdef CONFIG_SPL_BUILD
514/* No env to setup for SPL */
515static inline void setup_board_eeprom_env(void) { }
516
517/* Override function to read eeprom information */
518void do_board_detect(void)
519{
520 int rc;
521
522 rc = ti_i2c_eeprom_am_get(CONFIG_EEPROM_BUS_ADDRESS,
523 CONFIG_EEPROM_CHIP_ADDRESS);
524 if (rc)
525 printf("ti_i2c_eeprom_init failed %d\n", rc);
Caleb Robey0dfcc932020-01-02 08:17:25 -0600526
527#ifdef CONFIG_SUPPORT_EMMC_BOOT
528 rc = board_bootmode_has_emmc();
529 if (!rc)
530 rc = ti_emmc_boardid_get();
531 if (rc)
532 printf("ti_emmc_boardid_get failed %d\n", rc);
533#endif
Kipisz, Steven161f1382016-02-24 12:30:58 -0600534}
535
536#else /* CONFIG_SPL_BUILD */
537
538/* Override function to read eeprom information: actual i2c read done by SPL*/
539void do_board_detect(void)
540{
541 char *bname = NULL;
542 int rc;
543
544 rc = ti_i2c_eeprom_am_get(CONFIG_EEPROM_BUS_ADDRESS,
545 CONFIG_EEPROM_CHIP_ADDRESS);
546 if (rc)
547 printf("ti_i2c_eeprom_init failed %d\n", rc);
548
Caleb Robey0dfcc932020-01-02 08:17:25 -0600549#ifdef CONFIG_SUPPORT_EMMC_BOOT
550 rc = board_bootmode_has_emmc();
551 if (!rc)
552 rc = ti_emmc_boardid_get();
553 if (rc)
554 printf("ti_emmc_boardid_get failed %d\n", rc);
555#endif
556
Kipisz, Steven161f1382016-02-24 12:30:58 -0600557 if (board_is_x15())
558 bname = "BeagleBoard X15";
559 else if (board_is_am572x_evm())
560 bname = "AM572x EVM";
Lokesh Vutla374aea02017-12-29 11:47:52 +0530561 else if (board_is_am574x_idk())
562 bname = "AM574x IDK";
Steve Kipisz0ac8cea2016-04-08 17:01:29 -0500563 else if (board_is_am572x_idk())
564 bname = "AM572x IDK";
Steve Kipiszc95cddd2016-11-25 11:14:24 +0530565 else if (board_is_am571x_idk())
566 bname = "AM571x IDK";
Caleb Robey940d6372020-01-02 08:17:27 -0600567 else if (board_is_bbai())
568 bname = "BeagleBone AI";
Kipisz, Steven161f1382016-02-24 12:30:58 -0600569
570 if (bname)
571 snprintf(sysinfo.board_string, SYSINFO_BOARD_NAME_MAX_LEN,
572 "Board: %s REV %s\n", bname, board_ti_get_rev());
573}
574
575static void setup_board_eeprom_env(void)
576{
577 char *name = "beagle_x15";
578 int rc;
579
580 rc = ti_i2c_eeprom_am_get(CONFIG_EEPROM_BUS_ADDRESS,
581 CONFIG_EEPROM_CHIP_ADDRESS);
582 if (rc)
583 goto invalid_eeprom;
584
Nishanth Menona2aea1c2016-11-25 11:14:19 +0530585 if (board_is_x15()) {
Lokesh Vutla638e1c02016-11-25 11:14:20 +0530586 if (board_is_x15_revb1())
587 name = "beagle_x15_revb1";
Lokesh Vutla816178b2017-07-16 19:59:19 +0530588 else if (board_is_x15_revc())
589 name = "beagle_x15_revc";
Lokesh Vutla638e1c02016-11-25 11:14:20 +0530590 else
591 name = "beagle_x15";
Nishanth Menona2aea1c2016-11-25 11:14:19 +0530592 } else if (board_is_am572x_evm()) {
593 if (board_is_am572x_evm_reva3())
594 name = "am57xx_evm_reva3";
595 else
596 name = "am57xx_evm";
Lokesh Vutla374aea02017-12-29 11:47:52 +0530597 } else if (board_is_am574x_idk()) {
598 name = "am574x_idk";
Nishanth Menona2aea1c2016-11-25 11:14:19 +0530599 } else if (board_is_am572x_idk()) {
Steve Kipisz0ac8cea2016-04-08 17:01:29 -0500600 name = "am572x_idk";
Steve Kipiszc95cddd2016-11-25 11:14:24 +0530601 } else if (board_is_am571x_idk()) {
602 name = "am571x_idk";
Caleb Robey940d6372020-01-02 08:17:27 -0600603 } else if (board_is_bbai()) {
604 name = "am5729_beagleboneai";
Nishanth Menona2aea1c2016-11-25 11:14:19 +0530605 } else {
Kipisz, Steven161f1382016-02-24 12:30:58 -0600606 printf("Unidentified board claims %s in eeprom header\n",
607 board_ti_get_name());
Nishanth Menona2aea1c2016-11-25 11:14:19 +0530608 }
Kipisz, Steven161f1382016-02-24 12:30:58 -0600609
610invalid_eeprom:
611 set_board_info_env(name);
612}
613
614#endif /* CONFIG_SPL_BUILD */
615
Keerthy152e9932016-05-24 11:45:06 +0530616void vcores_init(void)
617{
Lokesh Vutla6e9635c2017-12-29 11:47:53 +0530618 if (board_is_am572x_idk() || board_is_am574x_idk())
Keerthy152e9932016-05-24 11:45:06 +0530619 *omap_vcores = &am572x_idk_volts;
Keerthy9cc2aee2017-05-25 15:37:34 +0530620 else if (board_is_am571x_idk())
621 *omap_vcores = &am571x_idk_volts;
Keerthy152e9932016-05-24 11:45:06 +0530622 else
623 *omap_vcores = &beagle_x15_volts;
624}
625
Felipe Balbi4750eb62014-11-10 14:02:44 -0600626void hw_data_init(void)
627{
628 *prcm = &dra7xx_prcm;
Steve Kipisz81c46742017-08-22 13:52:58 +0530629 if (is_dra72x())
630 *dplls_data = &dra72x_dplls;
Lokesh Vutla6e9635c2017-12-29 11:47:53 +0530631 else if (is_dra76x())
632 *dplls_data = &dra76x_dplls;
Steve Kipisz81c46742017-08-22 13:52:58 +0530633 else
634 *dplls_data = &dra7xx_dplls;
Felipe Balbi4750eb62014-11-10 14:02:44 -0600635 *ctrl = &dra7xx_ctrl;
636}
637
Roger Quadros26130592017-03-13 15:04:28 +0200638bool am571x_idk_needs_lcd(void)
639{
640 bool needs_lcd;
641
642 gpio_request(GPIO_ETH_LCD, "nLCD_Detect");
643 if (gpio_get_value(GPIO_ETH_LCD))
644 needs_lcd = false;
645 else
646 needs_lcd = true;
647
648 gpio_free(GPIO_ETH_LCD);
649
650 return needs_lcd;
651}
652
Felipe Balbi4750eb62014-11-10 14:02:44 -0600653int board_init(void)
654{
655 gpmc_init();
656 gd->bd->bi_boot_params = (CONFIG_SYS_SDRAM_BASE + 0x100);
657
658 return 0;
659}
660
Nishanth Menond0f399c2017-03-13 15:04:30 +0200661void am57x_idk_lcd_detect(void)
Felipe Balbi4750eb62014-11-10 14:02:44 -0600662{
Nishanth Menond0f399c2017-03-13 15:04:30 +0200663 int r = -ENODEV;
664 char *idk_lcd = "no";
Jean-Jacques Hiblot184ec9a2018-12-07 14:50:50 +0100665 struct udevice *dev;
Nishanth Menond0f399c2017-03-13 15:04:30 +0200666
667 /* Only valid for IDKs */
Caleb Robey940d6372020-01-02 08:17:27 -0600668 if (board_is_x15() || board_is_am572x_evm() || board_is_bbai())
Nishanth Menond0f399c2017-03-13 15:04:30 +0200669 return;
670
671 /* Only AM571x IDK has gpio control detect.. so check that */
672 if (board_is_am571x_idk() && !am571x_idk_needs_lcd())
673 goto out;
674
Jean-Jacques Hiblot52a51512018-12-07 14:50:49 +0100675 r = i2c_get_chip_for_busnum(OSD_TS_FT_BUS_ADDRESS,
676 OSD_TS_FT_CHIP_ADDRESS, 1, &dev);
Nishanth Menond0f399c2017-03-13 15:04:30 +0200677 if (r) {
Jean-Jacques Hiblot52a51512018-12-07 14:50:49 +0100678 printf("%s: Failed to get I2C device %d/%d (ret %d)\n",
679 __func__, OSD_TS_FT_BUS_ADDRESS, OSD_TS_FT_CHIP_ADDRESS,
680 r);
Nishanth Menond0f399c2017-03-13 15:04:30 +0200681 /* AM572x IDK has no explicit settings for optional LCD kit */
Jean-Jacques Hiblot52a51512018-12-07 14:50:49 +0100682 if (board_is_am571x_idk())
Nishanth Menond0f399c2017-03-13 15:04:30 +0200683 printf("%s: Touch screen detect failed: %d!\n",
684 __func__, r);
Nishanth Menond0f399c2017-03-13 15:04:30 +0200685 goto out;
686 }
687
688 /* Read FT ID */
Jean-Jacques Hiblot52a51512018-12-07 14:50:49 +0100689 r = dm_i2c_reg_read(dev, OSD_TS_FT_REG_ID);
690 if (r < 0) {
Nishanth Menond0f399c2017-03-13 15:04:30 +0200691 printf("%s: Touch screen ID read %d:0x%02x[0x%02x] failed:%d\n",
692 __func__, OSD_TS_FT_BUS_ADDRESS, OSD_TS_FT_CHIP_ADDRESS,
693 OSD_TS_FT_REG_ID, r);
694 goto out;
695 }
696
Jean-Jacques Hiblot184ec9a2018-12-07 14:50:50 +0100697 switch (r) {
Nishanth Menond0f399c2017-03-13 15:04:30 +0200698 case OSD_TS_FT_ID_5606:
699 idk_lcd = "osd101t2045";
700 break;
701 case OSD_TS_FT_ID_5x46:
702 idk_lcd = "osd101t2587";
703 break;
704 default:
705 printf("%s: Unidentifed Touch screen ID 0x%02x\n",
Jean-Jacques Hiblot184ec9a2018-12-07 14:50:50 +0100706 __func__, r);
Nishanth Menond0f399c2017-03-13 15:04:30 +0200707 /* we will let default be "no lcd" */
708 }
709out:
Simon Glass6a38e412017-08-03 12:22:09 -0600710 env_set("idk_lcd", idk_lcd);
Roger Quadros8835eee2020-02-10 11:59:24 +0200711
712 /*
713 * On AM571x_IDK, no Display with J51 set to LCD is considered as an
714 * invalid configuration and we prevent boot to get user attention.
715 */
716 if (board_is_am571x_idk() && am571x_idk_needs_lcd() &&
717 !strncmp(idk_lcd, "no", 2)) {
718 printf("%s: Invalid HW configuration: display not detected/supported but J51 is set. Remove J51 to boot without display.\n",
719 __func__);
720 hang();
721 }
722
Nishanth Menond0f399c2017-03-13 15:04:30 +0200723 return;
724}
Roger Quadros26130592017-03-13 15:04:28 +0200725
Vignesh R98c5f632018-11-29 10:57:42 +0100726#if CONFIG_IS_ENABLED(DM_USB) && CONFIG_IS_ENABLED(OF_CONTROL)
727static int device_okay(const char *path)
728{
729 int node;
730
731 node = fdt_path_offset(gd->fdt_blob, path);
732 if (node < 0)
733 return 0;
734
735 return fdtdec_get_is_enabled(gd->fdt_blob, node);
736}
737#endif
738
Nishanth Menond0f399c2017-03-13 15:04:30 +0200739int board_late_init(void)
740{
Kipisz, Steven161f1382016-02-24 12:30:58 -0600741 setup_board_eeprom_env();
Keerthyee85ebe2016-11-30 15:02:53 +0530742 u8 val;
Tero Kristodfbc6b82019-09-27 19:14:27 +0300743 struct udevice *dev;
Kipisz, Steven161f1382016-02-24 12:30:58 -0600744
Felipe Balbi4750eb62014-11-10 14:02:44 -0600745 /*
746 * DEV_CTRL.DEV_ON = 1 please - else palmas switches off in 8 seconds
747 * This is the POWERHOLD-in-Low behavior.
748 */
749 palmas_i2c_write_u8(TPS65903X_CHIP_P1, 0xA0, 0x1);
Lokesh Vutla2c47e8c2016-11-29 11:58:02 +0530750
751 /*
752 * Default FIT boot on HS devices. Non FIT images are not allowed
753 * on HS devices.
754 */
755 if (get_device_type() == HS_DEVICE)
Simon Glass6a38e412017-08-03 12:22:09 -0600756 env_set("boot_fit", "1");
Lokesh Vutla2c47e8c2016-11-29 11:58:02 +0530757
Keerthyee85ebe2016-11-30 15:02:53 +0530758 /*
759 * Set the GPIO7 Pad to POWERHOLD. This has higher priority
760 * over DEV_CTRL.DEV_ON bit. This can be reset in case of
761 * PMIC Power off. So to be on the safer side set it back
762 * to POWERHOLD mode irrespective of the current state.
763 */
764 palmas_i2c_read_u8(TPS65903X_CHIP_P1, TPS65903X_PRIMARY_SECONDARY_PAD2,
765 &val);
766 val = val | TPS65903X_PAD2_POWERHOLD_MASK;
767 palmas_i2c_write_u8(TPS65903X_CHIP_P1, TPS65903X_PRIMARY_SECONDARY_PAD2,
768 val);
769
Semen Protsenko4b0721f2017-02-13 19:09:37 +0200770 omap_die_id_serial();
Semen Protsenkob72dccd2017-05-22 19:16:41 +0300771 omap_set_fastboot_vars();
Semen Protsenko4b0721f2017-02-13 19:09:37 +0200772
Nishanth Menond0f399c2017-03-13 15:04:30 +0200773 am57x_idk_lcd_detect();
Roger Quadros26130592017-03-13 15:04:28 +0200774
Tero Kristodfbc6b82019-09-27 19:14:27 +0300775 /* Just probe the potentially supported cdce913 device */
776 uclass_get_device(UCLASS_CLK, 0, &dev);
777
Caleb Robey940d6372020-01-02 08:17:27 -0600778 if (board_is_bbai())
779 env_set("console", "ttyS0,115200n8");
780
Roger Quadros26130592017-03-13 15:04:28 +0200781#if !defined(CONFIG_SPL_BUILD)
782 board_ti_set_ethaddr(2);
783#endif
784
Vignesh R98c5f632018-11-29 10:57:42 +0100785#if CONFIG_IS_ENABLED(DM_USB) && CONFIG_IS_ENABLED(OF_CONTROL)
786 if (device_okay("/ocp/omap_dwc3_1@48880000"))
787 enable_usb_clocks(0);
788 if (device_okay("/ocp/omap_dwc3_2@488c0000"))
789 enable_usb_clocks(1);
790#endif
Felipe Balbi4750eb62014-11-10 14:02:44 -0600791 return 0;
792}
793
Paul Kocialkowskia00b1e52016-02-27 19:18:56 +0100794void set_muxconf_regs(void)
Felipe Balbi4750eb62014-11-10 14:02:44 -0600795{
796 do_set_mux32((*ctrl)->control_padconf_core_base,
Lokesh Vutlac3d39f92015-06-04 16:42:41 +0530797 early_padconf, ARRAY_SIZE(early_padconf));
Caleb Robey0dfcc932020-01-02 08:17:25 -0600798
799#ifdef CONFIG_SUPPORT_EMMC_BOOT
800 do_set_mux32((*ctrl)->control_padconf_core_base,
801 emmc_padconf, ARRAY_SIZE(emmc_padconf));
802#endif
Felipe Balbi4750eb62014-11-10 14:02:44 -0600803}
804
Lokesh Vutlac3d39f92015-06-04 16:42:41 +0530805#ifdef CONFIG_IODELAY_RECALIBRATION
806void recalibrate_iodelay(void)
807{
Steve Kipisz0ac8cea2016-04-08 17:01:29 -0500808 const struct pad_conf_entry *pconf;
Lokesh Vutla3cb4c622017-06-05 14:48:16 +0530809 const struct iodelay_cfg_entry *iod, *delta_iod;
810 int pconf_sz, iod_sz, delta_iod_sz = 0;
Nishanth Menon8e3212e2016-11-25 11:14:22 +0530811 int ret;
Steve Kipisz0ac8cea2016-04-08 17:01:29 -0500812
Lokesh Vutla1e3425c2017-12-29 11:47:55 +0530813 if (board_is_am572x_idk()) {
Steve Kipisz0ac8cea2016-04-08 17:01:29 -0500814 pconf = core_padconf_array_essential_am572x_idk;
815 pconf_sz = ARRAY_SIZE(core_padconf_array_essential_am572x_idk);
816 iod = iodelay_cfg_array_am572x_idk;
817 iod_sz = ARRAY_SIZE(iodelay_cfg_array_am572x_idk);
Lokesh Vutla1e3425c2017-12-29 11:47:55 +0530818 } else if (board_is_am574x_idk()) {
819 pconf = core_padconf_array_essential_am574x_idk;
820 pconf_sz = ARRAY_SIZE(core_padconf_array_essential_am574x_idk);
821 iod = iodelay_cfg_array_am574x_idk;
822 iod_sz = ARRAY_SIZE(iodelay_cfg_array_am574x_idk);
Steve Kipiszc95cddd2016-11-25 11:14:24 +0530823 } else if (board_is_am571x_idk()) {
824 pconf = core_padconf_array_essential_am571x_idk;
825 pconf_sz = ARRAY_SIZE(core_padconf_array_essential_am571x_idk);
826 iod = iodelay_cfg_array_am571x_idk;
827 iod_sz = ARRAY_SIZE(iodelay_cfg_array_am571x_idk);
Caleb Robey940d6372020-01-02 08:17:27 -0600828 } else if (board_is_bbai()) {
829 pconf = core_padconf_array_essential_bbai;
830 pconf_sz = ARRAY_SIZE(core_padconf_array_essential_bbai);
831 iod = iodelay_cfg_array_bbai;
832 iod_sz = ARRAY_SIZE(iodelay_cfg_array_bbai);
Steve Kipisz0ac8cea2016-04-08 17:01:29 -0500833 } else {
834 /* Common for X15/GPEVM */
835 pconf = core_padconf_array_essential_x15;
836 pconf_sz = ARRAY_SIZE(core_padconf_array_essential_x15);
Nishanth Menon8e3212e2016-11-25 11:14:22 +0530837 /* There never was an SR1.0 X15.. So.. */
838 if (omap_revision() == DRA752_ES1_1) {
839 iod = iodelay_cfg_array_x15_sr1_1;
840 iod_sz = ARRAY_SIZE(iodelay_cfg_array_x15_sr1_1);
841 } else {
842 /* Since full production should switch to SR2.0 */
843 iod = iodelay_cfg_array_x15_sr2_0;
844 iod_sz = ARRAY_SIZE(iodelay_cfg_array_x15_sr2_0);
845 }
Steve Kipisz0ac8cea2016-04-08 17:01:29 -0500846 }
847
Nishanth Menon8e3212e2016-11-25 11:14:22 +0530848 /* Setup I/O isolation */
849 ret = __recalibrate_iodelay_start();
850 if (ret)
851 goto err;
852
853 /* Do the muxing here */
854 do_set_mux32((*ctrl)->control_padconf_core_base, pconf, pconf_sz);
855
856 /* Now do the weird minor deltas that should be safe */
857 if (board_is_x15() || board_is_am572x_evm()) {
Lokesh Vutla816178b2017-07-16 19:59:19 +0530858 if (board_is_x15_revb1() || board_is_am572x_evm_reva3() ||
859 board_is_x15_revc()) {
Nishanth Menon8e3212e2016-11-25 11:14:22 +0530860 pconf = core_padconf_array_delta_x15_sr2_0;
861 pconf_sz = ARRAY_SIZE(core_padconf_array_delta_x15_sr2_0);
862 } else {
863 pconf = core_padconf_array_delta_x15_sr1_1;
864 pconf_sz = ARRAY_SIZE(core_padconf_array_delta_x15_sr1_1);
865 }
866 do_set_mux32((*ctrl)->control_padconf_core_base, pconf, pconf_sz);
867 }
868
Roger Quadros26130592017-03-13 15:04:28 +0200869 if (board_is_am571x_idk()) {
870 if (am571x_idk_needs_lcd()) {
871 pconf = core_padconf_array_vout_am571x_idk;
872 pconf_sz = ARRAY_SIZE(core_padconf_array_vout_am571x_idk);
Lokesh Vutla3cb4c622017-06-05 14:48:16 +0530873 delta_iod = iodelay_cfg_array_am571x_idk_4port;
874 delta_iod_sz = ARRAY_SIZE(iodelay_cfg_array_am571x_idk_4port);
875
Roger Quadros26130592017-03-13 15:04:28 +0200876 } else {
877 pconf = core_padconf_array_icss1eth_am571x_idk;
878 pconf_sz = ARRAY_SIZE(core_padconf_array_icss1eth_am571x_idk);
879 }
880 do_set_mux32((*ctrl)->control_padconf_core_base, pconf, pconf_sz);
881 }
882
Nishanth Menon8e3212e2016-11-25 11:14:22 +0530883 /* Setup IOdelay configuration */
884 ret = do_set_iodelay((*ctrl)->iodelay_config_base, iod, iod_sz);
Lokesh Vutla3cb4c622017-06-05 14:48:16 +0530885 if (delta_iod_sz)
886 ret = do_set_iodelay((*ctrl)->iodelay_config_base, delta_iod,
887 delta_iod_sz);
888
Nishanth Menon8e3212e2016-11-25 11:14:22 +0530889err:
890 /* Closeup.. remove isolation */
891 __recalibrate_iodelay_end(ret);
Lokesh Vutlac3d39f92015-06-04 16:42:41 +0530892}
893#endif
894
Masahiro Yamada0a780172017-05-09 20:31:39 +0900895#if defined(CONFIG_MMC)
Felipe Balbi4750eb62014-11-10 14:02:44 -0600896int board_mmc_init(bd_t *bis)
897{
898 omap_mmc_init(0, 0, 0, -1, -1);
899 omap_mmc_init(1, 0, 0, -1, -1);
900 return 0;
901}
Kishon Vijay Abraham I110ed012018-01-30 16:01:52 +0100902
903static const struct mmc_platform_fixups am57x_es1_1_mmc1_fixups = {
904 .hw_rev = "rev11",
905 .unsupported_caps = MMC_CAP(MMC_HS_200) |
906 MMC_CAP(UHS_SDR104),
907 .max_freq = 96000000,
908};
909
910static const struct mmc_platform_fixups am57x_es1_1_mmc23_fixups = {
911 .hw_rev = "rev11",
912 .unsupported_caps = MMC_CAP(MMC_HS_200) |
913 MMC_CAP(UHS_SDR104) |
914 MMC_CAP(UHS_SDR50),
915 .max_freq = 48000000,
916};
917
918const struct mmc_platform_fixups *platform_fixups_mmc(uint32_t addr)
919{
920 switch (omap_revision()) {
921 case DRA752_ES1_0:
922 case DRA752_ES1_1:
923 if (addr == OMAP_HSMMC1_BASE)
924 return &am57x_es1_1_mmc1_fixups;
925 else
926 return &am57x_es1_1_mmc23_fixups;
927 default:
928 return NULL;
929 }
930}
Felipe Balbi4750eb62014-11-10 14:02:44 -0600931#endif
932
933#if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_OS_BOOT)
934int spl_start_uboot(void)
935{
936 /* break into full u-boot on 'c' */
937 if (serial_tstc() && serial_getc() == 'c')
938 return 1;
939
940#ifdef CONFIG_SPL_ENV_SUPPORT
941 env_init();
Simon Glass17539572017-08-03 12:22:07 -0600942 env_load();
Simon Glass22c34c22017-08-03 12:22:13 -0600943 if (env_get_yesno("boot_os") != 1)
Felipe Balbi4750eb62014-11-10 14:02:44 -0600944 return 1;
945#endif
946
947 return 0;
948}
949#endif
950
951#ifdef CONFIG_DRIVER_TI_CPSW
952
953/* Delay value to add to calibrated value */
954#define RGMII0_TXCTL_DLY_VAL ((0x3 << 5) + 0x8)
955#define RGMII0_TXD0_DLY_VAL ((0x3 << 5) + 0x8)
956#define RGMII0_TXD1_DLY_VAL ((0x3 << 5) + 0x2)
957#define RGMII0_TXD2_DLY_VAL ((0x4 << 5) + 0x0)
958#define RGMII0_TXD3_DLY_VAL ((0x4 << 5) + 0x0)
959#define VIN2A_D13_DLY_VAL ((0x3 << 5) + 0x8)
960#define VIN2A_D17_DLY_VAL ((0x3 << 5) + 0x8)
961#define VIN2A_D16_DLY_VAL ((0x3 << 5) + 0x2)
962#define VIN2A_D15_DLY_VAL ((0x4 << 5) + 0x0)
963#define VIN2A_D14_DLY_VAL ((0x4 << 5) + 0x0)
964
965static void cpsw_control(int enabled)
966{
967 /* VTP can be added here */
968}
969
970static struct cpsw_slave_data cpsw_slaves[] = {
971 {
972 .slave_reg_ofs = 0x208,
973 .sliver_reg_ofs = 0xd80,
974 .phy_addr = 1,
975 },
976 {
977 .slave_reg_ofs = 0x308,
978 .sliver_reg_ofs = 0xdc0,
979 .phy_addr = 2,
980 },
981};
982
983static struct cpsw_platform_data cpsw_data = {
984 .mdio_base = CPSW_MDIO_BASE,
985 .cpsw_base = CPSW_BASE,
986 .mdio_div = 0xff,
987 .channels = 8,
988 .cpdma_reg_ofs = 0x800,
989 .slaves = 1,
990 .slave_data = cpsw_slaves,
991 .ale_reg_ofs = 0xd00,
992 .ale_entries = 1024,
993 .host_port_reg_ofs = 0x108,
994 .hw_stats_reg_ofs = 0x900,
995 .bd_ram_ofs = 0x2000,
996 .mac_control = (1 << 5),
997 .control = cpsw_control,
998 .host_port_num = 0,
999 .version = CPSW_CTRL_VERSION_2,
1000};
1001
Roger Quadros64217a22016-03-18 13:18:12 +02001002static u64 mac_to_u64(u8 mac[6])
1003{
1004 int i;
1005 u64 addr = 0;
1006
1007 for (i = 0; i < 6; i++) {
1008 addr <<= 8;
1009 addr |= mac[i];
1010 }
1011
1012 return addr;
1013}
1014
1015static void u64_to_mac(u64 addr, u8 mac[6])
1016{
1017 mac[5] = addr;
1018 mac[4] = addr >> 8;
1019 mac[3] = addr >> 16;
1020 mac[2] = addr >> 24;
1021 mac[1] = addr >> 32;
1022 mac[0] = addr >> 40;
1023}
1024
Felipe Balbi4750eb62014-11-10 14:02:44 -06001025int board_eth_init(bd_t *bis)
1026{
1027 int ret;
1028 uint8_t mac_addr[6];
1029 uint32_t mac_hi, mac_lo;
1030 uint32_t ctrl_val;
Roger Quadros64217a22016-03-18 13:18:12 +02001031 int i;
1032 u64 mac1, mac2;
1033 u8 mac_addr1[6], mac_addr2[6];
1034 int num_macs;
Felipe Balbi4750eb62014-11-10 14:02:44 -06001035
1036 /* try reading mac address from efuse */
1037 mac_lo = readl((*ctrl)->control_core_mac_id_0_lo);
1038 mac_hi = readl((*ctrl)->control_core_mac_id_0_hi);
1039 mac_addr[0] = (mac_hi & 0xFF0000) >> 16;
1040 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
1041 mac_addr[2] = mac_hi & 0xFF;
1042 mac_addr[3] = (mac_lo & 0xFF0000) >> 16;
1043 mac_addr[4] = (mac_lo & 0xFF00) >> 8;
1044 mac_addr[5] = mac_lo & 0xFF;
1045
Simon Glass64b723f2017-08-03 12:22:12 -06001046 if (!env_get("ethaddr")) {
Felipe Balbi4750eb62014-11-10 14:02:44 -06001047 printf("<ethaddr> not set. Validating first E-fuse MAC\n");
1048
Joe Hershberger8ecdbed2015-04-08 01:41:04 -05001049 if (is_valid_ethaddr(mac_addr))
Simon Glass8551d552017-08-03 12:22:11 -06001050 eth_env_set_enetaddr("ethaddr", mac_addr);
Felipe Balbi4750eb62014-11-10 14:02:44 -06001051 }
1052
1053 mac_lo = readl((*ctrl)->control_core_mac_id_1_lo);
1054 mac_hi = readl((*ctrl)->control_core_mac_id_1_hi);
1055 mac_addr[0] = (mac_hi & 0xFF0000) >> 16;
1056 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
1057 mac_addr[2] = mac_hi & 0xFF;
1058 mac_addr[3] = (mac_lo & 0xFF0000) >> 16;
1059 mac_addr[4] = (mac_lo & 0xFF00) >> 8;
1060 mac_addr[5] = mac_lo & 0xFF;
1061
Simon Glass64b723f2017-08-03 12:22:12 -06001062 if (!env_get("eth1addr")) {
Joe Hershberger8ecdbed2015-04-08 01:41:04 -05001063 if (is_valid_ethaddr(mac_addr))
Simon Glass8551d552017-08-03 12:22:11 -06001064 eth_env_set_enetaddr("eth1addr", mac_addr);
Felipe Balbi4750eb62014-11-10 14:02:44 -06001065 }
1066
1067 ctrl_val = readl((*ctrl)->control_core_control_io1) & (~0x33);
1068 ctrl_val |= 0x22;
1069 writel(ctrl_val, (*ctrl)->control_core_control_io1);
1070
Steve Kipiszc95cddd2016-11-25 11:14:24 +05301071 /* The phy address for the AM57xx IDK are different than x15 */
Lokesh Vutla6e9635c2017-12-29 11:47:53 +05301072 if (board_is_am572x_idk() || board_is_am571x_idk() ||
1073 board_is_am574x_idk()) {
Steve Kipisz0ac8cea2016-04-08 17:01:29 -05001074 cpsw_data.slave_data[0].phy_addr = 0;
1075 cpsw_data.slave_data[1].phy_addr = 1;
1076 }
1077
Felipe Balbi4750eb62014-11-10 14:02:44 -06001078 ret = cpsw_register(&cpsw_data);
1079 if (ret < 0)
1080 printf("Error %d registering CPSW switch\n", ret);
1081
Roger Quadros64217a22016-03-18 13:18:12 +02001082 /*
1083 * Export any Ethernet MAC addresses from EEPROM.
1084 * On AM57xx the 2 MAC addresses define the address range
1085 */
1086 board_ti_get_eth_mac_addr(0, mac_addr1);
1087 board_ti_get_eth_mac_addr(1, mac_addr2);
1088
1089 if (is_valid_ethaddr(mac_addr1) && is_valid_ethaddr(mac_addr2)) {
1090 mac1 = mac_to_u64(mac_addr1);
1091 mac2 = mac_to_u64(mac_addr2);
1092
1093 /* must contain an address range */
1094 num_macs = mac2 - mac1 + 1;
1095 /* <= 50 to protect against user programming error */
1096 if (num_macs > 0 && num_macs <= 50) {
1097 for (i = 0; i < num_macs; i++) {
1098 u64_to_mac(mac1 + i, mac_addr);
1099 if (is_valid_ethaddr(mac_addr)) {
Simon Glass8551d552017-08-03 12:22:11 -06001100 eth_env_set_enetaddr_by_index("eth",
1101 i + 2,
1102 mac_addr);
Roger Quadros64217a22016-03-18 13:18:12 +02001103 }
1104 }
1105 }
1106 }
1107
Felipe Balbi4750eb62014-11-10 14:02:44 -06001108 return ret;
1109}
1110#endif
Lokesh Vutla9f150672015-06-16 20:36:05 +05301111
1112#ifdef CONFIG_BOARD_EARLY_INIT_F
1113/* VTT regulator enable */
1114static inline void vtt_regulator_enable(void)
1115{
1116 if (omap_hw_init_context() == OMAP_INIT_CONTEXT_UBOOT_AFTER_SPL)
1117 return;
1118
1119 gpio_request(GPIO_DDR_VTT_EN, "ddr_vtt_en");
1120 gpio_direction_output(GPIO_DDR_VTT_EN, 1);
1121}
1122
1123int board_early_init_f(void)
1124{
1125 vtt_regulator_enable();
1126 return 0;
1127}
1128#endif
Daniel Allred7ceffb22016-05-19 19:10:54 -05001129
1130#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
1131int ft_board_setup(void *blob, bd_t *bd)
1132{
1133 ft_cpu_setup(blob, bd);
1134
1135 return 0;
1136}
1137#endif
Lokesh Vutla00bf8b22016-06-10 09:35:43 +05301138
1139#ifdef CONFIG_SPL_LOAD_FIT
1140int board_fit_config_name_match(const char *name)
1141{
Lokesh Vutla638e1c02016-11-25 11:14:20 +05301142 if (board_is_x15()) {
1143 if (board_is_x15_revb1()) {
1144 if (!strcmp(name, "am57xx-beagle-x15-revb1"))
1145 return 0;
Lokesh Vutlaf35589c2017-08-23 11:39:06 +05301146 } else if (board_is_x15_revc()) {
1147 if (!strcmp(name, "am57xx-beagle-x15-revc"))
1148 return 0;
Lokesh Vutla638e1c02016-11-25 11:14:20 +05301149 } else if (!strcmp(name, "am57xx-beagle-x15")) {
1150 return 0;
1151 }
1152 } else if (board_is_am572x_evm() &&
1153 !strcmp(name, "am57xx-beagle-x15")) {
Lokesh Vutla00bf8b22016-06-10 09:35:43 +05301154 return 0;
Lokesh Vutla638e1c02016-11-25 11:14:20 +05301155 } else if (board_is_am572x_idk() && !strcmp(name, "am572x-idk")) {
Schuyler Patton99519852016-06-10 09:35:45 +05301156 return 0;
Lokesh Vutla58a3c1b2017-12-29 11:47:57 +05301157 } else if (board_is_am574x_idk() && !strcmp(name, "am574x-idk")) {
1158 return 0;
Schuyler Pattonc665e272016-11-25 11:14:25 +05301159 } else if (board_is_am571x_idk() && !strcmp(name, "am571x-idk")) {
1160 return 0;
Caleb Robey940d6372020-01-02 08:17:27 -06001161 } else if (board_is_bbai() && !strcmp(name, "am5729-beagleboneai")) {
1162 return 0;
Lokesh Vutla638e1c02016-11-25 11:14:20 +05301163 }
1164
1165 return -1;
Lokesh Vutla00bf8b22016-06-10 09:35:43 +05301166}
1167#endif
Andreas Dannenberg5cf344b2016-06-27 09:19:22 -05001168
Andrew F. Davisd3555832019-02-11 08:00:08 -06001169#if CONFIG_IS_ENABLED(FASTBOOT) && !CONFIG_IS_ENABLED(ENV_IS_NOWHERE)
1170int fastboot_set_reboot_flag(void)
1171{
1172 printf("Setting reboot to fastboot flag ...\n");
1173 env_set("dofastboot", "1");
1174 env_save();
1175 return 0;
1176}
1177#endif
1178
Caleb Robey0dfcc932020-01-02 08:17:25 -06001179#ifdef CONFIG_SUPPORT_EMMC_BOOT
1180static int board_bootmode_has_emmc(void)
1181{
1182 /* Check that boot mode is same as BBAI */
1183 if (gd->arch.omap_boot_mode != 2)
1184 return -EIO;
1185
1186 return 0;
1187}
1188#endif
1189
Andreas Dannenberg5cf344b2016-06-27 09:19:22 -05001190#ifdef CONFIG_TI_SECURE_DEVICE
1191void board_fit_image_post_process(void **p_image, size_t *p_size)
1192{
1193 secure_boot_verify_image(p_image, p_size);
1194}
Andrew F. Davis7d250622016-11-29 16:33:26 -06001195
1196void board_tee_image_process(ulong tee_image, size_t tee_size)
1197{
1198 secure_tee_install((u32)tee_image);
1199}
1200
1201U_BOOT_FIT_LOADABLE_HANDLER(IH_TYPE_TEE, board_tee_image_process);
Andreas Dannenberg5cf344b2016-06-27 09:19:22 -05001202#endif