blob: 399a2e5d9130ccc13c3467506e12eb420c096bfa [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"
Kory Maincent66fd9ec2021-05-04 19:31:25 +020046#include "../common/cape_detect.h"
Felipe Balbi4750eb62014-11-10 14:02:44 -060047#include "mux_data.h"
48
Caleb Robey0dfcc932020-01-02 08:17:25 -060049#ifdef CONFIG_SUPPORT_EMMC_BOOT
50static int board_bootmode_has_emmc(void);
51#endif
52
Kipisz, Steven161f1382016-02-24 12:30:58 -060053#define board_is_x15() board_ti_is("BBRDX15_")
Lokesh Vutla638e1c02016-11-25 11:14:20 +053054#define board_is_x15_revb1() (board_ti_is("BBRDX15_") && \
Lokesh Vutlaab4f71e2017-07-16 19:59:18 +053055 !strncmp("B.10", board_ti_get_rev(), 3))
Lokesh Vutla816178b2017-07-16 19:59:19 +053056#define board_is_x15_revc() (board_ti_is("BBRDX15_") && \
57 !strncmp("C.00", board_ti_get_rev(), 3))
Kipisz, Steven161f1382016-02-24 12:30:58 -060058#define board_is_am572x_evm() board_ti_is("AM572PM_")
Nishanth Menona2aea1c2016-11-25 11:14:19 +053059#define board_is_am572x_evm_reva3() \
60 (board_ti_is("AM572PM_") && \
Lokesh Vutlaab4f71e2017-07-16 19:59:18 +053061 !strncmp("A.30", board_ti_get_rev(), 3))
Lokesh Vutla374aea02017-12-29 11:47:52 +053062#define board_is_am574x_idk() board_ti_is("AM574IDK")
Steve Kipisz0ac8cea2016-04-08 17:01:29 -050063#define board_is_am572x_idk() board_ti_is("AM572IDK")
Steve Kipiszc95cddd2016-11-25 11:14:24 +053064#define board_is_am571x_idk() board_ti_is("AM571IDK")
Caleb Robey940d6372020-01-02 08:17:27 -060065#define board_is_bbai() board_ti_is("BBONE-AI")
Kipisz, Steven161f1382016-02-24 12:30:58 -060066
Luca Ceresoli93f6bc22020-05-21 15:06:25 +020067#define board_is_ti_idk() board_is_am574x_idk() || \
68 board_is_am572x_idk() || \
69 board_is_am571x_idk()
70
Felipe Balbi4750eb62014-11-10 14:02:44 -060071#ifdef CONFIG_DRIVER_TI_CPSW
72#include <cpsw.h>
73#endif
74
75DECLARE_GLOBAL_DATA_PTR;
76
Roger Quadros26130592017-03-13 15:04:28 +020077#define GPIO_ETH_LCD GPIO_TO_PIN(2, 22)
Luca Ceresoliacea16b2020-05-21 15:06:24 +020078#define GPIO_DDR_VTT_EN GPIO_TO_PIN(7, 11)
Lokesh Vutla9f150672015-06-16 20:36:05 +053079
Nishanth Menond0f399c2017-03-13 15:04:30 +020080/* Touch screen controller to identify the LCD */
81#define OSD_TS_FT_BUS_ADDRESS 0
82#define OSD_TS_FT_CHIP_ADDRESS 0x38
83#define OSD_TS_FT_REG_ID 0xA3
84/*
85 * Touchscreen IDs for various OSD panels
86 * Ref: http://www.osddisplays.com/TI/OSD101T2587-53TS_A.1.pdf
87 */
88/* Used on newer osd101t2587 Panels */
89#define OSD_TS_FT_ID_5x46 0x54
90/* Used on older osd101t2045 Panels */
91#define OSD_TS_FT_ID_5606 0x08
92
Kipisz, Steven161f1382016-02-24 12:30:58 -060093#define SYSINFO_BOARD_NAME_MAX_LEN 45
94
Keerthyee85ebe2016-11-30 15:02:53 +053095#define TPS65903X_PRIMARY_SECONDARY_PAD2 0xFB
96#define TPS65903X_PAD2_POWERHOLD_MASK 0x20
97
Felipe Balbi4750eb62014-11-10 14:02:44 -060098const struct omap_sysinfo sysinfo = {
Kipisz, Steven161f1382016-02-24 12:30:58 -060099 "Board: UNKNOWN(BeagleBoard X15?) REV UNKNOWN\n"
Felipe Balbi4750eb62014-11-10 14:02:44 -0600100};
101
102static const struct dmm_lisa_map_regs beagle_x15_lisa_regs = {
103 .dmm_lisa_map_3 = 0x80740300,
104 .is_ma_present = 0x1
105};
106
Steve Kipiszc95cddd2016-11-25 11:14:24 +0530107static const struct dmm_lisa_map_regs am571x_idk_lisa_regs = {
108 .dmm_lisa_map_3 = 0x80640100,
109 .is_ma_present = 0x1
110};
111
Lokesh Vutlacbd70db2017-12-29 11:47:54 +0530112static const struct dmm_lisa_map_regs am574x_idk_lisa_regs = {
113 .dmm_lisa_map_2 = 0xc0600200,
114 .dmm_lisa_map_3 = 0x80600100,
115 .is_ma_present = 0x1
116};
117
Caleb Robey940d6372020-01-02 08:17:27 -0600118static const struct dmm_lisa_map_regs bbai_lisa_regs = {
119 .dmm_lisa_map_3 = 0x80640100,
120 .is_ma_present = 0x1
121};
122
Felipe Balbi4750eb62014-11-10 14:02:44 -0600123void emif_get_dmm_regs(const struct dmm_lisa_map_regs **dmm_lisa_regs)
124{
Steve Kipiszc95cddd2016-11-25 11:14:24 +0530125 if (board_is_am571x_idk())
126 *dmm_lisa_regs = &am571x_idk_lisa_regs;
Lokesh Vutlacbd70db2017-12-29 11:47:54 +0530127 else if (board_is_am574x_idk())
128 *dmm_lisa_regs = &am574x_idk_lisa_regs;
Caleb Robey940d6372020-01-02 08:17:27 -0600129 else if (board_is_bbai())
130 *dmm_lisa_regs = &bbai_lisa_regs;
Steve Kipiszc95cddd2016-11-25 11:14:24 +0530131 else
132 *dmm_lisa_regs = &beagle_x15_lisa_regs;
Felipe Balbi4750eb62014-11-10 14:02:44 -0600133}
134
135static const struct emif_regs beagle_x15_emif1_ddr3_532mhz_emif_regs = {
Keerthy66dd8062016-05-24 11:45:07 +0530136 .sdram_config_init = 0x61851b32,
137 .sdram_config = 0x61851b32,
138 .sdram_config2 = 0x08000000,
139 .ref_ctrl = 0x000040F1,
140 .ref_ctrl_final = 0x00001035,
141 .sdram_tim1 = 0xcccf36ab,
142 .sdram_tim2 = 0x308f7fda,
143 .sdram_tim3 = 0x409f88a8,
144 .read_idle_ctrl = 0x00050000,
145 .zq_config = 0x5007190b,
146 .temp_alert_config = 0x00000000,
147 .emif_ddr_phy_ctlr_1_init = 0x0024400b,
148 .emif_ddr_phy_ctlr_1 = 0x0e24400b,
149 .emif_ddr_ext_phy_ctrl_1 = 0x10040100,
150 .emif_ddr_ext_phy_ctrl_2 = 0x00910091,
151 .emif_ddr_ext_phy_ctrl_3 = 0x00950095,
152 .emif_ddr_ext_phy_ctrl_4 = 0x009b009b,
153 .emif_ddr_ext_phy_ctrl_5 = 0x009e009e,
154 .emif_rd_wr_lvl_rmp_win = 0x00000000,
155 .emif_rd_wr_lvl_rmp_ctl = 0x80000000,
156 .emif_rd_wr_lvl_ctl = 0x00000000,
157 .emif_rd_wr_exec_thresh = 0x00000305
Felipe Balbi4750eb62014-11-10 14:02:44 -0600158};
159
Lokesh Vutla979d2c32015-06-03 14:43:21 +0530160/* Ext phy ctrl regs 1-35 */
Felipe Balbi4750eb62014-11-10 14:02:44 -0600161static const u32 beagle_x15_emif1_ddr3_ext_phy_ctrl_const_regs[] = {
Lokesh Vutla979d2c32015-06-03 14:43:21 +0530162 0x10040100,
Lokesh Vutla306b5972016-03-08 09:11:35 +0530163 0x00910091,
164 0x00950095,
165 0x009B009B,
166 0x009E009E,
167 0x00980098,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600168 0x00340034,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600169 0x00350035,
Lokesh Vutla306b5972016-03-08 09:11:35 +0530170 0x00340034,
171 0x00310031,
172 0x00340034,
173 0x007F007F,
174 0x007F007F,
175 0x007F007F,
176 0x007F007F,
177 0x007F007F,
178 0x00480048,
179 0x004A004A,
180 0x00520052,
181 0x00550055,
182 0x00500050,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600183 0x00000000,
184 0x00600020,
Lokesh Vutla979d2c32015-06-03 14:43:21 +0530185 0x40011080,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600186 0x08102040,
Lokesh Vutla306b5972016-03-08 09:11:35 +0530187 0x0,
188 0x0,
189 0x0,
190 0x0,
Lokesh Vutla51a0f1f2015-06-03 14:43:22 +0530191 0x0,
192 0x0,
193 0x0,
194 0x0,
Lokesh Vutla306b5972016-03-08 09:11:35 +0530195 0x0,
Lokesh Vutla51a0f1f2015-06-03 14:43:22 +0530196 0x0
Felipe Balbi4750eb62014-11-10 14:02:44 -0600197};
198
199static const struct emif_regs beagle_x15_emif2_ddr3_532mhz_emif_regs = {
Keerthy66dd8062016-05-24 11:45:07 +0530200 .sdram_config_init = 0x61851b32,
201 .sdram_config = 0x61851b32,
202 .sdram_config2 = 0x08000000,
203 .ref_ctrl = 0x000040F1,
204 .ref_ctrl_final = 0x00001035,
205 .sdram_tim1 = 0xcccf36b3,
206 .sdram_tim2 = 0x308f7fda,
207 .sdram_tim3 = 0x407f88a8,
208 .read_idle_ctrl = 0x00050000,
209 .zq_config = 0x5007190b,
210 .temp_alert_config = 0x00000000,
211 .emif_ddr_phy_ctlr_1_init = 0x0024400b,
212 .emif_ddr_phy_ctlr_1 = 0x0e24400b,
213 .emif_ddr_ext_phy_ctrl_1 = 0x10040100,
214 .emif_ddr_ext_phy_ctrl_2 = 0x00910091,
215 .emif_ddr_ext_phy_ctrl_3 = 0x00950095,
216 .emif_ddr_ext_phy_ctrl_4 = 0x009b009b,
217 .emif_ddr_ext_phy_ctrl_5 = 0x009e009e,
218 .emif_rd_wr_lvl_rmp_win = 0x00000000,
219 .emif_rd_wr_lvl_rmp_ctl = 0x80000000,
220 .emif_rd_wr_lvl_ctl = 0x00000000,
221 .emif_rd_wr_exec_thresh = 0x00000305
Felipe Balbi4750eb62014-11-10 14:02:44 -0600222};
223
224static const u32 beagle_x15_emif2_ddr3_ext_phy_ctrl_const_regs[] = {
Lokesh Vutla979d2c32015-06-03 14:43:21 +0530225 0x10040100,
Lokesh Vutla306b5972016-03-08 09:11:35 +0530226 0x00910091,
227 0x00950095,
228 0x009B009B,
229 0x009E009E,
230 0x00980098,
231 0x00340034,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600232 0x00350035,
Lokesh Vutla306b5972016-03-08 09:11:35 +0530233 0x00340034,
234 0x00310031,
235 0x00340034,
236 0x007F007F,
237 0x007F007F,
238 0x007F007F,
239 0x007F007F,
240 0x007F007F,
241 0x00480048,
242 0x004A004A,
243 0x00520052,
244 0x00550055,
245 0x00500050,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600246 0x00000000,
247 0x00600020,
Lokesh Vutla979d2c32015-06-03 14:43:21 +0530248 0x40011080,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600249 0x08102040,
Lokesh Vutla306b5972016-03-08 09:11:35 +0530250 0x0,
251 0x0,
252 0x0,
253 0x0,
254 0x0,
Lokesh Vutla51a0f1f2015-06-03 14:43:22 +0530255 0x0,
256 0x0,
257 0x0,
258 0x0,
259 0x0
Felipe Balbi4750eb62014-11-10 14:02:44 -0600260};
261
Steve Kipisz81c46742017-08-22 13:52:58 +0530262static const struct emif_regs am571x_emif1_ddr3_666mhz_emif_regs = {
263 .sdram_config_init = 0x61863332,
264 .sdram_config = 0x61863332,
265 .sdram_config2 = 0x08000000,
266 .ref_ctrl = 0x0000514d,
267 .ref_ctrl_final = 0x0000144a,
268 .sdram_tim1 = 0xd333887c,
Lokesh Vutlacbd70db2017-12-29 11:47:54 +0530269 .sdram_tim2 = 0x30b37fe3,
270 .sdram_tim3 = 0x409f8ad8,
Steve Kipisz81c46742017-08-22 13:52:58 +0530271 .read_idle_ctrl = 0x00050000,
272 .zq_config = 0x5007190b,
273 .temp_alert_config = 0x00000000,
274 .emif_ddr_phy_ctlr_1_init = 0x0024400f,
275 .emif_ddr_phy_ctlr_1 = 0x0e24400f,
276 .emif_ddr_ext_phy_ctrl_1 = 0x10040100,
277 .emif_ddr_ext_phy_ctrl_2 = 0x00910091,
278 .emif_ddr_ext_phy_ctrl_3 = 0x00950095,
279 .emif_ddr_ext_phy_ctrl_4 = 0x009b009b,
280 .emif_ddr_ext_phy_ctrl_5 = 0x009e009e,
281 .emif_rd_wr_lvl_rmp_win = 0x00000000,
282 .emif_rd_wr_lvl_rmp_ctl = 0x80000000,
283 .emif_rd_wr_lvl_ctl = 0x00000000,
284 .emif_rd_wr_exec_thresh = 0x00000305
285};
286
Lokesh Vutlacbd70db2017-12-29 11:47:54 +0530287static const struct emif_regs am574x_emif1_ddr3_666mhz_emif_ecc_regs = {
288 .sdram_config_init = 0x61863332,
289 .sdram_config = 0x61863332,
290 .sdram_config2 = 0x08000000,
291 .ref_ctrl = 0x0000514d,
292 .ref_ctrl_final = 0x0000144a,
293 .sdram_tim1 = 0xd333887c,
294 .sdram_tim2 = 0x30b37fe3,
295 .sdram_tim3 = 0x409f8ad8,
296 .read_idle_ctrl = 0x00050000,
297 .zq_config = 0x5007190b,
298 .temp_alert_config = 0x00000000,
299 .emif_ddr_phy_ctlr_1_init = 0x0024400f,
300 .emif_ddr_phy_ctlr_1 = 0x0e24400f,
301 .emif_ddr_ext_phy_ctrl_1 = 0x10040100,
302 .emif_ddr_ext_phy_ctrl_2 = 0x00910091,
303 .emif_ddr_ext_phy_ctrl_3 = 0x00950095,
304 .emif_ddr_ext_phy_ctrl_4 = 0x009b009b,
305 .emif_ddr_ext_phy_ctrl_5 = 0x009e009e,
306 .emif_rd_wr_lvl_rmp_win = 0x00000000,
307 .emif_rd_wr_lvl_rmp_ctl = 0x80000000,
308 .emif_rd_wr_lvl_ctl = 0x00000000,
309 .emif_rd_wr_exec_thresh = 0x00000305,
310 .emif_ecc_ctrl_reg = 0xD0000001,
311 .emif_ecc_address_range_1 = 0x3FFF0000,
312 .emif_ecc_address_range_2 = 0x00000000
313};
314
Felipe Balbi4750eb62014-11-10 14:02:44 -0600315void emif_get_reg_dump(u32 emif_nr, const struct emif_regs **regs)
316{
317 switch (emif_nr) {
318 case 1:
Steve Kipisz81c46742017-08-22 13:52:58 +0530319 if (board_is_am571x_idk())
320 *regs = &am571x_emif1_ddr3_666mhz_emif_regs;
Lokesh Vutlacbd70db2017-12-29 11:47:54 +0530321 else if (board_is_am574x_idk())
322 *regs = &am574x_emif1_ddr3_666mhz_emif_ecc_regs;
Steve Kipisz81c46742017-08-22 13:52:58 +0530323 else
324 *regs = &beagle_x15_emif1_ddr3_532mhz_emif_regs;
Felipe Balbi4750eb62014-11-10 14:02:44 -0600325 break;
326 case 2:
Lokesh Vutlacbd70db2017-12-29 11:47:54 +0530327 if (board_is_am574x_idk())
328 *regs = &am571x_emif1_ddr3_666mhz_emif_regs;
329 else
330 *regs = &beagle_x15_emif2_ddr3_532mhz_emif_regs;
Felipe Balbi4750eb62014-11-10 14:02:44 -0600331 break;
332 }
333}
334
335void emif_get_ext_phy_ctrl_const_regs(u32 emif_nr, const u32 **regs, u32 *size)
336{
337 switch (emif_nr) {
338 case 1:
339 *regs = beagle_x15_emif1_ddr3_ext_phy_ctrl_const_regs;
340 *size = ARRAY_SIZE(beagle_x15_emif1_ddr3_ext_phy_ctrl_const_regs);
341 break;
342 case 2:
343 *regs = beagle_x15_emif2_ddr3_ext_phy_ctrl_const_regs;
344 *size = ARRAY_SIZE(beagle_x15_emif2_ddr3_ext_phy_ctrl_const_regs);
345 break;
346 }
347}
348
349struct vcores_data beagle_x15_volts = {
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530350 .mpu.value[OPP_NOM] = VDD_MPU_DRA7_NOM,
351 .mpu.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_MPU_NOM,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600352 .mpu.efuse.reg_bits = DRA752_EFUSE_REGBITS,
353 .mpu.addr = TPS659038_REG_ADDR_SMPS12,
354 .mpu.pmic = &tps659038,
Keerthy66dd8062016-05-24 11:45:07 +0530355 .mpu.abb_tx_done_mask = OMAP_ABB_MPU_TXDONE_MASK,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600356
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530357 .eve.value[OPP_NOM] = VDD_EVE_DRA7_NOM,
358 .eve.value[OPP_OD] = VDD_EVE_DRA7_OD,
359 .eve.value[OPP_HIGH] = VDD_EVE_DRA7_HIGH,
360 .eve.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_DSPEVE_NOM,
361 .eve.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_DSPEVE_OD,
362 .eve.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_DSPEVE_HIGH,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600363 .eve.efuse.reg_bits = DRA752_EFUSE_REGBITS,
364 .eve.addr = TPS659038_REG_ADDR_SMPS45,
365 .eve.pmic = &tps659038,
Nishanth Menon59b92af2016-04-21 14:34:25 -0500366 .eve.abb_tx_done_mask = OMAP_ABB_EVE_TXDONE_MASK,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600367
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530368 .gpu.value[OPP_NOM] = VDD_GPU_DRA7_NOM,
369 .gpu.value[OPP_OD] = VDD_GPU_DRA7_OD,
370 .gpu.value[OPP_HIGH] = VDD_GPU_DRA7_HIGH,
371 .gpu.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_GPU_NOM,
372 .gpu.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_GPU_OD,
373 .gpu.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_GPU_HIGH,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600374 .gpu.efuse.reg_bits = DRA752_EFUSE_REGBITS,
375 .gpu.addr = TPS659038_REG_ADDR_SMPS45,
376 .gpu.pmic = &tps659038,
Nishanth Menon59b92af2016-04-21 14:34:25 -0500377 .gpu.abb_tx_done_mask = OMAP_ABB_GPU_TXDONE_MASK,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600378
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530379 .core.value[OPP_NOM] = VDD_CORE_DRA7_NOM,
380 .core.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_CORE_NOM,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600381 .core.efuse.reg_bits = DRA752_EFUSE_REGBITS,
382 .core.addr = TPS659038_REG_ADDR_SMPS6,
383 .core.pmic = &tps659038,
384
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530385 .iva.value[OPP_NOM] = VDD_IVA_DRA7_NOM,
386 .iva.value[OPP_OD] = VDD_IVA_DRA7_OD,
387 .iva.value[OPP_HIGH] = VDD_IVA_DRA7_HIGH,
388 .iva.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_IVA_NOM,
389 .iva.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_IVA_OD,
390 .iva.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_IVA_HIGH,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600391 .iva.efuse.reg_bits = DRA752_EFUSE_REGBITS,
392 .iva.addr = TPS659038_REG_ADDR_SMPS45,
393 .iva.pmic = &tps659038,
Nishanth Menon59b92af2016-04-21 14:34:25 -0500394 .iva.abb_tx_done_mask = OMAP_ABB_IVA_TXDONE_MASK,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600395};
396
Keerthy152e9932016-05-24 11:45:06 +0530397struct vcores_data am572x_idk_volts = {
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530398 .mpu.value[OPP_NOM] = VDD_MPU_DRA7_NOM,
399 .mpu.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_MPU_NOM,
Keerthy152e9932016-05-24 11:45:06 +0530400 .mpu.efuse.reg_bits = DRA752_EFUSE_REGBITS,
401 .mpu.addr = TPS659038_REG_ADDR_SMPS12,
402 .mpu.pmic = &tps659038,
403 .mpu.abb_tx_done_mask = OMAP_ABB_MPU_TXDONE_MASK,
404
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530405 .eve.value[OPP_NOM] = VDD_EVE_DRA7_NOM,
406 .eve.value[OPP_OD] = VDD_EVE_DRA7_OD,
407 .eve.value[OPP_HIGH] = VDD_EVE_DRA7_HIGH,
408 .eve.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_DSPEVE_NOM,
409 .eve.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_DSPEVE_OD,
410 .eve.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_DSPEVE_HIGH,
Keerthy152e9932016-05-24 11:45:06 +0530411 .eve.efuse.reg_bits = DRA752_EFUSE_REGBITS,
412 .eve.addr = TPS659038_REG_ADDR_SMPS45,
413 .eve.pmic = &tps659038,
414 .eve.abb_tx_done_mask = OMAP_ABB_EVE_TXDONE_MASK,
415
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530416 .gpu.value[OPP_NOM] = VDD_GPU_DRA7_NOM,
417 .gpu.value[OPP_OD] = VDD_GPU_DRA7_OD,
418 .gpu.value[OPP_HIGH] = VDD_GPU_DRA7_HIGH,
419 .gpu.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_GPU_NOM,
420 .gpu.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_GPU_OD,
421 .gpu.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_GPU_HIGH,
Keerthy152e9932016-05-24 11:45:06 +0530422 .gpu.efuse.reg_bits = DRA752_EFUSE_REGBITS,
423 .gpu.addr = TPS659038_REG_ADDR_SMPS6,
424 .gpu.pmic = &tps659038,
425 .gpu.abb_tx_done_mask = OMAP_ABB_GPU_TXDONE_MASK,
426
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530427 .core.value[OPP_NOM] = VDD_CORE_DRA7_NOM,
428 .core.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_CORE_NOM,
Keerthy152e9932016-05-24 11:45:06 +0530429 .core.efuse.reg_bits = DRA752_EFUSE_REGBITS,
430 .core.addr = TPS659038_REG_ADDR_SMPS7,
431 .core.pmic = &tps659038,
432
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530433 .iva.value[OPP_NOM] = VDD_IVA_DRA7_NOM,
434 .iva.value[OPP_OD] = VDD_IVA_DRA7_OD,
435 .iva.value[OPP_HIGH] = VDD_IVA_DRA7_HIGH,
436 .iva.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_IVA_NOM,
437 .iva.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_IVA_OD,
438 .iva.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_IVA_HIGH,
Keerthy152e9932016-05-24 11:45:06 +0530439 .iva.efuse.reg_bits = DRA752_EFUSE_REGBITS,
440 .iva.addr = TPS659038_REG_ADDR_SMPS8,
441 .iva.pmic = &tps659038,
442 .iva.abb_tx_done_mask = OMAP_ABB_IVA_TXDONE_MASK,
443};
444
Keerthy9cc2aee2017-05-25 15:37:34 +0530445struct vcores_data am571x_idk_volts = {
446 .mpu.value[OPP_NOM] = VDD_MPU_DRA7_NOM,
447 .mpu.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_MPU_NOM,
448 .mpu.efuse.reg_bits = DRA752_EFUSE_REGBITS,
449 .mpu.addr = TPS659038_REG_ADDR_SMPS12,
450 .mpu.pmic = &tps659038,
451 .mpu.abb_tx_done_mask = OMAP_ABB_MPU_TXDONE_MASK,
452
453 .eve.value[OPP_NOM] = VDD_EVE_DRA7_NOM,
454 .eve.value[OPP_OD] = VDD_EVE_DRA7_OD,
455 .eve.value[OPP_HIGH] = VDD_EVE_DRA7_HIGH,
456 .eve.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_DSPEVE_NOM,
457 .eve.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_DSPEVE_OD,
458 .eve.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_DSPEVE_HIGH,
459 .eve.efuse.reg_bits = DRA752_EFUSE_REGBITS,
460 .eve.addr = TPS659038_REG_ADDR_SMPS45,
461 .eve.pmic = &tps659038,
462 .eve.abb_tx_done_mask = OMAP_ABB_EVE_TXDONE_MASK,
463
464 .gpu.value[OPP_NOM] = VDD_GPU_DRA7_NOM,
465 .gpu.value[OPP_OD] = VDD_GPU_DRA7_OD,
466 .gpu.value[OPP_HIGH] = VDD_GPU_DRA7_HIGH,
467 .gpu.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_GPU_NOM,
468 .gpu.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_GPU_OD,
469 .gpu.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_GPU_HIGH,
470 .gpu.efuse.reg_bits = DRA752_EFUSE_REGBITS,
471 .gpu.addr = TPS659038_REG_ADDR_SMPS6,
472 .gpu.pmic = &tps659038,
473 .gpu.abb_tx_done_mask = OMAP_ABB_GPU_TXDONE_MASK,
474
475 .core.value[OPP_NOM] = VDD_CORE_DRA7_NOM,
476 .core.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_CORE_NOM,
477 .core.efuse.reg_bits = DRA752_EFUSE_REGBITS,
478 .core.addr = TPS659038_REG_ADDR_SMPS7,
479 .core.pmic = &tps659038,
480
481 .iva.value[OPP_NOM] = VDD_IVA_DRA7_NOM,
482 .iva.value[OPP_OD] = VDD_IVA_DRA7_OD,
483 .iva.value[OPP_HIGH] = VDD_IVA_DRA7_HIGH,
484 .iva.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_IVA_NOM,
485 .iva.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_IVA_OD,
486 .iva.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_IVA_HIGH,
487 .iva.efuse.reg_bits = DRA752_EFUSE_REGBITS,
488 .iva.addr = TPS659038_REG_ADDR_SMPS45,
489 .iva.pmic = &tps659038,
490 .iva.abb_tx_done_mask = OMAP_ABB_IVA_TXDONE_MASK,
491};
492
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530493int get_voltrail_opp(int rail_offset)
494{
495 int opp;
496
497 switch (rail_offset) {
498 case VOLT_MPU:
499 opp = DRA7_MPU_OPP;
500 break;
501 case VOLT_CORE:
502 opp = DRA7_CORE_OPP;
503 break;
504 case VOLT_GPU:
505 opp = DRA7_GPU_OPP;
506 break;
507 case VOLT_EVE:
508 opp = DRA7_DSPEVE_OPP;
509 break;
510 case VOLT_IVA:
511 opp = DRA7_IVA_OPP;
512 break;
513 default:
514 opp = OPP_NOM;
515 }
516
517 return opp;
518}
519
520
Kipisz, Steven161f1382016-02-24 12:30:58 -0600521#ifdef CONFIG_SPL_BUILD
522/* No env to setup for SPL */
523static inline void setup_board_eeprom_env(void) { }
524
525/* Override function to read eeprom information */
526void do_board_detect(void)
527{
528 int rc;
529
530 rc = ti_i2c_eeprom_am_get(CONFIG_EEPROM_BUS_ADDRESS,
531 CONFIG_EEPROM_CHIP_ADDRESS);
532 if (rc)
533 printf("ti_i2c_eeprom_init failed %d\n", rc);
Caleb Robey0dfcc932020-01-02 08:17:25 -0600534
535#ifdef CONFIG_SUPPORT_EMMC_BOOT
536 rc = board_bootmode_has_emmc();
537 if (!rc)
538 rc = ti_emmc_boardid_get();
539 if (rc)
540 printf("ti_emmc_boardid_get failed %d\n", rc);
541#endif
Kipisz, Steven161f1382016-02-24 12:30:58 -0600542}
543
544#else /* CONFIG_SPL_BUILD */
545
546/* Override function to read eeprom information: actual i2c read done by SPL*/
547void do_board_detect(void)
548{
549 char *bname = NULL;
550 int rc;
551
552 rc = ti_i2c_eeprom_am_get(CONFIG_EEPROM_BUS_ADDRESS,
553 CONFIG_EEPROM_CHIP_ADDRESS);
554 if (rc)
555 printf("ti_i2c_eeprom_init failed %d\n", rc);
556
Caleb Robey0dfcc932020-01-02 08:17:25 -0600557#ifdef CONFIG_SUPPORT_EMMC_BOOT
558 rc = board_bootmode_has_emmc();
559 if (!rc)
560 rc = ti_emmc_boardid_get();
561 if (rc)
562 printf("ti_emmc_boardid_get failed %d\n", rc);
563#endif
564
Kipisz, Steven161f1382016-02-24 12:30:58 -0600565 if (board_is_x15())
566 bname = "BeagleBoard X15";
567 else if (board_is_am572x_evm())
568 bname = "AM572x EVM";
Lokesh Vutla374aea02017-12-29 11:47:52 +0530569 else if (board_is_am574x_idk())
570 bname = "AM574x IDK";
Steve Kipisz0ac8cea2016-04-08 17:01:29 -0500571 else if (board_is_am572x_idk())
572 bname = "AM572x IDK";
Steve Kipiszc95cddd2016-11-25 11:14:24 +0530573 else if (board_is_am571x_idk())
574 bname = "AM571x IDK";
Caleb Robey940d6372020-01-02 08:17:27 -0600575 else if (board_is_bbai())
576 bname = "BeagleBone AI";
Kipisz, Steven161f1382016-02-24 12:30:58 -0600577
578 if (bname)
579 snprintf(sysinfo.board_string, SYSINFO_BOARD_NAME_MAX_LEN,
580 "Board: %s REV %s\n", bname, board_ti_get_rev());
581}
582
583static void setup_board_eeprom_env(void)
584{
585 char *name = "beagle_x15";
586 int rc;
587
588 rc = ti_i2c_eeprom_am_get(CONFIG_EEPROM_BUS_ADDRESS,
589 CONFIG_EEPROM_CHIP_ADDRESS);
590 if (rc)
591 goto invalid_eeprom;
592
Nishanth Menona2aea1c2016-11-25 11:14:19 +0530593 if (board_is_x15()) {
Lokesh Vutla638e1c02016-11-25 11:14:20 +0530594 if (board_is_x15_revb1())
595 name = "beagle_x15_revb1";
Lokesh Vutla816178b2017-07-16 19:59:19 +0530596 else if (board_is_x15_revc())
597 name = "beagle_x15_revc";
Lokesh Vutla638e1c02016-11-25 11:14:20 +0530598 else
599 name = "beagle_x15";
Nishanth Menona2aea1c2016-11-25 11:14:19 +0530600 } else if (board_is_am572x_evm()) {
601 if (board_is_am572x_evm_reva3())
602 name = "am57xx_evm_reva3";
603 else
604 name = "am57xx_evm";
Lokesh Vutla374aea02017-12-29 11:47:52 +0530605 } else if (board_is_am574x_idk()) {
606 name = "am574x_idk";
Nishanth Menona2aea1c2016-11-25 11:14:19 +0530607 } else if (board_is_am572x_idk()) {
Steve Kipisz0ac8cea2016-04-08 17:01:29 -0500608 name = "am572x_idk";
Steve Kipiszc95cddd2016-11-25 11:14:24 +0530609 } else if (board_is_am571x_idk()) {
610 name = "am571x_idk";
Caleb Robey940d6372020-01-02 08:17:27 -0600611 } else if (board_is_bbai()) {
612 name = "am5729_beagleboneai";
Nishanth Menona2aea1c2016-11-25 11:14:19 +0530613 } else {
Kipisz, Steven161f1382016-02-24 12:30:58 -0600614 printf("Unidentified board claims %s in eeprom header\n",
615 board_ti_get_name());
Nishanth Menona2aea1c2016-11-25 11:14:19 +0530616 }
Kipisz, Steven161f1382016-02-24 12:30:58 -0600617
618invalid_eeprom:
619 set_board_info_env(name);
620}
621
622#endif /* CONFIG_SPL_BUILD */
623
Keerthy152e9932016-05-24 11:45:06 +0530624void vcores_init(void)
625{
Lokesh Vutla6e9635c2017-12-29 11:47:53 +0530626 if (board_is_am572x_idk() || board_is_am574x_idk())
Keerthy152e9932016-05-24 11:45:06 +0530627 *omap_vcores = &am572x_idk_volts;
Keerthy9cc2aee2017-05-25 15:37:34 +0530628 else if (board_is_am571x_idk())
629 *omap_vcores = &am571x_idk_volts;
Keerthy152e9932016-05-24 11:45:06 +0530630 else
631 *omap_vcores = &beagle_x15_volts;
632}
633
Felipe Balbi4750eb62014-11-10 14:02:44 -0600634void hw_data_init(void)
635{
636 *prcm = &dra7xx_prcm;
Steve Kipisz81c46742017-08-22 13:52:58 +0530637 if (is_dra72x())
638 *dplls_data = &dra72x_dplls;
Lokesh Vutla6e9635c2017-12-29 11:47:53 +0530639 else if (is_dra76x())
640 *dplls_data = &dra76x_dplls;
Steve Kipisz81c46742017-08-22 13:52:58 +0530641 else
642 *dplls_data = &dra7xx_dplls;
Felipe Balbi4750eb62014-11-10 14:02:44 -0600643 *ctrl = &dra7xx_ctrl;
644}
645
Roger Quadros26130592017-03-13 15:04:28 +0200646bool am571x_idk_needs_lcd(void)
647{
648 bool needs_lcd;
649
650 gpio_request(GPIO_ETH_LCD, "nLCD_Detect");
651 if (gpio_get_value(GPIO_ETH_LCD))
652 needs_lcd = false;
653 else
654 needs_lcd = true;
655
656 gpio_free(GPIO_ETH_LCD);
657
658 return needs_lcd;
659}
660
Felipe Balbi4750eb62014-11-10 14:02:44 -0600661int board_init(void)
662{
663 gpmc_init();
664 gd->bd->bi_boot_params = (CONFIG_SYS_SDRAM_BASE + 0x100);
665
666 return 0;
667}
668
Nishanth Menond0f399c2017-03-13 15:04:30 +0200669void am57x_idk_lcd_detect(void)
Felipe Balbi4750eb62014-11-10 14:02:44 -0600670{
Nishanth Menond0f399c2017-03-13 15:04:30 +0200671 int r = -ENODEV;
672 char *idk_lcd = "no";
Jean-Jacques Hiblot184ec9a2018-12-07 14:50:50 +0100673 struct udevice *dev;
Nishanth Menond0f399c2017-03-13 15:04:30 +0200674
675 /* Only valid for IDKs */
Luca Ceresoli93f6bc22020-05-21 15:06:25 +0200676 if (!board_is_ti_idk())
Nishanth Menond0f399c2017-03-13 15:04:30 +0200677 return;
678
679 /* Only AM571x IDK has gpio control detect.. so check that */
680 if (board_is_am571x_idk() && !am571x_idk_needs_lcd())
681 goto out;
682
Jean-Jacques Hiblot52a51512018-12-07 14:50:49 +0100683 r = i2c_get_chip_for_busnum(OSD_TS_FT_BUS_ADDRESS,
684 OSD_TS_FT_CHIP_ADDRESS, 1, &dev);
Nishanth Menond0f399c2017-03-13 15:04:30 +0200685 if (r) {
Jean-Jacques Hiblot52a51512018-12-07 14:50:49 +0100686 printf("%s: Failed to get I2C device %d/%d (ret %d)\n",
687 __func__, OSD_TS_FT_BUS_ADDRESS, OSD_TS_FT_CHIP_ADDRESS,
688 r);
Nishanth Menond0f399c2017-03-13 15:04:30 +0200689 /* AM572x IDK has no explicit settings for optional LCD kit */
Jean-Jacques Hiblot52a51512018-12-07 14:50:49 +0100690 if (board_is_am571x_idk())
Nishanth Menond0f399c2017-03-13 15:04:30 +0200691 printf("%s: Touch screen detect failed: %d!\n",
692 __func__, r);
Nishanth Menond0f399c2017-03-13 15:04:30 +0200693 goto out;
694 }
695
696 /* Read FT ID */
Jean-Jacques Hiblot52a51512018-12-07 14:50:49 +0100697 r = dm_i2c_reg_read(dev, OSD_TS_FT_REG_ID);
698 if (r < 0) {
Nishanth Menond0f399c2017-03-13 15:04:30 +0200699 printf("%s: Touch screen ID read %d:0x%02x[0x%02x] failed:%d\n",
700 __func__, OSD_TS_FT_BUS_ADDRESS, OSD_TS_FT_CHIP_ADDRESS,
701 OSD_TS_FT_REG_ID, r);
702 goto out;
703 }
704
Jean-Jacques Hiblot184ec9a2018-12-07 14:50:50 +0100705 switch (r) {
Nishanth Menond0f399c2017-03-13 15:04:30 +0200706 case OSD_TS_FT_ID_5606:
707 idk_lcd = "osd101t2045";
708 break;
709 case OSD_TS_FT_ID_5x46:
710 idk_lcd = "osd101t2587";
711 break;
712 default:
713 printf("%s: Unidentifed Touch screen ID 0x%02x\n",
Jean-Jacques Hiblot184ec9a2018-12-07 14:50:50 +0100714 __func__, r);
Nishanth Menond0f399c2017-03-13 15:04:30 +0200715 /* we will let default be "no lcd" */
716 }
717out:
Simon Glass6a38e412017-08-03 12:22:09 -0600718 env_set("idk_lcd", idk_lcd);
Roger Quadros8835eee2020-02-10 11:59:24 +0200719
720 /*
721 * On AM571x_IDK, no Display with J51 set to LCD is considered as an
722 * invalid configuration and we prevent boot to get user attention.
723 */
724 if (board_is_am571x_idk() && am571x_idk_needs_lcd() &&
725 !strncmp(idk_lcd, "no", 2)) {
726 printf("%s: Invalid HW configuration: display not detected/supported but J51 is set. Remove J51 to boot without display.\n",
727 __func__);
728 hang();
729 }
730
Nishanth Menond0f399c2017-03-13 15:04:30 +0200731 return;
732}
Roger Quadros26130592017-03-13 15:04:28 +0200733
Vignesh R98c5f632018-11-29 10:57:42 +0100734#if CONFIG_IS_ENABLED(DM_USB) && CONFIG_IS_ENABLED(OF_CONTROL)
735static int device_okay(const char *path)
736{
737 int node;
738
739 node = fdt_path_offset(gd->fdt_blob, path);
740 if (node < 0)
741 return 0;
742
743 return fdtdec_get_is_enabled(gd->fdt_blob, node);
744}
745#endif
746
Nishanth Menond0f399c2017-03-13 15:04:30 +0200747int board_late_init(void)
748{
Kipisz, Steven161f1382016-02-24 12:30:58 -0600749 setup_board_eeprom_env();
Keerthyee85ebe2016-11-30 15:02:53 +0530750 u8 val;
Tero Kristodfbc6b82019-09-27 19:14:27 +0300751 struct udevice *dev;
Kipisz, Steven161f1382016-02-24 12:30:58 -0600752
Felipe Balbi4750eb62014-11-10 14:02:44 -0600753 /*
754 * DEV_CTRL.DEV_ON = 1 please - else palmas switches off in 8 seconds
755 * This is the POWERHOLD-in-Low behavior.
756 */
757 palmas_i2c_write_u8(TPS65903X_CHIP_P1, 0xA0, 0x1);
Lokesh Vutla2c47e8c2016-11-29 11:58:02 +0530758
759 /*
760 * Default FIT boot on HS devices. Non FIT images are not allowed
761 * on HS devices.
762 */
763 if (get_device_type() == HS_DEVICE)
Simon Glass6a38e412017-08-03 12:22:09 -0600764 env_set("boot_fit", "1");
Lokesh Vutla2c47e8c2016-11-29 11:58:02 +0530765
Keerthyee85ebe2016-11-30 15:02:53 +0530766 /*
767 * Set the GPIO7 Pad to POWERHOLD. This has higher priority
768 * over DEV_CTRL.DEV_ON bit. This can be reset in case of
769 * PMIC Power off. So to be on the safer side set it back
770 * to POWERHOLD mode irrespective of the current state.
771 */
772 palmas_i2c_read_u8(TPS65903X_CHIP_P1, TPS65903X_PRIMARY_SECONDARY_PAD2,
773 &val);
774 val = val | TPS65903X_PAD2_POWERHOLD_MASK;
775 palmas_i2c_write_u8(TPS65903X_CHIP_P1, TPS65903X_PRIMARY_SECONDARY_PAD2,
776 val);
777
Semen Protsenko4b0721f2017-02-13 19:09:37 +0200778 omap_die_id_serial();
Semen Protsenkob72dccd2017-05-22 19:16:41 +0300779 omap_set_fastboot_vars();
Semen Protsenko4b0721f2017-02-13 19:09:37 +0200780
Nishanth Menond0f399c2017-03-13 15:04:30 +0200781 am57x_idk_lcd_detect();
Roger Quadros26130592017-03-13 15:04:28 +0200782
Tero Kristodfbc6b82019-09-27 19:14:27 +0300783 /* Just probe the potentially supported cdce913 device */
784 uclass_get_device(UCLASS_CLK, 0, &dev);
785
Caleb Robey940d6372020-01-02 08:17:27 -0600786 if (board_is_bbai())
787 env_set("console", "ttyS0,115200n8");
788
Roger Quadros26130592017-03-13 15:04:28 +0200789#if !defined(CONFIG_SPL_BUILD)
790 board_ti_set_ethaddr(2);
791#endif
792
Vignesh R98c5f632018-11-29 10:57:42 +0100793#if CONFIG_IS_ENABLED(DM_USB) && CONFIG_IS_ENABLED(OF_CONTROL)
794 if (device_okay("/ocp/omap_dwc3_1@48880000"))
795 enable_usb_clocks(0);
796 if (device_okay("/ocp/omap_dwc3_2@488c0000"))
797 enable_usb_clocks(1);
798#endif
Felipe Balbi4750eb62014-11-10 14:02:44 -0600799 return 0;
800}
801
Paul Kocialkowskia00b1e52016-02-27 19:18:56 +0100802void set_muxconf_regs(void)
Felipe Balbi4750eb62014-11-10 14:02:44 -0600803{
804 do_set_mux32((*ctrl)->control_padconf_core_base,
Lokesh Vutlac3d39f92015-06-04 16:42:41 +0530805 early_padconf, ARRAY_SIZE(early_padconf));
Caleb Robey0dfcc932020-01-02 08:17:25 -0600806
807#ifdef CONFIG_SUPPORT_EMMC_BOOT
808 do_set_mux32((*ctrl)->control_padconf_core_base,
809 emmc_padconf, ARRAY_SIZE(emmc_padconf));
810#endif
Felipe Balbi4750eb62014-11-10 14:02:44 -0600811}
812
Lokesh Vutlac3d39f92015-06-04 16:42:41 +0530813#ifdef CONFIG_IODELAY_RECALIBRATION
814void recalibrate_iodelay(void)
815{
Steve Kipisz0ac8cea2016-04-08 17:01:29 -0500816 const struct pad_conf_entry *pconf;
Lokesh Vutla3cb4c622017-06-05 14:48:16 +0530817 const struct iodelay_cfg_entry *iod, *delta_iod;
818 int pconf_sz, iod_sz, delta_iod_sz = 0;
Nishanth Menon8e3212e2016-11-25 11:14:22 +0530819 int ret;
Steve Kipisz0ac8cea2016-04-08 17:01:29 -0500820
Lokesh Vutla1e3425c2017-12-29 11:47:55 +0530821 if (board_is_am572x_idk()) {
Steve Kipisz0ac8cea2016-04-08 17:01:29 -0500822 pconf = core_padconf_array_essential_am572x_idk;
823 pconf_sz = ARRAY_SIZE(core_padconf_array_essential_am572x_idk);
824 iod = iodelay_cfg_array_am572x_idk;
825 iod_sz = ARRAY_SIZE(iodelay_cfg_array_am572x_idk);
Lokesh Vutla1e3425c2017-12-29 11:47:55 +0530826 } else if (board_is_am574x_idk()) {
827 pconf = core_padconf_array_essential_am574x_idk;
828 pconf_sz = ARRAY_SIZE(core_padconf_array_essential_am574x_idk);
829 iod = iodelay_cfg_array_am574x_idk;
830 iod_sz = ARRAY_SIZE(iodelay_cfg_array_am574x_idk);
Steve Kipiszc95cddd2016-11-25 11:14:24 +0530831 } else if (board_is_am571x_idk()) {
832 pconf = core_padconf_array_essential_am571x_idk;
833 pconf_sz = ARRAY_SIZE(core_padconf_array_essential_am571x_idk);
834 iod = iodelay_cfg_array_am571x_idk;
835 iod_sz = ARRAY_SIZE(iodelay_cfg_array_am571x_idk);
Caleb Robey940d6372020-01-02 08:17:27 -0600836 } else if (board_is_bbai()) {
837 pconf = core_padconf_array_essential_bbai;
838 pconf_sz = ARRAY_SIZE(core_padconf_array_essential_bbai);
839 iod = iodelay_cfg_array_bbai;
840 iod_sz = ARRAY_SIZE(iodelay_cfg_array_bbai);
Steve Kipisz0ac8cea2016-04-08 17:01:29 -0500841 } else {
842 /* Common for X15/GPEVM */
843 pconf = core_padconf_array_essential_x15;
844 pconf_sz = ARRAY_SIZE(core_padconf_array_essential_x15);
Nishanth Menon8e3212e2016-11-25 11:14:22 +0530845 /* There never was an SR1.0 X15.. So.. */
846 if (omap_revision() == DRA752_ES1_1) {
847 iod = iodelay_cfg_array_x15_sr1_1;
848 iod_sz = ARRAY_SIZE(iodelay_cfg_array_x15_sr1_1);
849 } else {
850 /* Since full production should switch to SR2.0 */
851 iod = iodelay_cfg_array_x15_sr2_0;
852 iod_sz = ARRAY_SIZE(iodelay_cfg_array_x15_sr2_0);
853 }
Steve Kipisz0ac8cea2016-04-08 17:01:29 -0500854 }
855
Nishanth Menon8e3212e2016-11-25 11:14:22 +0530856 /* Setup I/O isolation */
857 ret = __recalibrate_iodelay_start();
858 if (ret)
859 goto err;
860
861 /* Do the muxing here */
862 do_set_mux32((*ctrl)->control_padconf_core_base, pconf, pconf_sz);
863
864 /* Now do the weird minor deltas that should be safe */
865 if (board_is_x15() || board_is_am572x_evm()) {
Lokesh Vutla816178b2017-07-16 19:59:19 +0530866 if (board_is_x15_revb1() || board_is_am572x_evm_reva3() ||
867 board_is_x15_revc()) {
Nishanth Menon8e3212e2016-11-25 11:14:22 +0530868 pconf = core_padconf_array_delta_x15_sr2_0;
869 pconf_sz = ARRAY_SIZE(core_padconf_array_delta_x15_sr2_0);
870 } else {
871 pconf = core_padconf_array_delta_x15_sr1_1;
872 pconf_sz = ARRAY_SIZE(core_padconf_array_delta_x15_sr1_1);
873 }
874 do_set_mux32((*ctrl)->control_padconf_core_base, pconf, pconf_sz);
875 }
876
Roger Quadros26130592017-03-13 15:04:28 +0200877 if (board_is_am571x_idk()) {
878 if (am571x_idk_needs_lcd()) {
879 pconf = core_padconf_array_vout_am571x_idk;
880 pconf_sz = ARRAY_SIZE(core_padconf_array_vout_am571x_idk);
Lokesh Vutla3cb4c622017-06-05 14:48:16 +0530881 delta_iod = iodelay_cfg_array_am571x_idk_4port;
882 delta_iod_sz = ARRAY_SIZE(iodelay_cfg_array_am571x_idk_4port);
883
Roger Quadros26130592017-03-13 15:04:28 +0200884 } else {
885 pconf = core_padconf_array_icss1eth_am571x_idk;
886 pconf_sz = ARRAY_SIZE(core_padconf_array_icss1eth_am571x_idk);
887 }
888 do_set_mux32((*ctrl)->control_padconf_core_base, pconf, pconf_sz);
889 }
890
Nishanth Menon8e3212e2016-11-25 11:14:22 +0530891 /* Setup IOdelay configuration */
892 ret = do_set_iodelay((*ctrl)->iodelay_config_base, iod, iod_sz);
Lokesh Vutla3cb4c622017-06-05 14:48:16 +0530893 if (delta_iod_sz)
894 ret = do_set_iodelay((*ctrl)->iodelay_config_base, delta_iod,
895 delta_iod_sz);
896
Nishanth Menon8e3212e2016-11-25 11:14:22 +0530897err:
898 /* Closeup.. remove isolation */
899 __recalibrate_iodelay_end(ret);
Lokesh Vutlac3d39f92015-06-04 16:42:41 +0530900}
901#endif
902
Masahiro Yamada0a780172017-05-09 20:31:39 +0900903#if defined(CONFIG_MMC)
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900904int board_mmc_init(struct bd_info *bis)
Felipe Balbi4750eb62014-11-10 14:02:44 -0600905{
906 omap_mmc_init(0, 0, 0, -1, -1);
907 omap_mmc_init(1, 0, 0, -1, -1);
908 return 0;
909}
Kishon Vijay Abraham I110ed012018-01-30 16:01:52 +0100910
911static const struct mmc_platform_fixups am57x_es1_1_mmc1_fixups = {
912 .hw_rev = "rev11",
913 .unsupported_caps = MMC_CAP(MMC_HS_200) |
914 MMC_CAP(UHS_SDR104),
915 .max_freq = 96000000,
916};
917
918static const struct mmc_platform_fixups am57x_es1_1_mmc23_fixups = {
919 .hw_rev = "rev11",
920 .unsupported_caps = MMC_CAP(MMC_HS_200) |
921 MMC_CAP(UHS_SDR104) |
922 MMC_CAP(UHS_SDR50),
923 .max_freq = 48000000,
924};
925
926const struct mmc_platform_fixups *platform_fixups_mmc(uint32_t addr)
927{
928 switch (omap_revision()) {
929 case DRA752_ES1_0:
930 case DRA752_ES1_1:
931 if (addr == OMAP_HSMMC1_BASE)
932 return &am57x_es1_1_mmc1_fixups;
933 else
934 return &am57x_es1_1_mmc23_fixups;
935 default:
936 return NULL;
937 }
938}
Felipe Balbi4750eb62014-11-10 14:02:44 -0600939#endif
940
941#if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_OS_BOOT)
942int spl_start_uboot(void)
943{
944 /* break into full u-boot on 'c' */
945 if (serial_tstc() && serial_getc() == 'c')
946 return 1;
947
948#ifdef CONFIG_SPL_ENV_SUPPORT
949 env_init();
Simon Glass17539572017-08-03 12:22:07 -0600950 env_load();
Simon Glass22c34c22017-08-03 12:22:13 -0600951 if (env_get_yesno("boot_os") != 1)
Felipe Balbi4750eb62014-11-10 14:02:44 -0600952 return 1;
953#endif
954
955 return 0;
956}
957#endif
958
959#ifdef CONFIG_DRIVER_TI_CPSW
960
961/* Delay value to add to calibrated value */
962#define RGMII0_TXCTL_DLY_VAL ((0x3 << 5) + 0x8)
963#define RGMII0_TXD0_DLY_VAL ((0x3 << 5) + 0x8)
964#define RGMII0_TXD1_DLY_VAL ((0x3 << 5) + 0x2)
965#define RGMII0_TXD2_DLY_VAL ((0x4 << 5) + 0x0)
966#define RGMII0_TXD3_DLY_VAL ((0x4 << 5) + 0x0)
967#define VIN2A_D13_DLY_VAL ((0x3 << 5) + 0x8)
968#define VIN2A_D17_DLY_VAL ((0x3 << 5) + 0x8)
969#define VIN2A_D16_DLY_VAL ((0x3 << 5) + 0x2)
970#define VIN2A_D15_DLY_VAL ((0x4 << 5) + 0x0)
971#define VIN2A_D14_DLY_VAL ((0x4 << 5) + 0x0)
972
973static void cpsw_control(int enabled)
974{
975 /* VTP can be added here */
976}
977
978static struct cpsw_slave_data cpsw_slaves[] = {
979 {
980 .slave_reg_ofs = 0x208,
981 .sliver_reg_ofs = 0xd80,
982 .phy_addr = 1,
983 },
984 {
985 .slave_reg_ofs = 0x308,
986 .sliver_reg_ofs = 0xdc0,
987 .phy_addr = 2,
988 },
989};
990
991static struct cpsw_platform_data cpsw_data = {
992 .mdio_base = CPSW_MDIO_BASE,
993 .cpsw_base = CPSW_BASE,
994 .mdio_div = 0xff,
995 .channels = 8,
996 .cpdma_reg_ofs = 0x800,
997 .slaves = 1,
998 .slave_data = cpsw_slaves,
999 .ale_reg_ofs = 0xd00,
1000 .ale_entries = 1024,
1001 .host_port_reg_ofs = 0x108,
1002 .hw_stats_reg_ofs = 0x900,
1003 .bd_ram_ofs = 0x2000,
1004 .mac_control = (1 << 5),
1005 .control = cpsw_control,
1006 .host_port_num = 0,
1007 .version = CPSW_CTRL_VERSION_2,
1008};
1009
Roger Quadros64217a22016-03-18 13:18:12 +02001010static u64 mac_to_u64(u8 mac[6])
1011{
1012 int i;
1013 u64 addr = 0;
1014
1015 for (i = 0; i < 6; i++) {
1016 addr <<= 8;
1017 addr |= mac[i];
1018 }
1019
1020 return addr;
1021}
1022
1023static void u64_to_mac(u64 addr, u8 mac[6])
1024{
1025 mac[5] = addr;
1026 mac[4] = addr >> 8;
1027 mac[3] = addr >> 16;
1028 mac[2] = addr >> 24;
1029 mac[1] = addr >> 32;
1030 mac[0] = addr >> 40;
1031}
1032
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +09001033int board_eth_init(struct bd_info *bis)
Felipe Balbi4750eb62014-11-10 14:02:44 -06001034{
1035 int ret;
1036 uint8_t mac_addr[6];
1037 uint32_t mac_hi, mac_lo;
1038 uint32_t ctrl_val;
Roger Quadros64217a22016-03-18 13:18:12 +02001039 int i;
1040 u64 mac1, mac2;
1041 u8 mac_addr1[6], mac_addr2[6];
1042 int num_macs;
Felipe Balbi4750eb62014-11-10 14:02:44 -06001043
1044 /* try reading mac address from efuse */
1045 mac_lo = readl((*ctrl)->control_core_mac_id_0_lo);
1046 mac_hi = readl((*ctrl)->control_core_mac_id_0_hi);
1047 mac_addr[0] = (mac_hi & 0xFF0000) >> 16;
1048 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
1049 mac_addr[2] = mac_hi & 0xFF;
1050 mac_addr[3] = (mac_lo & 0xFF0000) >> 16;
1051 mac_addr[4] = (mac_lo & 0xFF00) >> 8;
1052 mac_addr[5] = mac_lo & 0xFF;
1053
Simon Glass64b723f2017-08-03 12:22:12 -06001054 if (!env_get("ethaddr")) {
Felipe Balbi4750eb62014-11-10 14:02:44 -06001055 printf("<ethaddr> not set. Validating first E-fuse MAC\n");
1056
Joe Hershberger8ecdbed2015-04-08 01:41:04 -05001057 if (is_valid_ethaddr(mac_addr))
Simon Glass8551d552017-08-03 12:22:11 -06001058 eth_env_set_enetaddr("ethaddr", mac_addr);
Felipe Balbi4750eb62014-11-10 14:02:44 -06001059 }
1060
1061 mac_lo = readl((*ctrl)->control_core_mac_id_1_lo);
1062 mac_hi = readl((*ctrl)->control_core_mac_id_1_hi);
1063 mac_addr[0] = (mac_hi & 0xFF0000) >> 16;
1064 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
1065 mac_addr[2] = mac_hi & 0xFF;
1066 mac_addr[3] = (mac_lo & 0xFF0000) >> 16;
1067 mac_addr[4] = (mac_lo & 0xFF00) >> 8;
1068 mac_addr[5] = mac_lo & 0xFF;
1069
Simon Glass64b723f2017-08-03 12:22:12 -06001070 if (!env_get("eth1addr")) {
Joe Hershberger8ecdbed2015-04-08 01:41:04 -05001071 if (is_valid_ethaddr(mac_addr))
Simon Glass8551d552017-08-03 12:22:11 -06001072 eth_env_set_enetaddr("eth1addr", mac_addr);
Felipe Balbi4750eb62014-11-10 14:02:44 -06001073 }
1074
1075 ctrl_val = readl((*ctrl)->control_core_control_io1) & (~0x33);
1076 ctrl_val |= 0x22;
1077 writel(ctrl_val, (*ctrl)->control_core_control_io1);
1078
Steve Kipiszc95cddd2016-11-25 11:14:24 +05301079 /* The phy address for the AM57xx IDK are different than x15 */
Lokesh Vutla6e9635c2017-12-29 11:47:53 +05301080 if (board_is_am572x_idk() || board_is_am571x_idk() ||
1081 board_is_am574x_idk()) {
Steve Kipisz0ac8cea2016-04-08 17:01:29 -05001082 cpsw_data.slave_data[0].phy_addr = 0;
1083 cpsw_data.slave_data[1].phy_addr = 1;
1084 }
1085
Felipe Balbi4750eb62014-11-10 14:02:44 -06001086 ret = cpsw_register(&cpsw_data);
1087 if (ret < 0)
1088 printf("Error %d registering CPSW switch\n", ret);
1089
Roger Quadros64217a22016-03-18 13:18:12 +02001090 /*
1091 * Export any Ethernet MAC addresses from EEPROM.
1092 * On AM57xx the 2 MAC addresses define the address range
1093 */
1094 board_ti_get_eth_mac_addr(0, mac_addr1);
1095 board_ti_get_eth_mac_addr(1, mac_addr2);
1096
1097 if (is_valid_ethaddr(mac_addr1) && is_valid_ethaddr(mac_addr2)) {
1098 mac1 = mac_to_u64(mac_addr1);
1099 mac2 = mac_to_u64(mac_addr2);
1100
1101 /* must contain an address range */
1102 num_macs = mac2 - mac1 + 1;
1103 /* <= 50 to protect against user programming error */
1104 if (num_macs > 0 && num_macs <= 50) {
1105 for (i = 0; i < num_macs; i++) {
1106 u64_to_mac(mac1 + i, mac_addr);
1107 if (is_valid_ethaddr(mac_addr)) {
Simon Glass8551d552017-08-03 12:22:11 -06001108 eth_env_set_enetaddr_by_index("eth",
1109 i + 2,
1110 mac_addr);
Roger Quadros64217a22016-03-18 13:18:12 +02001111 }
1112 }
1113 }
1114 }
1115
Felipe Balbi4750eb62014-11-10 14:02:44 -06001116 return ret;
1117}
1118#endif
Lokesh Vutla9f150672015-06-16 20:36:05 +05301119
1120#ifdef CONFIG_BOARD_EARLY_INIT_F
1121/* VTT regulator enable */
1122static inline void vtt_regulator_enable(void)
1123{
1124 if (omap_hw_init_context() == OMAP_INIT_CONTEXT_UBOOT_AFTER_SPL)
1125 return;
1126
1127 gpio_request(GPIO_DDR_VTT_EN, "ddr_vtt_en");
1128 gpio_direction_output(GPIO_DDR_VTT_EN, 1);
1129}
1130
1131int board_early_init_f(void)
1132{
1133 vtt_regulator_enable();
1134 return 0;
1135}
1136#endif
Daniel Allred7ceffb22016-05-19 19:10:54 -05001137
1138#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +09001139int ft_board_setup(void *blob, struct bd_info *bd)
Daniel Allred7ceffb22016-05-19 19:10:54 -05001140{
1141 ft_cpu_setup(blob, bd);
1142
1143 return 0;
1144}
1145#endif
Lokesh Vutla00bf8b22016-06-10 09:35:43 +05301146
1147#ifdef CONFIG_SPL_LOAD_FIT
1148int board_fit_config_name_match(const char *name)
1149{
Lokesh Vutla638e1c02016-11-25 11:14:20 +05301150 if (board_is_x15()) {
1151 if (board_is_x15_revb1()) {
1152 if (!strcmp(name, "am57xx-beagle-x15-revb1"))
1153 return 0;
Lokesh Vutlaf35589c2017-08-23 11:39:06 +05301154 } else if (board_is_x15_revc()) {
1155 if (!strcmp(name, "am57xx-beagle-x15-revc"))
1156 return 0;
Lokesh Vutla638e1c02016-11-25 11:14:20 +05301157 } else if (!strcmp(name, "am57xx-beagle-x15")) {
1158 return 0;
1159 }
1160 } else if (board_is_am572x_evm() &&
1161 !strcmp(name, "am57xx-beagle-x15")) {
Lokesh Vutla00bf8b22016-06-10 09:35:43 +05301162 return 0;
Lokesh Vutla638e1c02016-11-25 11:14:20 +05301163 } else if (board_is_am572x_idk() && !strcmp(name, "am572x-idk")) {
Schuyler Patton99519852016-06-10 09:35:45 +05301164 return 0;
Lokesh Vutla58a3c1b2017-12-29 11:47:57 +05301165 } else if (board_is_am574x_idk() && !strcmp(name, "am574x-idk")) {
1166 return 0;
Schuyler Pattonc665e272016-11-25 11:14:25 +05301167 } else if (board_is_am571x_idk() && !strcmp(name, "am571x-idk")) {
1168 return 0;
Caleb Robey940d6372020-01-02 08:17:27 -06001169 } else if (board_is_bbai() && !strcmp(name, "am5729-beagleboneai")) {
1170 return 0;
Lokesh Vutla638e1c02016-11-25 11:14:20 +05301171 }
1172
1173 return -1;
Lokesh Vutla00bf8b22016-06-10 09:35:43 +05301174}
1175#endif
Andreas Dannenberg5cf344b2016-06-27 09:19:22 -05001176
Andrew F. Davisd3555832019-02-11 08:00:08 -06001177#if CONFIG_IS_ENABLED(FASTBOOT) && !CONFIG_IS_ENABLED(ENV_IS_NOWHERE)
Roman Kovalivskyi1bb13422020-07-28 23:35:32 +03001178int fastboot_set_reboot_flag(enum fastboot_reboot_reason reason)
Andrew F. Davisd3555832019-02-11 08:00:08 -06001179{
Roman Kovalivskyi1bb13422020-07-28 23:35:32 +03001180 if (reason != FASTBOOT_REBOOT_REASON_BOOTLOADER)
1181 return -ENOTSUPP;
1182
Andrew F. Davisd3555832019-02-11 08:00:08 -06001183 printf("Setting reboot to fastboot flag ...\n");
1184 env_set("dofastboot", "1");
1185 env_save();
1186 return 0;
1187}
1188#endif
1189
Caleb Robey0dfcc932020-01-02 08:17:25 -06001190#ifdef CONFIG_SUPPORT_EMMC_BOOT
1191static int board_bootmode_has_emmc(void)
1192{
1193 /* Check that boot mode is same as BBAI */
1194 if (gd->arch.omap_boot_mode != 2)
1195 return -EIO;
1196
1197 return 0;
1198}
1199#endif
1200
Andreas Dannenberg5cf344b2016-06-27 09:19:22 -05001201#ifdef CONFIG_TI_SECURE_DEVICE
Lokesh Vutlab36dd3e2021-06-11 11:45:05 +03001202void board_fit_image_post_process(const void *fit, int node, void **p_image,
1203 size_t *p_size)
Andreas Dannenberg5cf344b2016-06-27 09:19:22 -05001204{
1205 secure_boot_verify_image(p_image, p_size);
1206}
Andrew F. Davis7d250622016-11-29 16:33:26 -06001207
1208void board_tee_image_process(ulong tee_image, size_t tee_size)
1209{
1210 secure_tee_install((u32)tee_image);
1211}
1212
1213U_BOOT_FIT_LOADABLE_HANDLER(IH_TYPE_TEE, board_tee_image_process);
Andreas Dannenberg5cf344b2016-06-27 09:19:22 -05001214#endif