blob: 73063faee69037c66de147c4f3b57ad7bfa04f35 [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>
Roman Kovalivskyi1bb13422020-07-28 23:35:32 +030012#include <fastboot.h>
Simon Glass3bbe70c2019-12-28 10:44:54 -070013#include <fdt_support.h>
Simon Glass2dc9c342020-05-10 11:40:01 -060014#include <image.h>
Simon Glassa7b51302019-11-14 12:57:46 -070015#include <init.h>
Simon Glass9bc15642020-02-03 07:36:16 -070016#include <malloc.h>
Simon Glass274e0b02020-05-10 11:39:56 -060017#include <net.h>
Felipe Balbi4750eb62014-11-10 14:02:44 -060018#include <palmas.h>
19#include <sata.h>
Simon Glass36736182019-11-14 12:57:24 -070020#include <serial.h>
Felipe Balbi4750eb62014-11-10 14:02:44 -060021#include <usb.h>
Caleb Robey0dfcc932020-01-02 08:17:25 -060022#include <errno.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060023#include <asm/global_data.h>
Felipe Balbi4750eb62014-11-10 14:02:44 -060024#include <asm/omap_common.h>
Andreas Dannenberg5cf344b2016-06-27 09:19:22 -050025#include <asm/omap_sec_common.h>
Felipe Balbi4750eb62014-11-10 14:02:44 -060026#include <asm/emif.h>
Lokesh Vutla9f150672015-06-16 20:36:05 +053027#include <asm/gpio.h>
28#include <asm/arch/gpio.h>
Felipe Balbi4750eb62014-11-10 14:02:44 -060029#include <asm/arch/clock.h>
Lokesh Vutlac3d39f92015-06-04 16:42:41 +053030#include <asm/arch/dra7xx_iodelay.h>
Felipe Balbi4750eb62014-11-10 14:02:44 -060031#include <asm/arch/sys_proto.h>
32#include <asm/arch/mmc_host_def.h>
33#include <asm/arch/sata.h>
34#include <asm/arch/gpio.h>
Kishon Vijay Abraham I5f19b2d2015-08-19 14:13:19 +053035#include <asm/arch/omap.h>
Kishon Vijay Abraham I5f19b2d2015-08-19 14:13:19 +053036#include <usb.h>
37#include <linux/usb/gadget.h>
38#include <dwc3-uboot.h>
39#include <dwc3-omap-uboot.h>
40#include <ti-usb-phy-uboot.h>
Kishon Vijay Abraham I110ed012018-01-30 16:01:52 +010041#include <mmc.h>
Tero Kristodfbc6b82019-09-27 19:14:27 +030042#include <dm/uclass.h>
Roger Quadros8835eee2020-02-10 11:59:24 +020043#include <hang.h>
Felipe Balbi4750eb62014-11-10 14:02:44 -060044
Kipisz, Steven161f1382016-02-24 12:30:58 -060045#include "../common/board_detect.h"
Felipe Balbi4750eb62014-11-10 14:02:44 -060046#include "mux_data.h"
47
Caleb Robey0dfcc932020-01-02 08:17:25 -060048#ifdef CONFIG_SUPPORT_EMMC_BOOT
49static int board_bootmode_has_emmc(void);
50#endif
51
Kipisz, Steven161f1382016-02-24 12:30:58 -060052#define board_is_x15() board_ti_is("BBRDX15_")
Lokesh Vutla638e1c02016-11-25 11:14:20 +053053#define board_is_x15_revb1() (board_ti_is("BBRDX15_") && \
Lokesh Vutlaab4f71e2017-07-16 19:59:18 +053054 !strncmp("B.10", board_ti_get_rev(), 3))
Lokesh Vutla816178b2017-07-16 19:59:19 +053055#define board_is_x15_revc() (board_ti_is("BBRDX15_") && \
56 !strncmp("C.00", board_ti_get_rev(), 3))
Kipisz, Steven161f1382016-02-24 12:30:58 -060057#define board_is_am572x_evm() board_ti_is("AM572PM_")
Nishanth Menona2aea1c2016-11-25 11:14:19 +053058#define board_is_am572x_evm_reva3() \
59 (board_ti_is("AM572PM_") && \
Lokesh Vutlaab4f71e2017-07-16 19:59:18 +053060 !strncmp("A.30", board_ti_get_rev(), 3))
Lokesh Vutla374aea02017-12-29 11:47:52 +053061#define board_is_am574x_idk() board_ti_is("AM574IDK")
Steve Kipisz0ac8cea2016-04-08 17:01:29 -050062#define board_is_am572x_idk() board_ti_is("AM572IDK")
Steve Kipiszc95cddd2016-11-25 11:14:24 +053063#define board_is_am571x_idk() board_ti_is("AM571IDK")
Caleb Robey940d6372020-01-02 08:17:27 -060064#define board_is_bbai() board_ti_is("BBONE-AI")
Kipisz, Steven161f1382016-02-24 12:30:58 -060065
Luca Ceresoli93f6bc22020-05-21 15:06:25 +020066#define board_is_ti_idk() board_is_am574x_idk() || \
67 board_is_am572x_idk() || \
68 board_is_am571x_idk()
69
Felipe Balbi4750eb62014-11-10 14:02:44 -060070#ifdef CONFIG_DRIVER_TI_CPSW
71#include <cpsw.h>
72#endif
73
74DECLARE_GLOBAL_DATA_PTR;
75
Roger Quadros26130592017-03-13 15:04:28 +020076#define GPIO_ETH_LCD GPIO_TO_PIN(2, 22)
Luca Ceresoliacea16b2020-05-21 15:06:24 +020077#define GPIO_DDR_VTT_EN GPIO_TO_PIN(7, 11)
Lokesh Vutla9f150672015-06-16 20:36:05 +053078
Nishanth Menond0f399c2017-03-13 15:04:30 +020079/* Touch screen controller to identify the LCD */
80#define OSD_TS_FT_BUS_ADDRESS 0
81#define OSD_TS_FT_CHIP_ADDRESS 0x38
82#define OSD_TS_FT_REG_ID 0xA3
83/*
84 * Touchscreen IDs for various OSD panels
85 * Ref: http://www.osddisplays.com/TI/OSD101T2587-53TS_A.1.pdf
86 */
87/* Used on newer osd101t2587 Panels */
88#define OSD_TS_FT_ID_5x46 0x54
89/* Used on older osd101t2045 Panels */
90#define OSD_TS_FT_ID_5606 0x08
91
Kipisz, Steven161f1382016-02-24 12:30:58 -060092#define SYSINFO_BOARD_NAME_MAX_LEN 45
93
Keerthyee85ebe2016-11-30 15:02:53 +053094#define TPS65903X_PRIMARY_SECONDARY_PAD2 0xFB
95#define TPS65903X_PAD2_POWERHOLD_MASK 0x20
96
Felipe Balbi4750eb62014-11-10 14:02:44 -060097const struct omap_sysinfo sysinfo = {
Kipisz, Steven161f1382016-02-24 12:30:58 -060098 "Board: UNKNOWN(BeagleBoard X15?) REV UNKNOWN\n"
Felipe Balbi4750eb62014-11-10 14:02:44 -060099};
100
101static const struct dmm_lisa_map_regs beagle_x15_lisa_regs = {
102 .dmm_lisa_map_3 = 0x80740300,
103 .is_ma_present = 0x1
104};
105
Steve Kipiszc95cddd2016-11-25 11:14:24 +0530106static const struct dmm_lisa_map_regs am571x_idk_lisa_regs = {
107 .dmm_lisa_map_3 = 0x80640100,
108 .is_ma_present = 0x1
109};
110
Lokesh Vutlacbd70db2017-12-29 11:47:54 +0530111static const struct dmm_lisa_map_regs am574x_idk_lisa_regs = {
112 .dmm_lisa_map_2 = 0xc0600200,
113 .dmm_lisa_map_3 = 0x80600100,
114 .is_ma_present = 0x1
115};
116
Caleb Robey940d6372020-01-02 08:17:27 -0600117static const struct dmm_lisa_map_regs bbai_lisa_regs = {
118 .dmm_lisa_map_3 = 0x80640100,
119 .is_ma_present = 0x1
120};
121
Felipe Balbi4750eb62014-11-10 14:02:44 -0600122void emif_get_dmm_regs(const struct dmm_lisa_map_regs **dmm_lisa_regs)
123{
Steve Kipiszc95cddd2016-11-25 11:14:24 +0530124 if (board_is_am571x_idk())
125 *dmm_lisa_regs = &am571x_idk_lisa_regs;
Lokesh Vutlacbd70db2017-12-29 11:47:54 +0530126 else if (board_is_am574x_idk())
127 *dmm_lisa_regs = &am574x_idk_lisa_regs;
Caleb Robey940d6372020-01-02 08:17:27 -0600128 else if (board_is_bbai())
129 *dmm_lisa_regs = &bbai_lisa_regs;
Steve Kipiszc95cddd2016-11-25 11:14:24 +0530130 else
131 *dmm_lisa_regs = &beagle_x15_lisa_regs;
Felipe Balbi4750eb62014-11-10 14:02:44 -0600132}
133
134static const struct emif_regs beagle_x15_emif1_ddr3_532mhz_emif_regs = {
Keerthy66dd8062016-05-24 11:45:07 +0530135 .sdram_config_init = 0x61851b32,
136 .sdram_config = 0x61851b32,
137 .sdram_config2 = 0x08000000,
138 .ref_ctrl = 0x000040F1,
139 .ref_ctrl_final = 0x00001035,
140 .sdram_tim1 = 0xcccf36ab,
141 .sdram_tim2 = 0x308f7fda,
142 .sdram_tim3 = 0x409f88a8,
143 .read_idle_ctrl = 0x00050000,
144 .zq_config = 0x5007190b,
145 .temp_alert_config = 0x00000000,
146 .emif_ddr_phy_ctlr_1_init = 0x0024400b,
147 .emif_ddr_phy_ctlr_1 = 0x0e24400b,
148 .emif_ddr_ext_phy_ctrl_1 = 0x10040100,
149 .emif_ddr_ext_phy_ctrl_2 = 0x00910091,
150 .emif_ddr_ext_phy_ctrl_3 = 0x00950095,
151 .emif_ddr_ext_phy_ctrl_4 = 0x009b009b,
152 .emif_ddr_ext_phy_ctrl_5 = 0x009e009e,
153 .emif_rd_wr_lvl_rmp_win = 0x00000000,
154 .emif_rd_wr_lvl_rmp_ctl = 0x80000000,
155 .emif_rd_wr_lvl_ctl = 0x00000000,
156 .emif_rd_wr_exec_thresh = 0x00000305
Felipe Balbi4750eb62014-11-10 14:02:44 -0600157};
158
Lokesh Vutla979d2c32015-06-03 14:43:21 +0530159/* Ext phy ctrl regs 1-35 */
Felipe Balbi4750eb62014-11-10 14:02:44 -0600160static const u32 beagle_x15_emif1_ddr3_ext_phy_ctrl_const_regs[] = {
Lokesh Vutla979d2c32015-06-03 14:43:21 +0530161 0x10040100,
Lokesh Vutla306b5972016-03-08 09:11:35 +0530162 0x00910091,
163 0x00950095,
164 0x009B009B,
165 0x009E009E,
166 0x00980098,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600167 0x00340034,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600168 0x00350035,
Lokesh Vutla306b5972016-03-08 09:11:35 +0530169 0x00340034,
170 0x00310031,
171 0x00340034,
172 0x007F007F,
173 0x007F007F,
174 0x007F007F,
175 0x007F007F,
176 0x007F007F,
177 0x00480048,
178 0x004A004A,
179 0x00520052,
180 0x00550055,
181 0x00500050,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600182 0x00000000,
183 0x00600020,
Lokesh Vutla979d2c32015-06-03 14:43:21 +0530184 0x40011080,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600185 0x08102040,
Lokesh Vutla306b5972016-03-08 09:11:35 +0530186 0x0,
187 0x0,
188 0x0,
189 0x0,
Lokesh Vutla51a0f1f2015-06-03 14:43:22 +0530190 0x0,
191 0x0,
192 0x0,
193 0x0,
Lokesh Vutla306b5972016-03-08 09:11:35 +0530194 0x0,
Lokesh Vutla51a0f1f2015-06-03 14:43:22 +0530195 0x0
Felipe Balbi4750eb62014-11-10 14:02:44 -0600196};
197
198static const struct emif_regs beagle_x15_emif2_ddr3_532mhz_emif_regs = {
Keerthy66dd8062016-05-24 11:45:07 +0530199 .sdram_config_init = 0x61851b32,
200 .sdram_config = 0x61851b32,
201 .sdram_config2 = 0x08000000,
202 .ref_ctrl = 0x000040F1,
203 .ref_ctrl_final = 0x00001035,
204 .sdram_tim1 = 0xcccf36b3,
205 .sdram_tim2 = 0x308f7fda,
206 .sdram_tim3 = 0x407f88a8,
207 .read_idle_ctrl = 0x00050000,
208 .zq_config = 0x5007190b,
209 .temp_alert_config = 0x00000000,
210 .emif_ddr_phy_ctlr_1_init = 0x0024400b,
211 .emif_ddr_phy_ctlr_1 = 0x0e24400b,
212 .emif_ddr_ext_phy_ctrl_1 = 0x10040100,
213 .emif_ddr_ext_phy_ctrl_2 = 0x00910091,
214 .emif_ddr_ext_phy_ctrl_3 = 0x00950095,
215 .emif_ddr_ext_phy_ctrl_4 = 0x009b009b,
216 .emif_ddr_ext_phy_ctrl_5 = 0x009e009e,
217 .emif_rd_wr_lvl_rmp_win = 0x00000000,
218 .emif_rd_wr_lvl_rmp_ctl = 0x80000000,
219 .emif_rd_wr_lvl_ctl = 0x00000000,
220 .emif_rd_wr_exec_thresh = 0x00000305
Felipe Balbi4750eb62014-11-10 14:02:44 -0600221};
222
223static const u32 beagle_x15_emif2_ddr3_ext_phy_ctrl_const_regs[] = {
Lokesh Vutla979d2c32015-06-03 14:43:21 +0530224 0x10040100,
Lokesh Vutla306b5972016-03-08 09:11:35 +0530225 0x00910091,
226 0x00950095,
227 0x009B009B,
228 0x009E009E,
229 0x00980098,
230 0x00340034,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600231 0x00350035,
Lokesh Vutla306b5972016-03-08 09:11:35 +0530232 0x00340034,
233 0x00310031,
234 0x00340034,
235 0x007F007F,
236 0x007F007F,
237 0x007F007F,
238 0x007F007F,
239 0x007F007F,
240 0x00480048,
241 0x004A004A,
242 0x00520052,
243 0x00550055,
244 0x00500050,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600245 0x00000000,
246 0x00600020,
Lokesh Vutla979d2c32015-06-03 14:43:21 +0530247 0x40011080,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600248 0x08102040,
Lokesh Vutla306b5972016-03-08 09:11:35 +0530249 0x0,
250 0x0,
251 0x0,
252 0x0,
253 0x0,
Lokesh Vutla51a0f1f2015-06-03 14:43:22 +0530254 0x0,
255 0x0,
256 0x0,
257 0x0,
258 0x0
Felipe Balbi4750eb62014-11-10 14:02:44 -0600259};
260
Steve Kipisz81c46742017-08-22 13:52:58 +0530261static const struct emif_regs am571x_emif1_ddr3_666mhz_emif_regs = {
262 .sdram_config_init = 0x61863332,
263 .sdram_config = 0x61863332,
264 .sdram_config2 = 0x08000000,
265 .ref_ctrl = 0x0000514d,
266 .ref_ctrl_final = 0x0000144a,
267 .sdram_tim1 = 0xd333887c,
Lokesh Vutlacbd70db2017-12-29 11:47:54 +0530268 .sdram_tim2 = 0x30b37fe3,
269 .sdram_tim3 = 0x409f8ad8,
Steve Kipisz81c46742017-08-22 13:52:58 +0530270 .read_idle_ctrl = 0x00050000,
271 .zq_config = 0x5007190b,
272 .temp_alert_config = 0x00000000,
273 .emif_ddr_phy_ctlr_1_init = 0x0024400f,
274 .emif_ddr_phy_ctlr_1 = 0x0e24400f,
275 .emif_ddr_ext_phy_ctrl_1 = 0x10040100,
276 .emif_ddr_ext_phy_ctrl_2 = 0x00910091,
277 .emif_ddr_ext_phy_ctrl_3 = 0x00950095,
278 .emif_ddr_ext_phy_ctrl_4 = 0x009b009b,
279 .emif_ddr_ext_phy_ctrl_5 = 0x009e009e,
280 .emif_rd_wr_lvl_rmp_win = 0x00000000,
281 .emif_rd_wr_lvl_rmp_ctl = 0x80000000,
282 .emif_rd_wr_lvl_ctl = 0x00000000,
283 .emif_rd_wr_exec_thresh = 0x00000305
284};
285
Lokesh Vutlacbd70db2017-12-29 11:47:54 +0530286static const struct emif_regs am574x_emif1_ddr3_666mhz_emif_ecc_regs = {
287 .sdram_config_init = 0x61863332,
288 .sdram_config = 0x61863332,
289 .sdram_config2 = 0x08000000,
290 .ref_ctrl = 0x0000514d,
291 .ref_ctrl_final = 0x0000144a,
292 .sdram_tim1 = 0xd333887c,
293 .sdram_tim2 = 0x30b37fe3,
294 .sdram_tim3 = 0x409f8ad8,
295 .read_idle_ctrl = 0x00050000,
296 .zq_config = 0x5007190b,
297 .temp_alert_config = 0x00000000,
298 .emif_ddr_phy_ctlr_1_init = 0x0024400f,
299 .emif_ddr_phy_ctlr_1 = 0x0e24400f,
300 .emif_ddr_ext_phy_ctrl_1 = 0x10040100,
301 .emif_ddr_ext_phy_ctrl_2 = 0x00910091,
302 .emif_ddr_ext_phy_ctrl_3 = 0x00950095,
303 .emif_ddr_ext_phy_ctrl_4 = 0x009b009b,
304 .emif_ddr_ext_phy_ctrl_5 = 0x009e009e,
305 .emif_rd_wr_lvl_rmp_win = 0x00000000,
306 .emif_rd_wr_lvl_rmp_ctl = 0x80000000,
307 .emif_rd_wr_lvl_ctl = 0x00000000,
308 .emif_rd_wr_exec_thresh = 0x00000305,
309 .emif_ecc_ctrl_reg = 0xD0000001,
310 .emif_ecc_address_range_1 = 0x3FFF0000,
311 .emif_ecc_address_range_2 = 0x00000000
312};
313
Felipe Balbi4750eb62014-11-10 14:02:44 -0600314void emif_get_reg_dump(u32 emif_nr, const struct emif_regs **regs)
315{
316 switch (emif_nr) {
317 case 1:
Steve Kipisz81c46742017-08-22 13:52:58 +0530318 if (board_is_am571x_idk())
319 *regs = &am571x_emif1_ddr3_666mhz_emif_regs;
Lokesh Vutlacbd70db2017-12-29 11:47:54 +0530320 else if (board_is_am574x_idk())
321 *regs = &am574x_emif1_ddr3_666mhz_emif_ecc_regs;
Steve Kipisz81c46742017-08-22 13:52:58 +0530322 else
323 *regs = &beagle_x15_emif1_ddr3_532mhz_emif_regs;
Felipe Balbi4750eb62014-11-10 14:02:44 -0600324 break;
325 case 2:
Lokesh Vutlacbd70db2017-12-29 11:47:54 +0530326 if (board_is_am574x_idk())
327 *regs = &am571x_emif1_ddr3_666mhz_emif_regs;
328 else
329 *regs = &beagle_x15_emif2_ddr3_532mhz_emif_regs;
Felipe Balbi4750eb62014-11-10 14:02:44 -0600330 break;
331 }
332}
333
334void emif_get_ext_phy_ctrl_const_regs(u32 emif_nr, const u32 **regs, u32 *size)
335{
336 switch (emif_nr) {
337 case 1:
338 *regs = beagle_x15_emif1_ddr3_ext_phy_ctrl_const_regs;
339 *size = ARRAY_SIZE(beagle_x15_emif1_ddr3_ext_phy_ctrl_const_regs);
340 break;
341 case 2:
342 *regs = beagle_x15_emif2_ddr3_ext_phy_ctrl_const_regs;
343 *size = ARRAY_SIZE(beagle_x15_emif2_ddr3_ext_phy_ctrl_const_regs);
344 break;
345 }
346}
347
348struct vcores_data beagle_x15_volts = {
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530349 .mpu.value[OPP_NOM] = VDD_MPU_DRA7_NOM,
350 .mpu.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_MPU_NOM,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600351 .mpu.efuse.reg_bits = DRA752_EFUSE_REGBITS,
352 .mpu.addr = TPS659038_REG_ADDR_SMPS12,
353 .mpu.pmic = &tps659038,
Keerthy66dd8062016-05-24 11:45:07 +0530354 .mpu.abb_tx_done_mask = OMAP_ABB_MPU_TXDONE_MASK,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600355
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530356 .eve.value[OPP_NOM] = VDD_EVE_DRA7_NOM,
357 .eve.value[OPP_OD] = VDD_EVE_DRA7_OD,
358 .eve.value[OPP_HIGH] = VDD_EVE_DRA7_HIGH,
359 .eve.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_DSPEVE_NOM,
360 .eve.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_DSPEVE_OD,
361 .eve.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_DSPEVE_HIGH,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600362 .eve.efuse.reg_bits = DRA752_EFUSE_REGBITS,
363 .eve.addr = TPS659038_REG_ADDR_SMPS45,
364 .eve.pmic = &tps659038,
Nishanth Menon59b92af2016-04-21 14:34:25 -0500365 .eve.abb_tx_done_mask = OMAP_ABB_EVE_TXDONE_MASK,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600366
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530367 .gpu.value[OPP_NOM] = VDD_GPU_DRA7_NOM,
368 .gpu.value[OPP_OD] = VDD_GPU_DRA7_OD,
369 .gpu.value[OPP_HIGH] = VDD_GPU_DRA7_HIGH,
370 .gpu.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_GPU_NOM,
371 .gpu.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_GPU_OD,
372 .gpu.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_GPU_HIGH,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600373 .gpu.efuse.reg_bits = DRA752_EFUSE_REGBITS,
374 .gpu.addr = TPS659038_REG_ADDR_SMPS45,
375 .gpu.pmic = &tps659038,
Nishanth Menon59b92af2016-04-21 14:34:25 -0500376 .gpu.abb_tx_done_mask = OMAP_ABB_GPU_TXDONE_MASK,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600377
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530378 .core.value[OPP_NOM] = VDD_CORE_DRA7_NOM,
379 .core.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_CORE_NOM,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600380 .core.efuse.reg_bits = DRA752_EFUSE_REGBITS,
381 .core.addr = TPS659038_REG_ADDR_SMPS6,
382 .core.pmic = &tps659038,
383
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530384 .iva.value[OPP_NOM] = VDD_IVA_DRA7_NOM,
385 .iva.value[OPP_OD] = VDD_IVA_DRA7_OD,
386 .iva.value[OPP_HIGH] = VDD_IVA_DRA7_HIGH,
387 .iva.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_IVA_NOM,
388 .iva.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_IVA_OD,
389 .iva.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_IVA_HIGH,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600390 .iva.efuse.reg_bits = DRA752_EFUSE_REGBITS,
391 .iva.addr = TPS659038_REG_ADDR_SMPS45,
392 .iva.pmic = &tps659038,
Nishanth Menon59b92af2016-04-21 14:34:25 -0500393 .iva.abb_tx_done_mask = OMAP_ABB_IVA_TXDONE_MASK,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600394};
395
Keerthy152e9932016-05-24 11:45:06 +0530396struct vcores_data am572x_idk_volts = {
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530397 .mpu.value[OPP_NOM] = VDD_MPU_DRA7_NOM,
398 .mpu.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_MPU_NOM,
Keerthy152e9932016-05-24 11:45:06 +0530399 .mpu.efuse.reg_bits = DRA752_EFUSE_REGBITS,
400 .mpu.addr = TPS659038_REG_ADDR_SMPS12,
401 .mpu.pmic = &tps659038,
402 .mpu.abb_tx_done_mask = OMAP_ABB_MPU_TXDONE_MASK,
403
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530404 .eve.value[OPP_NOM] = VDD_EVE_DRA7_NOM,
405 .eve.value[OPP_OD] = VDD_EVE_DRA7_OD,
406 .eve.value[OPP_HIGH] = VDD_EVE_DRA7_HIGH,
407 .eve.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_DSPEVE_NOM,
408 .eve.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_DSPEVE_OD,
409 .eve.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_DSPEVE_HIGH,
Keerthy152e9932016-05-24 11:45:06 +0530410 .eve.efuse.reg_bits = DRA752_EFUSE_REGBITS,
411 .eve.addr = TPS659038_REG_ADDR_SMPS45,
412 .eve.pmic = &tps659038,
413 .eve.abb_tx_done_mask = OMAP_ABB_EVE_TXDONE_MASK,
414
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530415 .gpu.value[OPP_NOM] = VDD_GPU_DRA7_NOM,
416 .gpu.value[OPP_OD] = VDD_GPU_DRA7_OD,
417 .gpu.value[OPP_HIGH] = VDD_GPU_DRA7_HIGH,
418 .gpu.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_GPU_NOM,
419 .gpu.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_GPU_OD,
420 .gpu.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_GPU_HIGH,
Keerthy152e9932016-05-24 11:45:06 +0530421 .gpu.efuse.reg_bits = DRA752_EFUSE_REGBITS,
422 .gpu.addr = TPS659038_REG_ADDR_SMPS6,
423 .gpu.pmic = &tps659038,
424 .gpu.abb_tx_done_mask = OMAP_ABB_GPU_TXDONE_MASK,
425
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530426 .core.value[OPP_NOM] = VDD_CORE_DRA7_NOM,
427 .core.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_CORE_NOM,
Keerthy152e9932016-05-24 11:45:06 +0530428 .core.efuse.reg_bits = DRA752_EFUSE_REGBITS,
429 .core.addr = TPS659038_REG_ADDR_SMPS7,
430 .core.pmic = &tps659038,
431
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530432 .iva.value[OPP_NOM] = VDD_IVA_DRA7_NOM,
433 .iva.value[OPP_OD] = VDD_IVA_DRA7_OD,
434 .iva.value[OPP_HIGH] = VDD_IVA_DRA7_HIGH,
435 .iva.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_IVA_NOM,
436 .iva.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_IVA_OD,
437 .iva.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_IVA_HIGH,
Keerthy152e9932016-05-24 11:45:06 +0530438 .iva.efuse.reg_bits = DRA752_EFUSE_REGBITS,
439 .iva.addr = TPS659038_REG_ADDR_SMPS8,
440 .iva.pmic = &tps659038,
441 .iva.abb_tx_done_mask = OMAP_ABB_IVA_TXDONE_MASK,
442};
443
Keerthy9cc2aee2017-05-25 15:37:34 +0530444struct vcores_data am571x_idk_volts = {
445 .mpu.value[OPP_NOM] = VDD_MPU_DRA7_NOM,
446 .mpu.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_MPU_NOM,
447 .mpu.efuse.reg_bits = DRA752_EFUSE_REGBITS,
448 .mpu.addr = TPS659038_REG_ADDR_SMPS12,
449 .mpu.pmic = &tps659038,
450 .mpu.abb_tx_done_mask = OMAP_ABB_MPU_TXDONE_MASK,
451
452 .eve.value[OPP_NOM] = VDD_EVE_DRA7_NOM,
453 .eve.value[OPP_OD] = VDD_EVE_DRA7_OD,
454 .eve.value[OPP_HIGH] = VDD_EVE_DRA7_HIGH,
455 .eve.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_DSPEVE_NOM,
456 .eve.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_DSPEVE_OD,
457 .eve.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_DSPEVE_HIGH,
458 .eve.efuse.reg_bits = DRA752_EFUSE_REGBITS,
459 .eve.addr = TPS659038_REG_ADDR_SMPS45,
460 .eve.pmic = &tps659038,
461 .eve.abb_tx_done_mask = OMAP_ABB_EVE_TXDONE_MASK,
462
463 .gpu.value[OPP_NOM] = VDD_GPU_DRA7_NOM,
464 .gpu.value[OPP_OD] = VDD_GPU_DRA7_OD,
465 .gpu.value[OPP_HIGH] = VDD_GPU_DRA7_HIGH,
466 .gpu.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_GPU_NOM,
467 .gpu.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_GPU_OD,
468 .gpu.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_GPU_HIGH,
469 .gpu.efuse.reg_bits = DRA752_EFUSE_REGBITS,
470 .gpu.addr = TPS659038_REG_ADDR_SMPS6,
471 .gpu.pmic = &tps659038,
472 .gpu.abb_tx_done_mask = OMAP_ABB_GPU_TXDONE_MASK,
473
474 .core.value[OPP_NOM] = VDD_CORE_DRA7_NOM,
475 .core.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_CORE_NOM,
476 .core.efuse.reg_bits = DRA752_EFUSE_REGBITS,
477 .core.addr = TPS659038_REG_ADDR_SMPS7,
478 .core.pmic = &tps659038,
479
480 .iva.value[OPP_NOM] = VDD_IVA_DRA7_NOM,
481 .iva.value[OPP_OD] = VDD_IVA_DRA7_OD,
482 .iva.value[OPP_HIGH] = VDD_IVA_DRA7_HIGH,
483 .iva.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_IVA_NOM,
484 .iva.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_IVA_OD,
485 .iva.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_IVA_HIGH,
486 .iva.efuse.reg_bits = DRA752_EFUSE_REGBITS,
487 .iva.addr = TPS659038_REG_ADDR_SMPS45,
488 .iva.pmic = &tps659038,
489 .iva.abb_tx_done_mask = OMAP_ABB_IVA_TXDONE_MASK,
490};
491
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530492int get_voltrail_opp(int rail_offset)
493{
494 int opp;
495
496 switch (rail_offset) {
497 case VOLT_MPU:
498 opp = DRA7_MPU_OPP;
499 break;
500 case VOLT_CORE:
501 opp = DRA7_CORE_OPP;
502 break;
503 case VOLT_GPU:
504 opp = DRA7_GPU_OPP;
505 break;
506 case VOLT_EVE:
507 opp = DRA7_DSPEVE_OPP;
508 break;
509 case VOLT_IVA:
510 opp = DRA7_IVA_OPP;
511 break;
512 default:
513 opp = OPP_NOM;
514 }
515
516 return opp;
517}
518
519
Kipisz, Steven161f1382016-02-24 12:30:58 -0600520#ifdef CONFIG_SPL_BUILD
521/* No env to setup for SPL */
522static inline void setup_board_eeprom_env(void) { }
523
524/* Override function to read eeprom information */
525void do_board_detect(void)
526{
527 int rc;
528
529 rc = ti_i2c_eeprom_am_get(CONFIG_EEPROM_BUS_ADDRESS,
530 CONFIG_EEPROM_CHIP_ADDRESS);
531 if (rc)
532 printf("ti_i2c_eeprom_init failed %d\n", rc);
Caleb Robey0dfcc932020-01-02 08:17:25 -0600533
534#ifdef CONFIG_SUPPORT_EMMC_BOOT
535 rc = board_bootmode_has_emmc();
536 if (!rc)
537 rc = ti_emmc_boardid_get();
538 if (rc)
539 printf("ti_emmc_boardid_get failed %d\n", rc);
540#endif
Kipisz, Steven161f1382016-02-24 12:30:58 -0600541}
542
543#else /* CONFIG_SPL_BUILD */
544
545/* Override function to read eeprom information: actual i2c read done by SPL*/
546void do_board_detect(void)
547{
548 char *bname = NULL;
549 int rc;
550
551 rc = ti_i2c_eeprom_am_get(CONFIG_EEPROM_BUS_ADDRESS,
552 CONFIG_EEPROM_CHIP_ADDRESS);
553 if (rc)
554 printf("ti_i2c_eeprom_init failed %d\n", rc);
555
Caleb Robey0dfcc932020-01-02 08:17:25 -0600556#ifdef CONFIG_SUPPORT_EMMC_BOOT
557 rc = board_bootmode_has_emmc();
558 if (!rc)
559 rc = ti_emmc_boardid_get();
560 if (rc)
561 printf("ti_emmc_boardid_get failed %d\n", rc);
562#endif
563
Kipisz, Steven161f1382016-02-24 12:30:58 -0600564 if (board_is_x15())
565 bname = "BeagleBoard X15";
566 else if (board_is_am572x_evm())
567 bname = "AM572x EVM";
Lokesh Vutla374aea02017-12-29 11:47:52 +0530568 else if (board_is_am574x_idk())
569 bname = "AM574x IDK";
Steve Kipisz0ac8cea2016-04-08 17:01:29 -0500570 else if (board_is_am572x_idk())
571 bname = "AM572x IDK";
Steve Kipiszc95cddd2016-11-25 11:14:24 +0530572 else if (board_is_am571x_idk())
573 bname = "AM571x IDK";
Caleb Robey940d6372020-01-02 08:17:27 -0600574 else if (board_is_bbai())
575 bname = "BeagleBone AI";
Kipisz, Steven161f1382016-02-24 12:30:58 -0600576
577 if (bname)
578 snprintf(sysinfo.board_string, SYSINFO_BOARD_NAME_MAX_LEN,
579 "Board: %s REV %s\n", bname, board_ti_get_rev());
580}
581
582static void setup_board_eeprom_env(void)
583{
584 char *name = "beagle_x15";
585 int rc;
586
587 rc = ti_i2c_eeprom_am_get(CONFIG_EEPROM_BUS_ADDRESS,
588 CONFIG_EEPROM_CHIP_ADDRESS);
589 if (rc)
590 goto invalid_eeprom;
591
Nishanth Menona2aea1c2016-11-25 11:14:19 +0530592 if (board_is_x15()) {
Lokesh Vutla638e1c02016-11-25 11:14:20 +0530593 if (board_is_x15_revb1())
594 name = "beagle_x15_revb1";
Lokesh Vutla816178b2017-07-16 19:59:19 +0530595 else if (board_is_x15_revc())
596 name = "beagle_x15_revc";
Lokesh Vutla638e1c02016-11-25 11:14:20 +0530597 else
598 name = "beagle_x15";
Nishanth Menona2aea1c2016-11-25 11:14:19 +0530599 } else if (board_is_am572x_evm()) {
600 if (board_is_am572x_evm_reva3())
601 name = "am57xx_evm_reva3";
602 else
603 name = "am57xx_evm";
Lokesh Vutla374aea02017-12-29 11:47:52 +0530604 } else if (board_is_am574x_idk()) {
605 name = "am574x_idk";
Nishanth Menona2aea1c2016-11-25 11:14:19 +0530606 } else if (board_is_am572x_idk()) {
Steve Kipisz0ac8cea2016-04-08 17:01:29 -0500607 name = "am572x_idk";
Steve Kipiszc95cddd2016-11-25 11:14:24 +0530608 } else if (board_is_am571x_idk()) {
609 name = "am571x_idk";
Caleb Robey940d6372020-01-02 08:17:27 -0600610 } else if (board_is_bbai()) {
611 name = "am5729_beagleboneai";
Nishanth Menona2aea1c2016-11-25 11:14:19 +0530612 } else {
Kipisz, Steven161f1382016-02-24 12:30:58 -0600613 printf("Unidentified board claims %s in eeprom header\n",
614 board_ti_get_name());
Nishanth Menona2aea1c2016-11-25 11:14:19 +0530615 }
Kipisz, Steven161f1382016-02-24 12:30:58 -0600616
617invalid_eeprom:
618 set_board_info_env(name);
619}
620
621#endif /* CONFIG_SPL_BUILD */
622
Keerthy152e9932016-05-24 11:45:06 +0530623void vcores_init(void)
624{
Lokesh Vutla6e9635c2017-12-29 11:47:53 +0530625 if (board_is_am572x_idk() || board_is_am574x_idk())
Keerthy152e9932016-05-24 11:45:06 +0530626 *omap_vcores = &am572x_idk_volts;
Keerthy9cc2aee2017-05-25 15:37:34 +0530627 else if (board_is_am571x_idk())
628 *omap_vcores = &am571x_idk_volts;
Keerthy152e9932016-05-24 11:45:06 +0530629 else
630 *omap_vcores = &beagle_x15_volts;
631}
632
Felipe Balbi4750eb62014-11-10 14:02:44 -0600633void hw_data_init(void)
634{
635 *prcm = &dra7xx_prcm;
Steve Kipisz81c46742017-08-22 13:52:58 +0530636 if (is_dra72x())
637 *dplls_data = &dra72x_dplls;
Lokesh Vutla6e9635c2017-12-29 11:47:53 +0530638 else if (is_dra76x())
639 *dplls_data = &dra76x_dplls;
Steve Kipisz81c46742017-08-22 13:52:58 +0530640 else
641 *dplls_data = &dra7xx_dplls;
Felipe Balbi4750eb62014-11-10 14:02:44 -0600642 *ctrl = &dra7xx_ctrl;
643}
644
Roger Quadros26130592017-03-13 15:04:28 +0200645bool am571x_idk_needs_lcd(void)
646{
647 bool needs_lcd;
648
649 gpio_request(GPIO_ETH_LCD, "nLCD_Detect");
650 if (gpio_get_value(GPIO_ETH_LCD))
651 needs_lcd = false;
652 else
653 needs_lcd = true;
654
655 gpio_free(GPIO_ETH_LCD);
656
657 return needs_lcd;
658}
659
Felipe Balbi4750eb62014-11-10 14:02:44 -0600660int board_init(void)
661{
662 gpmc_init();
663 gd->bd->bi_boot_params = (CONFIG_SYS_SDRAM_BASE + 0x100);
664
665 return 0;
666}
667
Nishanth Menond0f399c2017-03-13 15:04:30 +0200668void am57x_idk_lcd_detect(void)
Felipe Balbi4750eb62014-11-10 14:02:44 -0600669{
Nishanth Menond0f399c2017-03-13 15:04:30 +0200670 int r = -ENODEV;
671 char *idk_lcd = "no";
Jean-Jacques Hiblot184ec9a2018-12-07 14:50:50 +0100672 struct udevice *dev;
Nishanth Menond0f399c2017-03-13 15:04:30 +0200673
674 /* Only valid for IDKs */
Luca Ceresoli93f6bc22020-05-21 15:06:25 +0200675 if (!board_is_ti_idk())
Nishanth Menond0f399c2017-03-13 15:04:30 +0200676 return;
677
678 /* Only AM571x IDK has gpio control detect.. so check that */
679 if (board_is_am571x_idk() && !am571x_idk_needs_lcd())
680 goto out;
681
Jean-Jacques Hiblot52a51512018-12-07 14:50:49 +0100682 r = i2c_get_chip_for_busnum(OSD_TS_FT_BUS_ADDRESS,
683 OSD_TS_FT_CHIP_ADDRESS, 1, &dev);
Nishanth Menond0f399c2017-03-13 15:04:30 +0200684 if (r) {
Jean-Jacques Hiblot52a51512018-12-07 14:50:49 +0100685 printf("%s: Failed to get I2C device %d/%d (ret %d)\n",
686 __func__, OSD_TS_FT_BUS_ADDRESS, OSD_TS_FT_CHIP_ADDRESS,
687 r);
Nishanth Menond0f399c2017-03-13 15:04:30 +0200688 /* AM572x IDK has no explicit settings for optional LCD kit */
Jean-Jacques Hiblot52a51512018-12-07 14:50:49 +0100689 if (board_is_am571x_idk())
Nishanth Menond0f399c2017-03-13 15:04:30 +0200690 printf("%s: Touch screen detect failed: %d!\n",
691 __func__, r);
Nishanth Menond0f399c2017-03-13 15:04:30 +0200692 goto out;
693 }
694
695 /* Read FT ID */
Jean-Jacques Hiblot52a51512018-12-07 14:50:49 +0100696 r = dm_i2c_reg_read(dev, OSD_TS_FT_REG_ID);
697 if (r < 0) {
Nishanth Menond0f399c2017-03-13 15:04:30 +0200698 printf("%s: Touch screen ID read %d:0x%02x[0x%02x] failed:%d\n",
699 __func__, OSD_TS_FT_BUS_ADDRESS, OSD_TS_FT_CHIP_ADDRESS,
700 OSD_TS_FT_REG_ID, r);
701 goto out;
702 }
703
Jean-Jacques Hiblot184ec9a2018-12-07 14:50:50 +0100704 switch (r) {
Nishanth Menond0f399c2017-03-13 15:04:30 +0200705 case OSD_TS_FT_ID_5606:
706 idk_lcd = "osd101t2045";
707 break;
708 case OSD_TS_FT_ID_5x46:
709 idk_lcd = "osd101t2587";
710 break;
711 default:
712 printf("%s: Unidentifed Touch screen ID 0x%02x\n",
Jean-Jacques Hiblot184ec9a2018-12-07 14:50:50 +0100713 __func__, r);
Nishanth Menond0f399c2017-03-13 15:04:30 +0200714 /* we will let default be "no lcd" */
715 }
716out:
Simon Glass6a38e412017-08-03 12:22:09 -0600717 env_set("idk_lcd", idk_lcd);
Roger Quadros8835eee2020-02-10 11:59:24 +0200718
719 /*
720 * On AM571x_IDK, no Display with J51 set to LCD is considered as an
721 * invalid configuration and we prevent boot to get user attention.
722 */
723 if (board_is_am571x_idk() && am571x_idk_needs_lcd() &&
724 !strncmp(idk_lcd, "no", 2)) {
725 printf("%s: Invalid HW configuration: display not detected/supported but J51 is set. Remove J51 to boot without display.\n",
726 __func__);
727 hang();
728 }
729
Nishanth Menond0f399c2017-03-13 15:04:30 +0200730 return;
731}
Roger Quadros26130592017-03-13 15:04:28 +0200732
Vignesh R98c5f632018-11-29 10:57:42 +0100733#if CONFIG_IS_ENABLED(DM_USB) && CONFIG_IS_ENABLED(OF_CONTROL)
734static int device_okay(const char *path)
735{
736 int node;
737
738 node = fdt_path_offset(gd->fdt_blob, path);
739 if (node < 0)
740 return 0;
741
742 return fdtdec_get_is_enabled(gd->fdt_blob, node);
743}
744#endif
745
Nishanth Menond0f399c2017-03-13 15:04:30 +0200746int board_late_init(void)
747{
Kipisz, Steven161f1382016-02-24 12:30:58 -0600748 setup_board_eeprom_env();
Keerthyee85ebe2016-11-30 15:02:53 +0530749 u8 val;
Tero Kristodfbc6b82019-09-27 19:14:27 +0300750 struct udevice *dev;
Kipisz, Steven161f1382016-02-24 12:30:58 -0600751
Felipe Balbi4750eb62014-11-10 14:02:44 -0600752 /*
753 * DEV_CTRL.DEV_ON = 1 please - else palmas switches off in 8 seconds
754 * This is the POWERHOLD-in-Low behavior.
755 */
756 palmas_i2c_write_u8(TPS65903X_CHIP_P1, 0xA0, 0x1);
Lokesh Vutla2c47e8c2016-11-29 11:58:02 +0530757
758 /*
759 * Default FIT boot on HS devices. Non FIT images are not allowed
760 * on HS devices.
761 */
762 if (get_device_type() == HS_DEVICE)
Simon Glass6a38e412017-08-03 12:22:09 -0600763 env_set("boot_fit", "1");
Lokesh Vutla2c47e8c2016-11-29 11:58:02 +0530764
Keerthyee85ebe2016-11-30 15:02:53 +0530765 /*
766 * Set the GPIO7 Pad to POWERHOLD. This has higher priority
767 * over DEV_CTRL.DEV_ON bit. This can be reset in case of
768 * PMIC Power off. So to be on the safer side set it back
769 * to POWERHOLD mode irrespective of the current state.
770 */
771 palmas_i2c_read_u8(TPS65903X_CHIP_P1, TPS65903X_PRIMARY_SECONDARY_PAD2,
772 &val);
773 val = val | TPS65903X_PAD2_POWERHOLD_MASK;
774 palmas_i2c_write_u8(TPS65903X_CHIP_P1, TPS65903X_PRIMARY_SECONDARY_PAD2,
775 val);
776
Semen Protsenko4b0721f2017-02-13 19:09:37 +0200777 omap_die_id_serial();
Semen Protsenkob72dccd2017-05-22 19:16:41 +0300778 omap_set_fastboot_vars();
Semen Protsenko4b0721f2017-02-13 19:09:37 +0200779
Nishanth Menond0f399c2017-03-13 15:04:30 +0200780 am57x_idk_lcd_detect();
Roger Quadros26130592017-03-13 15:04:28 +0200781
Tero Kristodfbc6b82019-09-27 19:14:27 +0300782 /* Just probe the potentially supported cdce913 device */
783 uclass_get_device(UCLASS_CLK, 0, &dev);
784
Caleb Robey940d6372020-01-02 08:17:27 -0600785 if (board_is_bbai())
786 env_set("console", "ttyS0,115200n8");
787
Roger Quadros26130592017-03-13 15:04:28 +0200788#if !defined(CONFIG_SPL_BUILD)
789 board_ti_set_ethaddr(2);
790#endif
791
Vignesh R98c5f632018-11-29 10:57:42 +0100792#if CONFIG_IS_ENABLED(DM_USB) && CONFIG_IS_ENABLED(OF_CONTROL)
793 if (device_okay("/ocp/omap_dwc3_1@48880000"))
794 enable_usb_clocks(0);
795 if (device_okay("/ocp/omap_dwc3_2@488c0000"))
796 enable_usb_clocks(1);
797#endif
Felipe Balbi4750eb62014-11-10 14:02:44 -0600798 return 0;
799}
800
Paul Kocialkowskia00b1e52016-02-27 19:18:56 +0100801void set_muxconf_regs(void)
Felipe Balbi4750eb62014-11-10 14:02:44 -0600802{
803 do_set_mux32((*ctrl)->control_padconf_core_base,
Lokesh Vutlac3d39f92015-06-04 16:42:41 +0530804 early_padconf, ARRAY_SIZE(early_padconf));
Caleb Robey0dfcc932020-01-02 08:17:25 -0600805
806#ifdef CONFIG_SUPPORT_EMMC_BOOT
807 do_set_mux32((*ctrl)->control_padconf_core_base,
808 emmc_padconf, ARRAY_SIZE(emmc_padconf));
809#endif
Felipe Balbi4750eb62014-11-10 14:02:44 -0600810}
811
Lokesh Vutlac3d39f92015-06-04 16:42:41 +0530812#ifdef CONFIG_IODELAY_RECALIBRATION
813void recalibrate_iodelay(void)
814{
Steve Kipisz0ac8cea2016-04-08 17:01:29 -0500815 const struct pad_conf_entry *pconf;
Lokesh Vutla3cb4c622017-06-05 14:48:16 +0530816 const struct iodelay_cfg_entry *iod, *delta_iod;
817 int pconf_sz, iod_sz, delta_iod_sz = 0;
Nishanth Menon8e3212e2016-11-25 11:14:22 +0530818 int ret;
Steve Kipisz0ac8cea2016-04-08 17:01:29 -0500819
Lokesh Vutla1e3425c2017-12-29 11:47:55 +0530820 if (board_is_am572x_idk()) {
Steve Kipisz0ac8cea2016-04-08 17:01:29 -0500821 pconf = core_padconf_array_essential_am572x_idk;
822 pconf_sz = ARRAY_SIZE(core_padconf_array_essential_am572x_idk);
823 iod = iodelay_cfg_array_am572x_idk;
824 iod_sz = ARRAY_SIZE(iodelay_cfg_array_am572x_idk);
Lokesh Vutla1e3425c2017-12-29 11:47:55 +0530825 } else if (board_is_am574x_idk()) {
826 pconf = core_padconf_array_essential_am574x_idk;
827 pconf_sz = ARRAY_SIZE(core_padconf_array_essential_am574x_idk);
828 iod = iodelay_cfg_array_am574x_idk;
829 iod_sz = ARRAY_SIZE(iodelay_cfg_array_am574x_idk);
Steve Kipiszc95cddd2016-11-25 11:14:24 +0530830 } else if (board_is_am571x_idk()) {
831 pconf = core_padconf_array_essential_am571x_idk;
832 pconf_sz = ARRAY_SIZE(core_padconf_array_essential_am571x_idk);
833 iod = iodelay_cfg_array_am571x_idk;
834 iod_sz = ARRAY_SIZE(iodelay_cfg_array_am571x_idk);
Caleb Robey940d6372020-01-02 08:17:27 -0600835 } else if (board_is_bbai()) {
836 pconf = core_padconf_array_essential_bbai;
837 pconf_sz = ARRAY_SIZE(core_padconf_array_essential_bbai);
838 iod = iodelay_cfg_array_bbai;
839 iod_sz = ARRAY_SIZE(iodelay_cfg_array_bbai);
Steve Kipisz0ac8cea2016-04-08 17:01:29 -0500840 } else {
841 /* Common for X15/GPEVM */
842 pconf = core_padconf_array_essential_x15;
843 pconf_sz = ARRAY_SIZE(core_padconf_array_essential_x15);
Nishanth Menon8e3212e2016-11-25 11:14:22 +0530844 /* There never was an SR1.0 X15.. So.. */
845 if (omap_revision() == DRA752_ES1_1) {
846 iod = iodelay_cfg_array_x15_sr1_1;
847 iod_sz = ARRAY_SIZE(iodelay_cfg_array_x15_sr1_1);
848 } else {
849 /* Since full production should switch to SR2.0 */
850 iod = iodelay_cfg_array_x15_sr2_0;
851 iod_sz = ARRAY_SIZE(iodelay_cfg_array_x15_sr2_0);
852 }
Steve Kipisz0ac8cea2016-04-08 17:01:29 -0500853 }
854
Nishanth Menon8e3212e2016-11-25 11:14:22 +0530855 /* Setup I/O isolation */
856 ret = __recalibrate_iodelay_start();
857 if (ret)
858 goto err;
859
860 /* Do the muxing here */
861 do_set_mux32((*ctrl)->control_padconf_core_base, pconf, pconf_sz);
862
863 /* Now do the weird minor deltas that should be safe */
864 if (board_is_x15() || board_is_am572x_evm()) {
Lokesh Vutla816178b2017-07-16 19:59:19 +0530865 if (board_is_x15_revb1() || board_is_am572x_evm_reva3() ||
866 board_is_x15_revc()) {
Nishanth Menon8e3212e2016-11-25 11:14:22 +0530867 pconf = core_padconf_array_delta_x15_sr2_0;
868 pconf_sz = ARRAY_SIZE(core_padconf_array_delta_x15_sr2_0);
869 } else {
870 pconf = core_padconf_array_delta_x15_sr1_1;
871 pconf_sz = ARRAY_SIZE(core_padconf_array_delta_x15_sr1_1);
872 }
873 do_set_mux32((*ctrl)->control_padconf_core_base, pconf, pconf_sz);
874 }
875
Roger Quadros26130592017-03-13 15:04:28 +0200876 if (board_is_am571x_idk()) {
877 if (am571x_idk_needs_lcd()) {
878 pconf = core_padconf_array_vout_am571x_idk;
879 pconf_sz = ARRAY_SIZE(core_padconf_array_vout_am571x_idk);
Lokesh Vutla3cb4c622017-06-05 14:48:16 +0530880 delta_iod = iodelay_cfg_array_am571x_idk_4port;
881 delta_iod_sz = ARRAY_SIZE(iodelay_cfg_array_am571x_idk_4port);
882
Roger Quadros26130592017-03-13 15:04:28 +0200883 } else {
884 pconf = core_padconf_array_icss1eth_am571x_idk;
885 pconf_sz = ARRAY_SIZE(core_padconf_array_icss1eth_am571x_idk);
886 }
887 do_set_mux32((*ctrl)->control_padconf_core_base, pconf, pconf_sz);
888 }
889
Nishanth Menon8e3212e2016-11-25 11:14:22 +0530890 /* Setup IOdelay configuration */
891 ret = do_set_iodelay((*ctrl)->iodelay_config_base, iod, iod_sz);
Lokesh Vutla3cb4c622017-06-05 14:48:16 +0530892 if (delta_iod_sz)
893 ret = do_set_iodelay((*ctrl)->iodelay_config_base, delta_iod,
894 delta_iod_sz);
895
Nishanth Menon8e3212e2016-11-25 11:14:22 +0530896err:
897 /* Closeup.. remove isolation */
898 __recalibrate_iodelay_end(ret);
Lokesh Vutlac3d39f92015-06-04 16:42:41 +0530899}
900#endif
901
Masahiro Yamada0a780172017-05-09 20:31:39 +0900902#if defined(CONFIG_MMC)
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900903int board_mmc_init(struct bd_info *bis)
Felipe Balbi4750eb62014-11-10 14:02:44 -0600904{
905 omap_mmc_init(0, 0, 0, -1, -1);
906 omap_mmc_init(1, 0, 0, -1, -1);
907 return 0;
908}
Kishon Vijay Abraham I110ed012018-01-30 16:01:52 +0100909
910static const struct mmc_platform_fixups am57x_es1_1_mmc1_fixups = {
911 .hw_rev = "rev11",
912 .unsupported_caps = MMC_CAP(MMC_HS_200) |
913 MMC_CAP(UHS_SDR104),
914 .max_freq = 96000000,
915};
916
917static const struct mmc_platform_fixups am57x_es1_1_mmc23_fixups = {
918 .hw_rev = "rev11",
919 .unsupported_caps = MMC_CAP(MMC_HS_200) |
920 MMC_CAP(UHS_SDR104) |
921 MMC_CAP(UHS_SDR50),
922 .max_freq = 48000000,
923};
924
925const struct mmc_platform_fixups *platform_fixups_mmc(uint32_t addr)
926{
927 switch (omap_revision()) {
928 case DRA752_ES1_0:
929 case DRA752_ES1_1:
930 if (addr == OMAP_HSMMC1_BASE)
931 return &am57x_es1_1_mmc1_fixups;
932 else
933 return &am57x_es1_1_mmc23_fixups;
934 default:
935 return NULL;
936 }
937}
Felipe Balbi4750eb62014-11-10 14:02:44 -0600938#endif
939
940#if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_OS_BOOT)
941int spl_start_uboot(void)
942{
943 /* break into full u-boot on 'c' */
944 if (serial_tstc() && serial_getc() == 'c')
945 return 1;
946
947#ifdef CONFIG_SPL_ENV_SUPPORT
948 env_init();
Simon Glass17539572017-08-03 12:22:07 -0600949 env_load();
Simon Glass22c34c22017-08-03 12:22:13 -0600950 if (env_get_yesno("boot_os") != 1)
Felipe Balbi4750eb62014-11-10 14:02:44 -0600951 return 1;
952#endif
953
954 return 0;
955}
956#endif
957
958#ifdef CONFIG_DRIVER_TI_CPSW
959
960/* Delay value to add to calibrated value */
961#define RGMII0_TXCTL_DLY_VAL ((0x3 << 5) + 0x8)
962#define RGMII0_TXD0_DLY_VAL ((0x3 << 5) + 0x8)
963#define RGMII0_TXD1_DLY_VAL ((0x3 << 5) + 0x2)
964#define RGMII0_TXD2_DLY_VAL ((0x4 << 5) + 0x0)
965#define RGMII0_TXD3_DLY_VAL ((0x4 << 5) + 0x0)
966#define VIN2A_D13_DLY_VAL ((0x3 << 5) + 0x8)
967#define VIN2A_D17_DLY_VAL ((0x3 << 5) + 0x8)
968#define VIN2A_D16_DLY_VAL ((0x3 << 5) + 0x2)
969#define VIN2A_D15_DLY_VAL ((0x4 << 5) + 0x0)
970#define VIN2A_D14_DLY_VAL ((0x4 << 5) + 0x0)
971
972static void cpsw_control(int enabled)
973{
974 /* VTP can be added here */
975}
976
977static struct cpsw_slave_data cpsw_slaves[] = {
978 {
979 .slave_reg_ofs = 0x208,
980 .sliver_reg_ofs = 0xd80,
981 .phy_addr = 1,
982 },
983 {
984 .slave_reg_ofs = 0x308,
985 .sliver_reg_ofs = 0xdc0,
986 .phy_addr = 2,
987 },
988};
989
990static struct cpsw_platform_data cpsw_data = {
991 .mdio_base = CPSW_MDIO_BASE,
992 .cpsw_base = CPSW_BASE,
993 .mdio_div = 0xff,
994 .channels = 8,
995 .cpdma_reg_ofs = 0x800,
996 .slaves = 1,
997 .slave_data = cpsw_slaves,
998 .ale_reg_ofs = 0xd00,
999 .ale_entries = 1024,
1000 .host_port_reg_ofs = 0x108,
1001 .hw_stats_reg_ofs = 0x900,
1002 .bd_ram_ofs = 0x2000,
1003 .mac_control = (1 << 5),
1004 .control = cpsw_control,
1005 .host_port_num = 0,
1006 .version = CPSW_CTRL_VERSION_2,
1007};
1008
Roger Quadros64217a22016-03-18 13:18:12 +02001009static u64 mac_to_u64(u8 mac[6])
1010{
1011 int i;
1012 u64 addr = 0;
1013
1014 for (i = 0; i < 6; i++) {
1015 addr <<= 8;
1016 addr |= mac[i];
1017 }
1018
1019 return addr;
1020}
1021
1022static void u64_to_mac(u64 addr, u8 mac[6])
1023{
1024 mac[5] = addr;
1025 mac[4] = addr >> 8;
1026 mac[3] = addr >> 16;
1027 mac[2] = addr >> 24;
1028 mac[1] = addr >> 32;
1029 mac[0] = addr >> 40;
1030}
1031
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +09001032int board_eth_init(struct bd_info *bis)
Felipe Balbi4750eb62014-11-10 14:02:44 -06001033{
1034 int ret;
1035 uint8_t mac_addr[6];
1036 uint32_t mac_hi, mac_lo;
1037 uint32_t ctrl_val;
Roger Quadros64217a22016-03-18 13:18:12 +02001038 int i;
1039 u64 mac1, mac2;
1040 u8 mac_addr1[6], mac_addr2[6];
1041 int num_macs;
Felipe Balbi4750eb62014-11-10 14:02:44 -06001042
1043 /* try reading mac address from efuse */
1044 mac_lo = readl((*ctrl)->control_core_mac_id_0_lo);
1045 mac_hi = readl((*ctrl)->control_core_mac_id_0_hi);
1046 mac_addr[0] = (mac_hi & 0xFF0000) >> 16;
1047 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
1048 mac_addr[2] = mac_hi & 0xFF;
1049 mac_addr[3] = (mac_lo & 0xFF0000) >> 16;
1050 mac_addr[4] = (mac_lo & 0xFF00) >> 8;
1051 mac_addr[5] = mac_lo & 0xFF;
1052
Simon Glass64b723f2017-08-03 12:22:12 -06001053 if (!env_get("ethaddr")) {
Felipe Balbi4750eb62014-11-10 14:02:44 -06001054 printf("<ethaddr> not set. Validating first E-fuse MAC\n");
1055
Joe Hershberger8ecdbed2015-04-08 01:41:04 -05001056 if (is_valid_ethaddr(mac_addr))
Simon Glass8551d552017-08-03 12:22:11 -06001057 eth_env_set_enetaddr("ethaddr", mac_addr);
Felipe Balbi4750eb62014-11-10 14:02:44 -06001058 }
1059
1060 mac_lo = readl((*ctrl)->control_core_mac_id_1_lo);
1061 mac_hi = readl((*ctrl)->control_core_mac_id_1_hi);
1062 mac_addr[0] = (mac_hi & 0xFF0000) >> 16;
1063 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
1064 mac_addr[2] = mac_hi & 0xFF;
1065 mac_addr[3] = (mac_lo & 0xFF0000) >> 16;
1066 mac_addr[4] = (mac_lo & 0xFF00) >> 8;
1067 mac_addr[5] = mac_lo & 0xFF;
1068
Simon Glass64b723f2017-08-03 12:22:12 -06001069 if (!env_get("eth1addr")) {
Joe Hershberger8ecdbed2015-04-08 01:41:04 -05001070 if (is_valid_ethaddr(mac_addr))
Simon Glass8551d552017-08-03 12:22:11 -06001071 eth_env_set_enetaddr("eth1addr", mac_addr);
Felipe Balbi4750eb62014-11-10 14:02:44 -06001072 }
1073
1074 ctrl_val = readl((*ctrl)->control_core_control_io1) & (~0x33);
1075 ctrl_val |= 0x22;
1076 writel(ctrl_val, (*ctrl)->control_core_control_io1);
1077
Steve Kipiszc95cddd2016-11-25 11:14:24 +05301078 /* The phy address for the AM57xx IDK are different than x15 */
Lokesh Vutla6e9635c2017-12-29 11:47:53 +05301079 if (board_is_am572x_idk() || board_is_am571x_idk() ||
1080 board_is_am574x_idk()) {
Steve Kipisz0ac8cea2016-04-08 17:01:29 -05001081 cpsw_data.slave_data[0].phy_addr = 0;
1082 cpsw_data.slave_data[1].phy_addr = 1;
1083 }
1084
Felipe Balbi4750eb62014-11-10 14:02:44 -06001085 ret = cpsw_register(&cpsw_data);
1086 if (ret < 0)
1087 printf("Error %d registering CPSW switch\n", ret);
1088
Roger Quadros64217a22016-03-18 13:18:12 +02001089 /*
1090 * Export any Ethernet MAC addresses from EEPROM.
1091 * On AM57xx the 2 MAC addresses define the address range
1092 */
1093 board_ti_get_eth_mac_addr(0, mac_addr1);
1094 board_ti_get_eth_mac_addr(1, mac_addr2);
1095
1096 if (is_valid_ethaddr(mac_addr1) && is_valid_ethaddr(mac_addr2)) {
1097 mac1 = mac_to_u64(mac_addr1);
1098 mac2 = mac_to_u64(mac_addr2);
1099
1100 /* must contain an address range */
1101 num_macs = mac2 - mac1 + 1;
1102 /* <= 50 to protect against user programming error */
1103 if (num_macs > 0 && num_macs <= 50) {
1104 for (i = 0; i < num_macs; i++) {
1105 u64_to_mac(mac1 + i, mac_addr);
1106 if (is_valid_ethaddr(mac_addr)) {
Simon Glass8551d552017-08-03 12:22:11 -06001107 eth_env_set_enetaddr_by_index("eth",
1108 i + 2,
1109 mac_addr);
Roger Quadros64217a22016-03-18 13:18:12 +02001110 }
1111 }
1112 }
1113 }
1114
Felipe Balbi4750eb62014-11-10 14:02:44 -06001115 return ret;
1116}
1117#endif
Lokesh Vutla9f150672015-06-16 20:36:05 +05301118
1119#ifdef CONFIG_BOARD_EARLY_INIT_F
1120/* VTT regulator enable */
1121static inline void vtt_regulator_enable(void)
1122{
1123 if (omap_hw_init_context() == OMAP_INIT_CONTEXT_UBOOT_AFTER_SPL)
1124 return;
1125
1126 gpio_request(GPIO_DDR_VTT_EN, "ddr_vtt_en");
1127 gpio_direction_output(GPIO_DDR_VTT_EN, 1);
1128}
1129
1130int board_early_init_f(void)
1131{
1132 vtt_regulator_enable();
1133 return 0;
1134}
1135#endif
Daniel Allred7ceffb22016-05-19 19:10:54 -05001136
1137#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +09001138int ft_board_setup(void *blob, struct bd_info *bd)
Daniel Allred7ceffb22016-05-19 19:10:54 -05001139{
1140 ft_cpu_setup(blob, bd);
1141
1142 return 0;
1143}
1144#endif
Lokesh Vutla00bf8b22016-06-10 09:35:43 +05301145
1146#ifdef CONFIG_SPL_LOAD_FIT
1147int board_fit_config_name_match(const char *name)
1148{
Lokesh Vutla638e1c02016-11-25 11:14:20 +05301149 if (board_is_x15()) {
1150 if (board_is_x15_revb1()) {
1151 if (!strcmp(name, "am57xx-beagle-x15-revb1"))
1152 return 0;
Lokesh Vutlaf35589c2017-08-23 11:39:06 +05301153 } else if (board_is_x15_revc()) {
1154 if (!strcmp(name, "am57xx-beagle-x15-revc"))
1155 return 0;
Lokesh Vutla638e1c02016-11-25 11:14:20 +05301156 } else if (!strcmp(name, "am57xx-beagle-x15")) {
1157 return 0;
1158 }
1159 } else if (board_is_am572x_evm() &&
1160 !strcmp(name, "am57xx-beagle-x15")) {
Lokesh Vutla00bf8b22016-06-10 09:35:43 +05301161 return 0;
Lokesh Vutla638e1c02016-11-25 11:14:20 +05301162 } else if (board_is_am572x_idk() && !strcmp(name, "am572x-idk")) {
Schuyler Patton99519852016-06-10 09:35:45 +05301163 return 0;
Lokesh Vutla58a3c1b2017-12-29 11:47:57 +05301164 } else if (board_is_am574x_idk() && !strcmp(name, "am574x-idk")) {
1165 return 0;
Schuyler Pattonc665e272016-11-25 11:14:25 +05301166 } else if (board_is_am571x_idk() && !strcmp(name, "am571x-idk")) {
1167 return 0;
Caleb Robey940d6372020-01-02 08:17:27 -06001168 } else if (board_is_bbai() && !strcmp(name, "am5729-beagleboneai")) {
1169 return 0;
Lokesh Vutla638e1c02016-11-25 11:14:20 +05301170 }
1171
1172 return -1;
Lokesh Vutla00bf8b22016-06-10 09:35:43 +05301173}
1174#endif
Andreas Dannenberg5cf344b2016-06-27 09:19:22 -05001175
Andrew F. Davisd3555832019-02-11 08:00:08 -06001176#if CONFIG_IS_ENABLED(FASTBOOT) && !CONFIG_IS_ENABLED(ENV_IS_NOWHERE)
Roman Kovalivskyi1bb13422020-07-28 23:35:32 +03001177int fastboot_set_reboot_flag(enum fastboot_reboot_reason reason)
Andrew F. Davisd3555832019-02-11 08:00:08 -06001178{
Roman Kovalivskyi1bb13422020-07-28 23:35:32 +03001179 if (reason != FASTBOOT_REBOOT_REASON_BOOTLOADER)
1180 return -ENOTSUPP;
1181
Andrew F. Davisd3555832019-02-11 08:00:08 -06001182 printf("Setting reboot to fastboot flag ...\n");
1183 env_set("dofastboot", "1");
1184 env_save();
1185 return 0;
1186}
1187#endif
1188
Caleb Robey0dfcc932020-01-02 08:17:25 -06001189#ifdef CONFIG_SUPPORT_EMMC_BOOT
1190static int board_bootmode_has_emmc(void)
1191{
1192 /* Check that boot mode is same as BBAI */
1193 if (gd->arch.omap_boot_mode != 2)
1194 return -EIO;
1195
1196 return 0;
1197}
1198#endif
1199
Andreas Dannenberg5cf344b2016-06-27 09:19:22 -05001200#ifdef CONFIG_TI_SECURE_DEVICE
1201void board_fit_image_post_process(void **p_image, size_t *p_size)
1202{
1203 secure_boot_verify_image(p_image, p_size);
1204}
Andrew F. Davis7d250622016-11-29 16:33:26 -06001205
1206void board_tee_image_process(ulong tee_image, size_t tee_size)
1207{
1208 secure_tee_install((u32)tee_image);
1209}
1210
1211U_BOOT_FIT_LOADABLE_HANDLER(IH_TYPE_TEE, board_tee_image_process);
Andreas Dannenberg5cf344b2016-06-27 09:19:22 -05001212#endif