blob: d70ab0c4d01c66a87e16dc1855ce702ecdcc5278 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Felipe Balbi4750eb62014-11-10 14:02:44 -06002/*
3 * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com
4 *
5 * Author: Felipe Balbi <balbi@ti.com>
6 *
7 * Based on board/ti/dra7xx/evm.c
Felipe Balbi4750eb62014-11-10 14:02:44 -06008 */
9
10#include <common.h>
Simon Glass79fd2142019-08-01 09:46:43 -060011#include <env.h>
Simon Glass3bbe70c2019-12-28 10:44:54 -070012#include <fdt_support.h>
Simon Glassa7b51302019-11-14 12:57:46 -070013#include <init.h>
Felipe Balbi4750eb62014-11-10 14:02:44 -060014#include <palmas.h>
15#include <sata.h>
Simon Glass36736182019-11-14 12:57:24 -070016#include <serial.h>
Felipe Balbi4750eb62014-11-10 14:02:44 -060017#include <usb.h>
Caleb Robey0dfcc932020-01-02 08:17:25 -060018#include <errno.h>
Felipe Balbi4750eb62014-11-10 14:02:44 -060019#include <asm/omap_common.h>
Andreas Dannenberg5cf344b2016-06-27 09:19:22 -050020#include <asm/omap_sec_common.h>
Felipe Balbi4750eb62014-11-10 14:02:44 -060021#include <asm/emif.h>
Lokesh Vutla9f150672015-06-16 20:36:05 +053022#include <asm/gpio.h>
23#include <asm/arch/gpio.h>
Felipe Balbi4750eb62014-11-10 14:02:44 -060024#include <asm/arch/clock.h>
Lokesh Vutlac3d39f92015-06-04 16:42:41 +053025#include <asm/arch/dra7xx_iodelay.h>
Felipe Balbi4750eb62014-11-10 14:02:44 -060026#include <asm/arch/sys_proto.h>
27#include <asm/arch/mmc_host_def.h>
28#include <asm/arch/sata.h>
29#include <asm/arch/gpio.h>
Kishon Vijay Abraham I5f19b2d2015-08-19 14:13:19 +053030#include <asm/arch/omap.h>
Kishon Vijay Abraham I5f19b2d2015-08-19 14:13:19 +053031#include <usb.h>
32#include <linux/usb/gadget.h>
33#include <dwc3-uboot.h>
34#include <dwc3-omap-uboot.h>
35#include <ti-usb-phy-uboot.h>
Kishon Vijay Abraham I110ed012018-01-30 16:01:52 +010036#include <mmc.h>
Tero Kristodfbc6b82019-09-27 19:14:27 +030037#include <dm/uclass.h>
Felipe Balbi4750eb62014-11-10 14:02:44 -060038
Kipisz, Steven161f1382016-02-24 12:30:58 -060039#include "../common/board_detect.h"
Felipe Balbi4750eb62014-11-10 14:02:44 -060040#include "mux_data.h"
41
Caleb Robey0dfcc932020-01-02 08:17:25 -060042#ifdef CONFIG_SUPPORT_EMMC_BOOT
43static int board_bootmode_has_emmc(void);
44#endif
45
Kipisz, Steven161f1382016-02-24 12:30:58 -060046#define board_is_x15() board_ti_is("BBRDX15_")
Lokesh Vutla638e1c02016-11-25 11:14:20 +053047#define board_is_x15_revb1() (board_ti_is("BBRDX15_") && \
Lokesh Vutlaab4f71e2017-07-16 19:59:18 +053048 !strncmp("B.10", board_ti_get_rev(), 3))
Lokesh Vutla816178b2017-07-16 19:59:19 +053049#define board_is_x15_revc() (board_ti_is("BBRDX15_") && \
50 !strncmp("C.00", board_ti_get_rev(), 3))
Kipisz, Steven161f1382016-02-24 12:30:58 -060051#define board_is_am572x_evm() board_ti_is("AM572PM_")
Nishanth Menona2aea1c2016-11-25 11:14:19 +053052#define board_is_am572x_evm_reva3() \
53 (board_ti_is("AM572PM_") && \
Lokesh Vutlaab4f71e2017-07-16 19:59:18 +053054 !strncmp("A.30", board_ti_get_rev(), 3))
Lokesh Vutla374aea02017-12-29 11:47:52 +053055#define board_is_am574x_idk() board_ti_is("AM574IDK")
Steve Kipisz0ac8cea2016-04-08 17:01:29 -050056#define board_is_am572x_idk() board_ti_is("AM572IDK")
Steve Kipiszc95cddd2016-11-25 11:14:24 +053057#define board_is_am571x_idk() board_ti_is("AM571IDK")
Caleb Robey940d6372020-01-02 08:17:27 -060058#define board_is_bbai() board_ti_is("BBONE-AI")
Kipisz, Steven161f1382016-02-24 12:30:58 -060059
Felipe Balbi4750eb62014-11-10 14:02:44 -060060#ifdef CONFIG_DRIVER_TI_CPSW
61#include <cpsw.h>
62#endif
63
64DECLARE_GLOBAL_DATA_PTR;
65
Roger Quadros26130592017-03-13 15:04:28 +020066#define GPIO_ETH_LCD GPIO_TO_PIN(2, 22)
Lokesh Vutla9f150672015-06-16 20:36:05 +053067/* GPIO 7_11 */
68#define GPIO_DDR_VTT_EN 203
69
Nishanth Menond0f399c2017-03-13 15:04:30 +020070/* Touch screen controller to identify the LCD */
71#define OSD_TS_FT_BUS_ADDRESS 0
72#define OSD_TS_FT_CHIP_ADDRESS 0x38
73#define OSD_TS_FT_REG_ID 0xA3
74/*
75 * Touchscreen IDs for various OSD panels
76 * Ref: http://www.osddisplays.com/TI/OSD101T2587-53TS_A.1.pdf
77 */
78/* Used on newer osd101t2587 Panels */
79#define OSD_TS_FT_ID_5x46 0x54
80/* Used on older osd101t2045 Panels */
81#define OSD_TS_FT_ID_5606 0x08
82
Kipisz, Steven161f1382016-02-24 12:30:58 -060083#define SYSINFO_BOARD_NAME_MAX_LEN 45
84
Keerthyee85ebe2016-11-30 15:02:53 +053085#define TPS65903X_PRIMARY_SECONDARY_PAD2 0xFB
86#define TPS65903X_PAD2_POWERHOLD_MASK 0x20
87
Felipe Balbi4750eb62014-11-10 14:02:44 -060088const struct omap_sysinfo sysinfo = {
Kipisz, Steven161f1382016-02-24 12:30:58 -060089 "Board: UNKNOWN(BeagleBoard X15?) REV UNKNOWN\n"
Felipe Balbi4750eb62014-11-10 14:02:44 -060090};
91
92static const struct dmm_lisa_map_regs beagle_x15_lisa_regs = {
93 .dmm_lisa_map_3 = 0x80740300,
94 .is_ma_present = 0x1
95};
96
Steve Kipiszc95cddd2016-11-25 11:14:24 +053097static const struct dmm_lisa_map_regs am571x_idk_lisa_regs = {
98 .dmm_lisa_map_3 = 0x80640100,
99 .is_ma_present = 0x1
100};
101
Lokesh Vutlacbd70db2017-12-29 11:47:54 +0530102static const struct dmm_lisa_map_regs am574x_idk_lisa_regs = {
103 .dmm_lisa_map_2 = 0xc0600200,
104 .dmm_lisa_map_3 = 0x80600100,
105 .is_ma_present = 0x1
106};
107
Caleb Robey940d6372020-01-02 08:17:27 -0600108static const struct dmm_lisa_map_regs bbai_lisa_regs = {
109 .dmm_lisa_map_3 = 0x80640100,
110 .is_ma_present = 0x1
111};
112
Felipe Balbi4750eb62014-11-10 14:02:44 -0600113void emif_get_dmm_regs(const struct dmm_lisa_map_regs **dmm_lisa_regs)
114{
Steve Kipiszc95cddd2016-11-25 11:14:24 +0530115 if (board_is_am571x_idk())
116 *dmm_lisa_regs = &am571x_idk_lisa_regs;
Lokesh Vutlacbd70db2017-12-29 11:47:54 +0530117 else if (board_is_am574x_idk())
118 *dmm_lisa_regs = &am574x_idk_lisa_regs;
Caleb Robey940d6372020-01-02 08:17:27 -0600119 else if (board_is_bbai())
120 *dmm_lisa_regs = &bbai_lisa_regs;
Steve Kipiszc95cddd2016-11-25 11:14:24 +0530121 else
122 *dmm_lisa_regs = &beagle_x15_lisa_regs;
Felipe Balbi4750eb62014-11-10 14:02:44 -0600123}
124
125static const struct emif_regs beagle_x15_emif1_ddr3_532mhz_emif_regs = {
Keerthy66dd8062016-05-24 11:45:07 +0530126 .sdram_config_init = 0x61851b32,
127 .sdram_config = 0x61851b32,
128 .sdram_config2 = 0x08000000,
129 .ref_ctrl = 0x000040F1,
130 .ref_ctrl_final = 0x00001035,
131 .sdram_tim1 = 0xcccf36ab,
132 .sdram_tim2 = 0x308f7fda,
133 .sdram_tim3 = 0x409f88a8,
134 .read_idle_ctrl = 0x00050000,
135 .zq_config = 0x5007190b,
136 .temp_alert_config = 0x00000000,
137 .emif_ddr_phy_ctlr_1_init = 0x0024400b,
138 .emif_ddr_phy_ctlr_1 = 0x0e24400b,
139 .emif_ddr_ext_phy_ctrl_1 = 0x10040100,
140 .emif_ddr_ext_phy_ctrl_2 = 0x00910091,
141 .emif_ddr_ext_phy_ctrl_3 = 0x00950095,
142 .emif_ddr_ext_phy_ctrl_4 = 0x009b009b,
143 .emif_ddr_ext_phy_ctrl_5 = 0x009e009e,
144 .emif_rd_wr_lvl_rmp_win = 0x00000000,
145 .emif_rd_wr_lvl_rmp_ctl = 0x80000000,
146 .emif_rd_wr_lvl_ctl = 0x00000000,
147 .emif_rd_wr_exec_thresh = 0x00000305
Felipe Balbi4750eb62014-11-10 14:02:44 -0600148};
149
Lokesh Vutla979d2c32015-06-03 14:43:21 +0530150/* Ext phy ctrl regs 1-35 */
Felipe Balbi4750eb62014-11-10 14:02:44 -0600151static const u32 beagle_x15_emif1_ddr3_ext_phy_ctrl_const_regs[] = {
Lokesh Vutla979d2c32015-06-03 14:43:21 +0530152 0x10040100,
Lokesh Vutla306b5972016-03-08 09:11:35 +0530153 0x00910091,
154 0x00950095,
155 0x009B009B,
156 0x009E009E,
157 0x00980098,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600158 0x00340034,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600159 0x00350035,
Lokesh Vutla306b5972016-03-08 09:11:35 +0530160 0x00340034,
161 0x00310031,
162 0x00340034,
163 0x007F007F,
164 0x007F007F,
165 0x007F007F,
166 0x007F007F,
167 0x007F007F,
168 0x00480048,
169 0x004A004A,
170 0x00520052,
171 0x00550055,
172 0x00500050,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600173 0x00000000,
174 0x00600020,
Lokesh Vutla979d2c32015-06-03 14:43:21 +0530175 0x40011080,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600176 0x08102040,
Lokesh Vutla306b5972016-03-08 09:11:35 +0530177 0x0,
178 0x0,
179 0x0,
180 0x0,
Lokesh Vutla51a0f1f2015-06-03 14:43:22 +0530181 0x0,
182 0x0,
183 0x0,
184 0x0,
Lokesh Vutla306b5972016-03-08 09:11:35 +0530185 0x0,
Lokesh Vutla51a0f1f2015-06-03 14:43:22 +0530186 0x0
Felipe Balbi4750eb62014-11-10 14:02:44 -0600187};
188
189static const struct emif_regs beagle_x15_emif2_ddr3_532mhz_emif_regs = {
Keerthy66dd8062016-05-24 11:45:07 +0530190 .sdram_config_init = 0x61851b32,
191 .sdram_config = 0x61851b32,
192 .sdram_config2 = 0x08000000,
193 .ref_ctrl = 0x000040F1,
194 .ref_ctrl_final = 0x00001035,
195 .sdram_tim1 = 0xcccf36b3,
196 .sdram_tim2 = 0x308f7fda,
197 .sdram_tim3 = 0x407f88a8,
198 .read_idle_ctrl = 0x00050000,
199 .zq_config = 0x5007190b,
200 .temp_alert_config = 0x00000000,
201 .emif_ddr_phy_ctlr_1_init = 0x0024400b,
202 .emif_ddr_phy_ctlr_1 = 0x0e24400b,
203 .emif_ddr_ext_phy_ctrl_1 = 0x10040100,
204 .emif_ddr_ext_phy_ctrl_2 = 0x00910091,
205 .emif_ddr_ext_phy_ctrl_3 = 0x00950095,
206 .emif_ddr_ext_phy_ctrl_4 = 0x009b009b,
207 .emif_ddr_ext_phy_ctrl_5 = 0x009e009e,
208 .emif_rd_wr_lvl_rmp_win = 0x00000000,
209 .emif_rd_wr_lvl_rmp_ctl = 0x80000000,
210 .emif_rd_wr_lvl_ctl = 0x00000000,
211 .emif_rd_wr_exec_thresh = 0x00000305
Felipe Balbi4750eb62014-11-10 14:02:44 -0600212};
213
214static const u32 beagle_x15_emif2_ddr3_ext_phy_ctrl_const_regs[] = {
Lokesh Vutla979d2c32015-06-03 14:43:21 +0530215 0x10040100,
Lokesh Vutla306b5972016-03-08 09:11:35 +0530216 0x00910091,
217 0x00950095,
218 0x009B009B,
219 0x009E009E,
220 0x00980098,
221 0x00340034,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600222 0x00350035,
Lokesh Vutla306b5972016-03-08 09:11:35 +0530223 0x00340034,
224 0x00310031,
225 0x00340034,
226 0x007F007F,
227 0x007F007F,
228 0x007F007F,
229 0x007F007F,
230 0x007F007F,
231 0x00480048,
232 0x004A004A,
233 0x00520052,
234 0x00550055,
235 0x00500050,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600236 0x00000000,
237 0x00600020,
Lokesh Vutla979d2c32015-06-03 14:43:21 +0530238 0x40011080,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600239 0x08102040,
Lokesh Vutla306b5972016-03-08 09:11:35 +0530240 0x0,
241 0x0,
242 0x0,
243 0x0,
244 0x0,
Lokesh Vutla51a0f1f2015-06-03 14:43:22 +0530245 0x0,
246 0x0,
247 0x0,
248 0x0,
249 0x0
Felipe Balbi4750eb62014-11-10 14:02:44 -0600250};
251
Steve Kipisz81c46742017-08-22 13:52:58 +0530252static const struct emif_regs am571x_emif1_ddr3_666mhz_emif_regs = {
253 .sdram_config_init = 0x61863332,
254 .sdram_config = 0x61863332,
255 .sdram_config2 = 0x08000000,
256 .ref_ctrl = 0x0000514d,
257 .ref_ctrl_final = 0x0000144a,
258 .sdram_tim1 = 0xd333887c,
Lokesh Vutlacbd70db2017-12-29 11:47:54 +0530259 .sdram_tim2 = 0x30b37fe3,
260 .sdram_tim3 = 0x409f8ad8,
Steve Kipisz81c46742017-08-22 13:52:58 +0530261 .read_idle_ctrl = 0x00050000,
262 .zq_config = 0x5007190b,
263 .temp_alert_config = 0x00000000,
264 .emif_ddr_phy_ctlr_1_init = 0x0024400f,
265 .emif_ddr_phy_ctlr_1 = 0x0e24400f,
266 .emif_ddr_ext_phy_ctrl_1 = 0x10040100,
267 .emif_ddr_ext_phy_ctrl_2 = 0x00910091,
268 .emif_ddr_ext_phy_ctrl_3 = 0x00950095,
269 .emif_ddr_ext_phy_ctrl_4 = 0x009b009b,
270 .emif_ddr_ext_phy_ctrl_5 = 0x009e009e,
271 .emif_rd_wr_lvl_rmp_win = 0x00000000,
272 .emif_rd_wr_lvl_rmp_ctl = 0x80000000,
273 .emif_rd_wr_lvl_ctl = 0x00000000,
274 .emif_rd_wr_exec_thresh = 0x00000305
275};
276
Lokesh Vutlacbd70db2017-12-29 11:47:54 +0530277static const struct emif_regs am574x_emif1_ddr3_666mhz_emif_ecc_regs = {
278 .sdram_config_init = 0x61863332,
279 .sdram_config = 0x61863332,
280 .sdram_config2 = 0x08000000,
281 .ref_ctrl = 0x0000514d,
282 .ref_ctrl_final = 0x0000144a,
283 .sdram_tim1 = 0xd333887c,
284 .sdram_tim2 = 0x30b37fe3,
285 .sdram_tim3 = 0x409f8ad8,
286 .read_idle_ctrl = 0x00050000,
287 .zq_config = 0x5007190b,
288 .temp_alert_config = 0x00000000,
289 .emif_ddr_phy_ctlr_1_init = 0x0024400f,
290 .emif_ddr_phy_ctlr_1 = 0x0e24400f,
291 .emif_ddr_ext_phy_ctrl_1 = 0x10040100,
292 .emif_ddr_ext_phy_ctrl_2 = 0x00910091,
293 .emif_ddr_ext_phy_ctrl_3 = 0x00950095,
294 .emif_ddr_ext_phy_ctrl_4 = 0x009b009b,
295 .emif_ddr_ext_phy_ctrl_5 = 0x009e009e,
296 .emif_rd_wr_lvl_rmp_win = 0x00000000,
297 .emif_rd_wr_lvl_rmp_ctl = 0x80000000,
298 .emif_rd_wr_lvl_ctl = 0x00000000,
299 .emif_rd_wr_exec_thresh = 0x00000305,
300 .emif_ecc_ctrl_reg = 0xD0000001,
301 .emif_ecc_address_range_1 = 0x3FFF0000,
302 .emif_ecc_address_range_2 = 0x00000000
303};
304
Felipe Balbi4750eb62014-11-10 14:02:44 -0600305void emif_get_reg_dump(u32 emif_nr, const struct emif_regs **regs)
306{
307 switch (emif_nr) {
308 case 1:
Steve Kipisz81c46742017-08-22 13:52:58 +0530309 if (board_is_am571x_idk())
310 *regs = &am571x_emif1_ddr3_666mhz_emif_regs;
Lokesh Vutlacbd70db2017-12-29 11:47:54 +0530311 else if (board_is_am574x_idk())
312 *regs = &am574x_emif1_ddr3_666mhz_emif_ecc_regs;
Steve Kipisz81c46742017-08-22 13:52:58 +0530313 else
314 *regs = &beagle_x15_emif1_ddr3_532mhz_emif_regs;
Felipe Balbi4750eb62014-11-10 14:02:44 -0600315 break;
316 case 2:
Lokesh Vutlacbd70db2017-12-29 11:47:54 +0530317 if (board_is_am574x_idk())
318 *regs = &am571x_emif1_ddr3_666mhz_emif_regs;
319 else
320 *regs = &beagle_x15_emif2_ddr3_532mhz_emif_regs;
Felipe Balbi4750eb62014-11-10 14:02:44 -0600321 break;
322 }
323}
324
325void emif_get_ext_phy_ctrl_const_regs(u32 emif_nr, const u32 **regs, u32 *size)
326{
327 switch (emif_nr) {
328 case 1:
329 *regs = beagle_x15_emif1_ddr3_ext_phy_ctrl_const_regs;
330 *size = ARRAY_SIZE(beagle_x15_emif1_ddr3_ext_phy_ctrl_const_regs);
331 break;
332 case 2:
333 *regs = beagle_x15_emif2_ddr3_ext_phy_ctrl_const_regs;
334 *size = ARRAY_SIZE(beagle_x15_emif2_ddr3_ext_phy_ctrl_const_regs);
335 break;
336 }
337}
338
339struct vcores_data beagle_x15_volts = {
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530340 .mpu.value[OPP_NOM] = VDD_MPU_DRA7_NOM,
341 .mpu.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_MPU_NOM,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600342 .mpu.efuse.reg_bits = DRA752_EFUSE_REGBITS,
343 .mpu.addr = TPS659038_REG_ADDR_SMPS12,
344 .mpu.pmic = &tps659038,
Keerthy66dd8062016-05-24 11:45:07 +0530345 .mpu.abb_tx_done_mask = OMAP_ABB_MPU_TXDONE_MASK,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600346
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530347 .eve.value[OPP_NOM] = VDD_EVE_DRA7_NOM,
348 .eve.value[OPP_OD] = VDD_EVE_DRA7_OD,
349 .eve.value[OPP_HIGH] = VDD_EVE_DRA7_HIGH,
350 .eve.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_DSPEVE_NOM,
351 .eve.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_DSPEVE_OD,
352 .eve.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_DSPEVE_HIGH,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600353 .eve.efuse.reg_bits = DRA752_EFUSE_REGBITS,
354 .eve.addr = TPS659038_REG_ADDR_SMPS45,
355 .eve.pmic = &tps659038,
Nishanth Menon59b92af2016-04-21 14:34:25 -0500356 .eve.abb_tx_done_mask = OMAP_ABB_EVE_TXDONE_MASK,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600357
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530358 .gpu.value[OPP_NOM] = VDD_GPU_DRA7_NOM,
359 .gpu.value[OPP_OD] = VDD_GPU_DRA7_OD,
360 .gpu.value[OPP_HIGH] = VDD_GPU_DRA7_HIGH,
361 .gpu.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_GPU_NOM,
362 .gpu.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_GPU_OD,
363 .gpu.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_GPU_HIGH,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600364 .gpu.efuse.reg_bits = DRA752_EFUSE_REGBITS,
365 .gpu.addr = TPS659038_REG_ADDR_SMPS45,
366 .gpu.pmic = &tps659038,
Nishanth Menon59b92af2016-04-21 14:34:25 -0500367 .gpu.abb_tx_done_mask = OMAP_ABB_GPU_TXDONE_MASK,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600368
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530369 .core.value[OPP_NOM] = VDD_CORE_DRA7_NOM,
370 .core.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_CORE_NOM,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600371 .core.efuse.reg_bits = DRA752_EFUSE_REGBITS,
372 .core.addr = TPS659038_REG_ADDR_SMPS6,
373 .core.pmic = &tps659038,
374
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530375 .iva.value[OPP_NOM] = VDD_IVA_DRA7_NOM,
376 .iva.value[OPP_OD] = VDD_IVA_DRA7_OD,
377 .iva.value[OPP_HIGH] = VDD_IVA_DRA7_HIGH,
378 .iva.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_IVA_NOM,
379 .iva.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_IVA_OD,
380 .iva.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_IVA_HIGH,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600381 .iva.efuse.reg_bits = DRA752_EFUSE_REGBITS,
382 .iva.addr = TPS659038_REG_ADDR_SMPS45,
383 .iva.pmic = &tps659038,
Nishanth Menon59b92af2016-04-21 14:34:25 -0500384 .iva.abb_tx_done_mask = OMAP_ABB_IVA_TXDONE_MASK,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600385};
386
Keerthy152e9932016-05-24 11:45:06 +0530387struct vcores_data am572x_idk_volts = {
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530388 .mpu.value[OPP_NOM] = VDD_MPU_DRA7_NOM,
389 .mpu.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_MPU_NOM,
Keerthy152e9932016-05-24 11:45:06 +0530390 .mpu.efuse.reg_bits = DRA752_EFUSE_REGBITS,
391 .mpu.addr = TPS659038_REG_ADDR_SMPS12,
392 .mpu.pmic = &tps659038,
393 .mpu.abb_tx_done_mask = OMAP_ABB_MPU_TXDONE_MASK,
394
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530395 .eve.value[OPP_NOM] = VDD_EVE_DRA7_NOM,
396 .eve.value[OPP_OD] = VDD_EVE_DRA7_OD,
397 .eve.value[OPP_HIGH] = VDD_EVE_DRA7_HIGH,
398 .eve.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_DSPEVE_NOM,
399 .eve.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_DSPEVE_OD,
400 .eve.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_DSPEVE_HIGH,
Keerthy152e9932016-05-24 11:45:06 +0530401 .eve.efuse.reg_bits = DRA752_EFUSE_REGBITS,
402 .eve.addr = TPS659038_REG_ADDR_SMPS45,
403 .eve.pmic = &tps659038,
404 .eve.abb_tx_done_mask = OMAP_ABB_EVE_TXDONE_MASK,
405
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530406 .gpu.value[OPP_NOM] = VDD_GPU_DRA7_NOM,
407 .gpu.value[OPP_OD] = VDD_GPU_DRA7_OD,
408 .gpu.value[OPP_HIGH] = VDD_GPU_DRA7_HIGH,
409 .gpu.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_GPU_NOM,
410 .gpu.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_GPU_OD,
411 .gpu.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_GPU_HIGH,
Keerthy152e9932016-05-24 11:45:06 +0530412 .gpu.efuse.reg_bits = DRA752_EFUSE_REGBITS,
413 .gpu.addr = TPS659038_REG_ADDR_SMPS6,
414 .gpu.pmic = &tps659038,
415 .gpu.abb_tx_done_mask = OMAP_ABB_GPU_TXDONE_MASK,
416
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530417 .core.value[OPP_NOM] = VDD_CORE_DRA7_NOM,
418 .core.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_CORE_NOM,
Keerthy152e9932016-05-24 11:45:06 +0530419 .core.efuse.reg_bits = DRA752_EFUSE_REGBITS,
420 .core.addr = TPS659038_REG_ADDR_SMPS7,
421 .core.pmic = &tps659038,
422
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530423 .iva.value[OPP_NOM] = VDD_IVA_DRA7_NOM,
424 .iva.value[OPP_OD] = VDD_IVA_DRA7_OD,
425 .iva.value[OPP_HIGH] = VDD_IVA_DRA7_HIGH,
426 .iva.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_IVA_NOM,
427 .iva.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_IVA_OD,
428 .iva.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_IVA_HIGH,
Keerthy152e9932016-05-24 11:45:06 +0530429 .iva.efuse.reg_bits = DRA752_EFUSE_REGBITS,
430 .iva.addr = TPS659038_REG_ADDR_SMPS8,
431 .iva.pmic = &tps659038,
432 .iva.abb_tx_done_mask = OMAP_ABB_IVA_TXDONE_MASK,
433};
434
Keerthy9cc2aee2017-05-25 15:37:34 +0530435struct vcores_data am571x_idk_volts = {
436 .mpu.value[OPP_NOM] = VDD_MPU_DRA7_NOM,
437 .mpu.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_MPU_NOM,
438 .mpu.efuse.reg_bits = DRA752_EFUSE_REGBITS,
439 .mpu.addr = TPS659038_REG_ADDR_SMPS12,
440 .mpu.pmic = &tps659038,
441 .mpu.abb_tx_done_mask = OMAP_ABB_MPU_TXDONE_MASK,
442
443 .eve.value[OPP_NOM] = VDD_EVE_DRA7_NOM,
444 .eve.value[OPP_OD] = VDD_EVE_DRA7_OD,
445 .eve.value[OPP_HIGH] = VDD_EVE_DRA7_HIGH,
446 .eve.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_DSPEVE_NOM,
447 .eve.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_DSPEVE_OD,
448 .eve.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_DSPEVE_HIGH,
449 .eve.efuse.reg_bits = DRA752_EFUSE_REGBITS,
450 .eve.addr = TPS659038_REG_ADDR_SMPS45,
451 .eve.pmic = &tps659038,
452 .eve.abb_tx_done_mask = OMAP_ABB_EVE_TXDONE_MASK,
453
454 .gpu.value[OPP_NOM] = VDD_GPU_DRA7_NOM,
455 .gpu.value[OPP_OD] = VDD_GPU_DRA7_OD,
456 .gpu.value[OPP_HIGH] = VDD_GPU_DRA7_HIGH,
457 .gpu.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_GPU_NOM,
458 .gpu.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_GPU_OD,
459 .gpu.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_GPU_HIGH,
460 .gpu.efuse.reg_bits = DRA752_EFUSE_REGBITS,
461 .gpu.addr = TPS659038_REG_ADDR_SMPS6,
462 .gpu.pmic = &tps659038,
463 .gpu.abb_tx_done_mask = OMAP_ABB_GPU_TXDONE_MASK,
464
465 .core.value[OPP_NOM] = VDD_CORE_DRA7_NOM,
466 .core.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_CORE_NOM,
467 .core.efuse.reg_bits = DRA752_EFUSE_REGBITS,
468 .core.addr = TPS659038_REG_ADDR_SMPS7,
469 .core.pmic = &tps659038,
470
471 .iva.value[OPP_NOM] = VDD_IVA_DRA7_NOM,
472 .iva.value[OPP_OD] = VDD_IVA_DRA7_OD,
473 .iva.value[OPP_HIGH] = VDD_IVA_DRA7_HIGH,
474 .iva.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_IVA_NOM,
475 .iva.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_IVA_OD,
476 .iva.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_IVA_HIGH,
477 .iva.efuse.reg_bits = DRA752_EFUSE_REGBITS,
478 .iva.addr = TPS659038_REG_ADDR_SMPS45,
479 .iva.pmic = &tps659038,
480 .iva.abb_tx_done_mask = OMAP_ABB_IVA_TXDONE_MASK,
481};
482
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530483int get_voltrail_opp(int rail_offset)
484{
485 int opp;
486
487 switch (rail_offset) {
488 case VOLT_MPU:
489 opp = DRA7_MPU_OPP;
490 break;
491 case VOLT_CORE:
492 opp = DRA7_CORE_OPP;
493 break;
494 case VOLT_GPU:
495 opp = DRA7_GPU_OPP;
496 break;
497 case VOLT_EVE:
498 opp = DRA7_DSPEVE_OPP;
499 break;
500 case VOLT_IVA:
501 opp = DRA7_IVA_OPP;
502 break;
503 default:
504 opp = OPP_NOM;
505 }
506
507 return opp;
508}
509
510
Kipisz, Steven161f1382016-02-24 12:30:58 -0600511#ifdef CONFIG_SPL_BUILD
512/* No env to setup for SPL */
513static inline void setup_board_eeprom_env(void) { }
514
515/* Override function to read eeprom information */
516void do_board_detect(void)
517{
518 int rc;
519
520 rc = ti_i2c_eeprom_am_get(CONFIG_EEPROM_BUS_ADDRESS,
521 CONFIG_EEPROM_CHIP_ADDRESS);
522 if (rc)
523 printf("ti_i2c_eeprom_init failed %d\n", rc);
Caleb Robey0dfcc932020-01-02 08:17:25 -0600524
525#ifdef CONFIG_SUPPORT_EMMC_BOOT
526 rc = board_bootmode_has_emmc();
527 if (!rc)
528 rc = ti_emmc_boardid_get();
529 if (rc)
530 printf("ti_emmc_boardid_get failed %d\n", rc);
531#endif
Kipisz, Steven161f1382016-02-24 12:30:58 -0600532}
533
534#else /* CONFIG_SPL_BUILD */
535
536/* Override function to read eeprom information: actual i2c read done by SPL*/
537void do_board_detect(void)
538{
539 char *bname = NULL;
540 int rc;
541
542 rc = ti_i2c_eeprom_am_get(CONFIG_EEPROM_BUS_ADDRESS,
543 CONFIG_EEPROM_CHIP_ADDRESS);
544 if (rc)
545 printf("ti_i2c_eeprom_init failed %d\n", rc);
546
Caleb Robey0dfcc932020-01-02 08:17:25 -0600547#ifdef CONFIG_SUPPORT_EMMC_BOOT
548 rc = board_bootmode_has_emmc();
549 if (!rc)
550 rc = ti_emmc_boardid_get();
551 if (rc)
552 printf("ti_emmc_boardid_get failed %d\n", rc);
553#endif
554
Kipisz, Steven161f1382016-02-24 12:30:58 -0600555 if (board_is_x15())
556 bname = "BeagleBoard X15";
557 else if (board_is_am572x_evm())
558 bname = "AM572x EVM";
Lokesh Vutla374aea02017-12-29 11:47:52 +0530559 else if (board_is_am574x_idk())
560 bname = "AM574x IDK";
Steve Kipisz0ac8cea2016-04-08 17:01:29 -0500561 else if (board_is_am572x_idk())
562 bname = "AM572x IDK";
Steve Kipiszc95cddd2016-11-25 11:14:24 +0530563 else if (board_is_am571x_idk())
564 bname = "AM571x IDK";
Caleb Robey940d6372020-01-02 08:17:27 -0600565 else if (board_is_bbai())
566 bname = "BeagleBone AI";
Kipisz, Steven161f1382016-02-24 12:30:58 -0600567
568 if (bname)
569 snprintf(sysinfo.board_string, SYSINFO_BOARD_NAME_MAX_LEN,
570 "Board: %s REV %s\n", bname, board_ti_get_rev());
571}
572
573static void setup_board_eeprom_env(void)
574{
575 char *name = "beagle_x15";
576 int rc;
577
578 rc = ti_i2c_eeprom_am_get(CONFIG_EEPROM_BUS_ADDRESS,
579 CONFIG_EEPROM_CHIP_ADDRESS);
580 if (rc)
581 goto invalid_eeprom;
582
Nishanth Menona2aea1c2016-11-25 11:14:19 +0530583 if (board_is_x15()) {
Lokesh Vutla638e1c02016-11-25 11:14:20 +0530584 if (board_is_x15_revb1())
585 name = "beagle_x15_revb1";
Lokesh Vutla816178b2017-07-16 19:59:19 +0530586 else if (board_is_x15_revc())
587 name = "beagle_x15_revc";
Lokesh Vutla638e1c02016-11-25 11:14:20 +0530588 else
589 name = "beagle_x15";
Nishanth Menona2aea1c2016-11-25 11:14:19 +0530590 } else if (board_is_am572x_evm()) {
591 if (board_is_am572x_evm_reva3())
592 name = "am57xx_evm_reva3";
593 else
594 name = "am57xx_evm";
Lokesh Vutla374aea02017-12-29 11:47:52 +0530595 } else if (board_is_am574x_idk()) {
596 name = "am574x_idk";
Nishanth Menona2aea1c2016-11-25 11:14:19 +0530597 } else if (board_is_am572x_idk()) {
Steve Kipisz0ac8cea2016-04-08 17:01:29 -0500598 name = "am572x_idk";
Steve Kipiszc95cddd2016-11-25 11:14:24 +0530599 } else if (board_is_am571x_idk()) {
600 name = "am571x_idk";
Caleb Robey940d6372020-01-02 08:17:27 -0600601 } else if (board_is_bbai()) {
602 name = "am5729_beagleboneai";
Nishanth Menona2aea1c2016-11-25 11:14:19 +0530603 } else {
Kipisz, Steven161f1382016-02-24 12:30:58 -0600604 printf("Unidentified board claims %s in eeprom header\n",
605 board_ti_get_name());
Nishanth Menona2aea1c2016-11-25 11:14:19 +0530606 }
Kipisz, Steven161f1382016-02-24 12:30:58 -0600607
608invalid_eeprom:
609 set_board_info_env(name);
610}
611
612#endif /* CONFIG_SPL_BUILD */
613
Keerthy152e9932016-05-24 11:45:06 +0530614void vcores_init(void)
615{
Lokesh Vutla6e9635c2017-12-29 11:47:53 +0530616 if (board_is_am572x_idk() || board_is_am574x_idk())
Keerthy152e9932016-05-24 11:45:06 +0530617 *omap_vcores = &am572x_idk_volts;
Keerthy9cc2aee2017-05-25 15:37:34 +0530618 else if (board_is_am571x_idk())
619 *omap_vcores = &am571x_idk_volts;
Keerthy152e9932016-05-24 11:45:06 +0530620 else
621 *omap_vcores = &beagle_x15_volts;
622}
623
Felipe Balbi4750eb62014-11-10 14:02:44 -0600624void hw_data_init(void)
625{
626 *prcm = &dra7xx_prcm;
Steve Kipisz81c46742017-08-22 13:52:58 +0530627 if (is_dra72x())
628 *dplls_data = &dra72x_dplls;
Lokesh Vutla6e9635c2017-12-29 11:47:53 +0530629 else if (is_dra76x())
630 *dplls_data = &dra76x_dplls;
Steve Kipisz81c46742017-08-22 13:52:58 +0530631 else
632 *dplls_data = &dra7xx_dplls;
Felipe Balbi4750eb62014-11-10 14:02:44 -0600633 *ctrl = &dra7xx_ctrl;
634}
635
Roger Quadros26130592017-03-13 15:04:28 +0200636bool am571x_idk_needs_lcd(void)
637{
638 bool needs_lcd;
639
640 gpio_request(GPIO_ETH_LCD, "nLCD_Detect");
641 if (gpio_get_value(GPIO_ETH_LCD))
642 needs_lcd = false;
643 else
644 needs_lcd = true;
645
646 gpio_free(GPIO_ETH_LCD);
647
648 return needs_lcd;
649}
650
Felipe Balbi4750eb62014-11-10 14:02:44 -0600651int board_init(void)
652{
653 gpmc_init();
654 gd->bd->bi_boot_params = (CONFIG_SYS_SDRAM_BASE + 0x100);
655
656 return 0;
657}
658
Nishanth Menond0f399c2017-03-13 15:04:30 +0200659void am57x_idk_lcd_detect(void)
Felipe Balbi4750eb62014-11-10 14:02:44 -0600660{
Nishanth Menond0f399c2017-03-13 15:04:30 +0200661 int r = -ENODEV;
662 char *idk_lcd = "no";
Jean-Jacques Hiblot184ec9a2018-12-07 14:50:50 +0100663 struct udevice *dev;
Nishanth Menond0f399c2017-03-13 15:04:30 +0200664
665 /* Only valid for IDKs */
Caleb Robey940d6372020-01-02 08:17:27 -0600666 if (board_is_x15() || board_is_am572x_evm() || board_is_bbai())
Nishanth Menond0f399c2017-03-13 15:04:30 +0200667 return;
668
669 /* Only AM571x IDK has gpio control detect.. so check that */
670 if (board_is_am571x_idk() && !am571x_idk_needs_lcd())
671 goto out;
672
Jean-Jacques Hiblot52a51512018-12-07 14:50:49 +0100673 r = i2c_get_chip_for_busnum(OSD_TS_FT_BUS_ADDRESS,
674 OSD_TS_FT_CHIP_ADDRESS, 1, &dev);
Nishanth Menond0f399c2017-03-13 15:04:30 +0200675 if (r) {
Jean-Jacques Hiblot52a51512018-12-07 14:50:49 +0100676 printf("%s: Failed to get I2C device %d/%d (ret %d)\n",
677 __func__, OSD_TS_FT_BUS_ADDRESS, OSD_TS_FT_CHIP_ADDRESS,
678 r);
Nishanth Menond0f399c2017-03-13 15:04:30 +0200679 /* AM572x IDK has no explicit settings for optional LCD kit */
Jean-Jacques Hiblot52a51512018-12-07 14:50:49 +0100680 if (board_is_am571x_idk())
Nishanth Menond0f399c2017-03-13 15:04:30 +0200681 printf("%s: Touch screen detect failed: %d!\n",
682 __func__, r);
Nishanth Menond0f399c2017-03-13 15:04:30 +0200683 goto out;
684 }
685
686 /* Read FT ID */
Jean-Jacques Hiblot52a51512018-12-07 14:50:49 +0100687 r = dm_i2c_reg_read(dev, OSD_TS_FT_REG_ID);
688 if (r < 0) {
Nishanth Menond0f399c2017-03-13 15:04:30 +0200689 printf("%s: Touch screen ID read %d:0x%02x[0x%02x] failed:%d\n",
690 __func__, OSD_TS_FT_BUS_ADDRESS, OSD_TS_FT_CHIP_ADDRESS,
691 OSD_TS_FT_REG_ID, r);
692 goto out;
693 }
694
Jean-Jacques Hiblot184ec9a2018-12-07 14:50:50 +0100695 switch (r) {
Nishanth Menond0f399c2017-03-13 15:04:30 +0200696 case OSD_TS_FT_ID_5606:
697 idk_lcd = "osd101t2045";
698 break;
699 case OSD_TS_FT_ID_5x46:
700 idk_lcd = "osd101t2587";
701 break;
702 default:
703 printf("%s: Unidentifed Touch screen ID 0x%02x\n",
Jean-Jacques Hiblot184ec9a2018-12-07 14:50:50 +0100704 __func__, r);
Nishanth Menond0f399c2017-03-13 15:04:30 +0200705 /* we will let default be "no lcd" */
706 }
707out:
Simon Glass6a38e412017-08-03 12:22:09 -0600708 env_set("idk_lcd", idk_lcd);
Nishanth Menond0f399c2017-03-13 15:04:30 +0200709 return;
710}
Roger Quadros26130592017-03-13 15:04:28 +0200711
Vignesh R98c5f632018-11-29 10:57:42 +0100712#if CONFIG_IS_ENABLED(DM_USB) && CONFIG_IS_ENABLED(OF_CONTROL)
713static int device_okay(const char *path)
714{
715 int node;
716
717 node = fdt_path_offset(gd->fdt_blob, path);
718 if (node < 0)
719 return 0;
720
721 return fdtdec_get_is_enabled(gd->fdt_blob, node);
722}
723#endif
724
Nishanth Menond0f399c2017-03-13 15:04:30 +0200725int board_late_init(void)
726{
Kipisz, Steven161f1382016-02-24 12:30:58 -0600727 setup_board_eeprom_env();
Keerthyee85ebe2016-11-30 15:02:53 +0530728 u8 val;
Tero Kristodfbc6b82019-09-27 19:14:27 +0300729 struct udevice *dev;
Kipisz, Steven161f1382016-02-24 12:30:58 -0600730
Felipe Balbi4750eb62014-11-10 14:02:44 -0600731 /*
732 * DEV_CTRL.DEV_ON = 1 please - else palmas switches off in 8 seconds
733 * This is the POWERHOLD-in-Low behavior.
734 */
735 palmas_i2c_write_u8(TPS65903X_CHIP_P1, 0xA0, 0x1);
Lokesh Vutla2c47e8c2016-11-29 11:58:02 +0530736
737 /*
738 * Default FIT boot on HS devices. Non FIT images are not allowed
739 * on HS devices.
740 */
741 if (get_device_type() == HS_DEVICE)
Simon Glass6a38e412017-08-03 12:22:09 -0600742 env_set("boot_fit", "1");
Lokesh Vutla2c47e8c2016-11-29 11:58:02 +0530743
Keerthyee85ebe2016-11-30 15:02:53 +0530744 /*
745 * Set the GPIO7 Pad to POWERHOLD. This has higher priority
746 * over DEV_CTRL.DEV_ON bit. This can be reset in case of
747 * PMIC Power off. So to be on the safer side set it back
748 * to POWERHOLD mode irrespective of the current state.
749 */
750 palmas_i2c_read_u8(TPS65903X_CHIP_P1, TPS65903X_PRIMARY_SECONDARY_PAD2,
751 &val);
752 val = val | TPS65903X_PAD2_POWERHOLD_MASK;
753 palmas_i2c_write_u8(TPS65903X_CHIP_P1, TPS65903X_PRIMARY_SECONDARY_PAD2,
754 val);
755
Semen Protsenko4b0721f2017-02-13 19:09:37 +0200756 omap_die_id_serial();
Semen Protsenkob72dccd2017-05-22 19:16:41 +0300757 omap_set_fastboot_vars();
Semen Protsenko4b0721f2017-02-13 19:09:37 +0200758
Nishanth Menond0f399c2017-03-13 15:04:30 +0200759 am57x_idk_lcd_detect();
Roger Quadros26130592017-03-13 15:04:28 +0200760
Tero Kristodfbc6b82019-09-27 19:14:27 +0300761 /* Just probe the potentially supported cdce913 device */
762 uclass_get_device(UCLASS_CLK, 0, &dev);
763
Caleb Robey940d6372020-01-02 08:17:27 -0600764 if (board_is_bbai())
765 env_set("console", "ttyS0,115200n8");
766
Roger Quadros26130592017-03-13 15:04:28 +0200767#if !defined(CONFIG_SPL_BUILD)
768 board_ti_set_ethaddr(2);
769#endif
770
Vignesh R98c5f632018-11-29 10:57:42 +0100771#if CONFIG_IS_ENABLED(DM_USB) && CONFIG_IS_ENABLED(OF_CONTROL)
772 if (device_okay("/ocp/omap_dwc3_1@48880000"))
773 enable_usb_clocks(0);
774 if (device_okay("/ocp/omap_dwc3_2@488c0000"))
775 enable_usb_clocks(1);
776#endif
Felipe Balbi4750eb62014-11-10 14:02:44 -0600777 return 0;
778}
779
Paul Kocialkowskia00b1e52016-02-27 19:18:56 +0100780void set_muxconf_regs(void)
Felipe Balbi4750eb62014-11-10 14:02:44 -0600781{
782 do_set_mux32((*ctrl)->control_padconf_core_base,
Lokesh Vutlac3d39f92015-06-04 16:42:41 +0530783 early_padconf, ARRAY_SIZE(early_padconf));
Caleb Robey0dfcc932020-01-02 08:17:25 -0600784
785#ifdef CONFIG_SUPPORT_EMMC_BOOT
786 do_set_mux32((*ctrl)->control_padconf_core_base,
787 emmc_padconf, ARRAY_SIZE(emmc_padconf));
788#endif
Felipe Balbi4750eb62014-11-10 14:02:44 -0600789}
790
Lokesh Vutlac3d39f92015-06-04 16:42:41 +0530791#ifdef CONFIG_IODELAY_RECALIBRATION
792void recalibrate_iodelay(void)
793{
Steve Kipisz0ac8cea2016-04-08 17:01:29 -0500794 const struct pad_conf_entry *pconf;
Lokesh Vutla3cb4c622017-06-05 14:48:16 +0530795 const struct iodelay_cfg_entry *iod, *delta_iod;
796 int pconf_sz, iod_sz, delta_iod_sz = 0;
Nishanth Menon8e3212e2016-11-25 11:14:22 +0530797 int ret;
Steve Kipisz0ac8cea2016-04-08 17:01:29 -0500798
Lokesh Vutla1e3425c2017-12-29 11:47:55 +0530799 if (board_is_am572x_idk()) {
Steve Kipisz0ac8cea2016-04-08 17:01:29 -0500800 pconf = core_padconf_array_essential_am572x_idk;
801 pconf_sz = ARRAY_SIZE(core_padconf_array_essential_am572x_idk);
802 iod = iodelay_cfg_array_am572x_idk;
803 iod_sz = ARRAY_SIZE(iodelay_cfg_array_am572x_idk);
Lokesh Vutla1e3425c2017-12-29 11:47:55 +0530804 } else if (board_is_am574x_idk()) {
805 pconf = core_padconf_array_essential_am574x_idk;
806 pconf_sz = ARRAY_SIZE(core_padconf_array_essential_am574x_idk);
807 iod = iodelay_cfg_array_am574x_idk;
808 iod_sz = ARRAY_SIZE(iodelay_cfg_array_am574x_idk);
Steve Kipiszc95cddd2016-11-25 11:14:24 +0530809 } else if (board_is_am571x_idk()) {
810 pconf = core_padconf_array_essential_am571x_idk;
811 pconf_sz = ARRAY_SIZE(core_padconf_array_essential_am571x_idk);
812 iod = iodelay_cfg_array_am571x_idk;
813 iod_sz = ARRAY_SIZE(iodelay_cfg_array_am571x_idk);
Caleb Robey940d6372020-01-02 08:17:27 -0600814 } else if (board_is_bbai()) {
815 pconf = core_padconf_array_essential_bbai;
816 pconf_sz = ARRAY_SIZE(core_padconf_array_essential_bbai);
817 iod = iodelay_cfg_array_bbai;
818 iod_sz = ARRAY_SIZE(iodelay_cfg_array_bbai);
Steve Kipisz0ac8cea2016-04-08 17:01:29 -0500819 } else {
820 /* Common for X15/GPEVM */
821 pconf = core_padconf_array_essential_x15;
822 pconf_sz = ARRAY_SIZE(core_padconf_array_essential_x15);
Nishanth Menon8e3212e2016-11-25 11:14:22 +0530823 /* There never was an SR1.0 X15.. So.. */
824 if (omap_revision() == DRA752_ES1_1) {
825 iod = iodelay_cfg_array_x15_sr1_1;
826 iod_sz = ARRAY_SIZE(iodelay_cfg_array_x15_sr1_1);
827 } else {
828 /* Since full production should switch to SR2.0 */
829 iod = iodelay_cfg_array_x15_sr2_0;
830 iod_sz = ARRAY_SIZE(iodelay_cfg_array_x15_sr2_0);
831 }
Steve Kipisz0ac8cea2016-04-08 17:01:29 -0500832 }
833
Nishanth Menon8e3212e2016-11-25 11:14:22 +0530834 /* Setup I/O isolation */
835 ret = __recalibrate_iodelay_start();
836 if (ret)
837 goto err;
838
839 /* Do the muxing here */
840 do_set_mux32((*ctrl)->control_padconf_core_base, pconf, pconf_sz);
841
842 /* Now do the weird minor deltas that should be safe */
843 if (board_is_x15() || board_is_am572x_evm()) {
Lokesh Vutla816178b2017-07-16 19:59:19 +0530844 if (board_is_x15_revb1() || board_is_am572x_evm_reva3() ||
845 board_is_x15_revc()) {
Nishanth Menon8e3212e2016-11-25 11:14:22 +0530846 pconf = core_padconf_array_delta_x15_sr2_0;
847 pconf_sz = ARRAY_SIZE(core_padconf_array_delta_x15_sr2_0);
848 } else {
849 pconf = core_padconf_array_delta_x15_sr1_1;
850 pconf_sz = ARRAY_SIZE(core_padconf_array_delta_x15_sr1_1);
851 }
852 do_set_mux32((*ctrl)->control_padconf_core_base, pconf, pconf_sz);
853 }
854
Roger Quadros26130592017-03-13 15:04:28 +0200855 if (board_is_am571x_idk()) {
856 if (am571x_idk_needs_lcd()) {
857 pconf = core_padconf_array_vout_am571x_idk;
858 pconf_sz = ARRAY_SIZE(core_padconf_array_vout_am571x_idk);
Lokesh Vutla3cb4c622017-06-05 14:48:16 +0530859 delta_iod = iodelay_cfg_array_am571x_idk_4port;
860 delta_iod_sz = ARRAY_SIZE(iodelay_cfg_array_am571x_idk_4port);
861
Roger Quadros26130592017-03-13 15:04:28 +0200862 } else {
863 pconf = core_padconf_array_icss1eth_am571x_idk;
864 pconf_sz = ARRAY_SIZE(core_padconf_array_icss1eth_am571x_idk);
865 }
866 do_set_mux32((*ctrl)->control_padconf_core_base, pconf, pconf_sz);
867 }
868
Nishanth Menon8e3212e2016-11-25 11:14:22 +0530869 /* Setup IOdelay configuration */
870 ret = do_set_iodelay((*ctrl)->iodelay_config_base, iod, iod_sz);
Lokesh Vutla3cb4c622017-06-05 14:48:16 +0530871 if (delta_iod_sz)
872 ret = do_set_iodelay((*ctrl)->iodelay_config_base, delta_iod,
873 delta_iod_sz);
874
Nishanth Menon8e3212e2016-11-25 11:14:22 +0530875err:
876 /* Closeup.. remove isolation */
877 __recalibrate_iodelay_end(ret);
Lokesh Vutlac3d39f92015-06-04 16:42:41 +0530878}
879#endif
880
Masahiro Yamada0a780172017-05-09 20:31:39 +0900881#if defined(CONFIG_MMC)
Felipe Balbi4750eb62014-11-10 14:02:44 -0600882int board_mmc_init(bd_t *bis)
883{
884 omap_mmc_init(0, 0, 0, -1, -1);
885 omap_mmc_init(1, 0, 0, -1, -1);
886 return 0;
887}
Kishon Vijay Abraham I110ed012018-01-30 16:01:52 +0100888
889static const struct mmc_platform_fixups am57x_es1_1_mmc1_fixups = {
890 .hw_rev = "rev11",
891 .unsupported_caps = MMC_CAP(MMC_HS_200) |
892 MMC_CAP(UHS_SDR104),
893 .max_freq = 96000000,
894};
895
896static const struct mmc_platform_fixups am57x_es1_1_mmc23_fixups = {
897 .hw_rev = "rev11",
898 .unsupported_caps = MMC_CAP(MMC_HS_200) |
899 MMC_CAP(UHS_SDR104) |
900 MMC_CAP(UHS_SDR50),
901 .max_freq = 48000000,
902};
903
904const struct mmc_platform_fixups *platform_fixups_mmc(uint32_t addr)
905{
906 switch (omap_revision()) {
907 case DRA752_ES1_0:
908 case DRA752_ES1_1:
909 if (addr == OMAP_HSMMC1_BASE)
910 return &am57x_es1_1_mmc1_fixups;
911 else
912 return &am57x_es1_1_mmc23_fixups;
913 default:
914 return NULL;
915 }
916}
Felipe Balbi4750eb62014-11-10 14:02:44 -0600917#endif
918
919#if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_OS_BOOT)
920int spl_start_uboot(void)
921{
922 /* break into full u-boot on 'c' */
923 if (serial_tstc() && serial_getc() == 'c')
924 return 1;
925
926#ifdef CONFIG_SPL_ENV_SUPPORT
927 env_init();
Simon Glass17539572017-08-03 12:22:07 -0600928 env_load();
Simon Glass22c34c22017-08-03 12:22:13 -0600929 if (env_get_yesno("boot_os") != 1)
Felipe Balbi4750eb62014-11-10 14:02:44 -0600930 return 1;
931#endif
932
933 return 0;
934}
935#endif
936
937#ifdef CONFIG_DRIVER_TI_CPSW
938
939/* Delay value to add to calibrated value */
940#define RGMII0_TXCTL_DLY_VAL ((0x3 << 5) + 0x8)
941#define RGMII0_TXD0_DLY_VAL ((0x3 << 5) + 0x8)
942#define RGMII0_TXD1_DLY_VAL ((0x3 << 5) + 0x2)
943#define RGMII0_TXD2_DLY_VAL ((0x4 << 5) + 0x0)
944#define RGMII0_TXD3_DLY_VAL ((0x4 << 5) + 0x0)
945#define VIN2A_D13_DLY_VAL ((0x3 << 5) + 0x8)
946#define VIN2A_D17_DLY_VAL ((0x3 << 5) + 0x8)
947#define VIN2A_D16_DLY_VAL ((0x3 << 5) + 0x2)
948#define VIN2A_D15_DLY_VAL ((0x4 << 5) + 0x0)
949#define VIN2A_D14_DLY_VAL ((0x4 << 5) + 0x0)
950
951static void cpsw_control(int enabled)
952{
953 /* VTP can be added here */
954}
955
956static struct cpsw_slave_data cpsw_slaves[] = {
957 {
958 .slave_reg_ofs = 0x208,
959 .sliver_reg_ofs = 0xd80,
960 .phy_addr = 1,
961 },
962 {
963 .slave_reg_ofs = 0x308,
964 .sliver_reg_ofs = 0xdc0,
965 .phy_addr = 2,
966 },
967};
968
969static struct cpsw_platform_data cpsw_data = {
970 .mdio_base = CPSW_MDIO_BASE,
971 .cpsw_base = CPSW_BASE,
972 .mdio_div = 0xff,
973 .channels = 8,
974 .cpdma_reg_ofs = 0x800,
975 .slaves = 1,
976 .slave_data = cpsw_slaves,
977 .ale_reg_ofs = 0xd00,
978 .ale_entries = 1024,
979 .host_port_reg_ofs = 0x108,
980 .hw_stats_reg_ofs = 0x900,
981 .bd_ram_ofs = 0x2000,
982 .mac_control = (1 << 5),
983 .control = cpsw_control,
984 .host_port_num = 0,
985 .version = CPSW_CTRL_VERSION_2,
986};
987
Roger Quadros64217a22016-03-18 13:18:12 +0200988static u64 mac_to_u64(u8 mac[6])
989{
990 int i;
991 u64 addr = 0;
992
993 for (i = 0; i < 6; i++) {
994 addr <<= 8;
995 addr |= mac[i];
996 }
997
998 return addr;
999}
1000
1001static void u64_to_mac(u64 addr, u8 mac[6])
1002{
1003 mac[5] = addr;
1004 mac[4] = addr >> 8;
1005 mac[3] = addr >> 16;
1006 mac[2] = addr >> 24;
1007 mac[1] = addr >> 32;
1008 mac[0] = addr >> 40;
1009}
1010
Felipe Balbi4750eb62014-11-10 14:02:44 -06001011int board_eth_init(bd_t *bis)
1012{
1013 int ret;
1014 uint8_t mac_addr[6];
1015 uint32_t mac_hi, mac_lo;
1016 uint32_t ctrl_val;
Roger Quadros64217a22016-03-18 13:18:12 +02001017 int i;
1018 u64 mac1, mac2;
1019 u8 mac_addr1[6], mac_addr2[6];
1020 int num_macs;
Felipe Balbi4750eb62014-11-10 14:02:44 -06001021
1022 /* try reading mac address from efuse */
1023 mac_lo = readl((*ctrl)->control_core_mac_id_0_lo);
1024 mac_hi = readl((*ctrl)->control_core_mac_id_0_hi);
1025 mac_addr[0] = (mac_hi & 0xFF0000) >> 16;
1026 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
1027 mac_addr[2] = mac_hi & 0xFF;
1028 mac_addr[3] = (mac_lo & 0xFF0000) >> 16;
1029 mac_addr[4] = (mac_lo & 0xFF00) >> 8;
1030 mac_addr[5] = mac_lo & 0xFF;
1031
Simon Glass64b723f2017-08-03 12:22:12 -06001032 if (!env_get("ethaddr")) {
Felipe Balbi4750eb62014-11-10 14:02:44 -06001033 printf("<ethaddr> not set. Validating first E-fuse MAC\n");
1034
Joe Hershberger8ecdbed2015-04-08 01:41:04 -05001035 if (is_valid_ethaddr(mac_addr))
Simon Glass8551d552017-08-03 12:22:11 -06001036 eth_env_set_enetaddr("ethaddr", mac_addr);
Felipe Balbi4750eb62014-11-10 14:02:44 -06001037 }
1038
1039 mac_lo = readl((*ctrl)->control_core_mac_id_1_lo);
1040 mac_hi = readl((*ctrl)->control_core_mac_id_1_hi);
1041 mac_addr[0] = (mac_hi & 0xFF0000) >> 16;
1042 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
1043 mac_addr[2] = mac_hi & 0xFF;
1044 mac_addr[3] = (mac_lo & 0xFF0000) >> 16;
1045 mac_addr[4] = (mac_lo & 0xFF00) >> 8;
1046 mac_addr[5] = mac_lo & 0xFF;
1047
Simon Glass64b723f2017-08-03 12:22:12 -06001048 if (!env_get("eth1addr")) {
Joe Hershberger8ecdbed2015-04-08 01:41:04 -05001049 if (is_valid_ethaddr(mac_addr))
Simon Glass8551d552017-08-03 12:22:11 -06001050 eth_env_set_enetaddr("eth1addr", mac_addr);
Felipe Balbi4750eb62014-11-10 14:02:44 -06001051 }
1052
1053 ctrl_val = readl((*ctrl)->control_core_control_io1) & (~0x33);
1054 ctrl_val |= 0x22;
1055 writel(ctrl_val, (*ctrl)->control_core_control_io1);
1056
Steve Kipiszc95cddd2016-11-25 11:14:24 +05301057 /* The phy address for the AM57xx IDK are different than x15 */
Lokesh Vutla6e9635c2017-12-29 11:47:53 +05301058 if (board_is_am572x_idk() || board_is_am571x_idk() ||
1059 board_is_am574x_idk()) {
Steve Kipisz0ac8cea2016-04-08 17:01:29 -05001060 cpsw_data.slave_data[0].phy_addr = 0;
1061 cpsw_data.slave_data[1].phy_addr = 1;
1062 }
1063
Felipe Balbi4750eb62014-11-10 14:02:44 -06001064 ret = cpsw_register(&cpsw_data);
1065 if (ret < 0)
1066 printf("Error %d registering CPSW switch\n", ret);
1067
Roger Quadros64217a22016-03-18 13:18:12 +02001068 /*
1069 * Export any Ethernet MAC addresses from EEPROM.
1070 * On AM57xx the 2 MAC addresses define the address range
1071 */
1072 board_ti_get_eth_mac_addr(0, mac_addr1);
1073 board_ti_get_eth_mac_addr(1, mac_addr2);
1074
1075 if (is_valid_ethaddr(mac_addr1) && is_valid_ethaddr(mac_addr2)) {
1076 mac1 = mac_to_u64(mac_addr1);
1077 mac2 = mac_to_u64(mac_addr2);
1078
1079 /* must contain an address range */
1080 num_macs = mac2 - mac1 + 1;
1081 /* <= 50 to protect against user programming error */
1082 if (num_macs > 0 && num_macs <= 50) {
1083 for (i = 0; i < num_macs; i++) {
1084 u64_to_mac(mac1 + i, mac_addr);
1085 if (is_valid_ethaddr(mac_addr)) {
Simon Glass8551d552017-08-03 12:22:11 -06001086 eth_env_set_enetaddr_by_index("eth",
1087 i + 2,
1088 mac_addr);
Roger Quadros64217a22016-03-18 13:18:12 +02001089 }
1090 }
1091 }
1092 }
1093
Felipe Balbi4750eb62014-11-10 14:02:44 -06001094 return ret;
1095}
1096#endif
Lokesh Vutla9f150672015-06-16 20:36:05 +05301097
1098#ifdef CONFIG_BOARD_EARLY_INIT_F
1099/* VTT regulator enable */
1100static inline void vtt_regulator_enable(void)
1101{
1102 if (omap_hw_init_context() == OMAP_INIT_CONTEXT_UBOOT_AFTER_SPL)
1103 return;
1104
1105 gpio_request(GPIO_DDR_VTT_EN, "ddr_vtt_en");
1106 gpio_direction_output(GPIO_DDR_VTT_EN, 1);
1107}
1108
1109int board_early_init_f(void)
1110{
1111 vtt_regulator_enable();
1112 return 0;
1113}
1114#endif
Daniel Allred7ceffb22016-05-19 19:10:54 -05001115
1116#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
1117int ft_board_setup(void *blob, bd_t *bd)
1118{
1119 ft_cpu_setup(blob, bd);
1120
1121 return 0;
1122}
1123#endif
Lokesh Vutla00bf8b22016-06-10 09:35:43 +05301124
1125#ifdef CONFIG_SPL_LOAD_FIT
1126int board_fit_config_name_match(const char *name)
1127{
Lokesh Vutla638e1c02016-11-25 11:14:20 +05301128 if (board_is_x15()) {
1129 if (board_is_x15_revb1()) {
1130 if (!strcmp(name, "am57xx-beagle-x15-revb1"))
1131 return 0;
Lokesh Vutlaf35589c2017-08-23 11:39:06 +05301132 } else if (board_is_x15_revc()) {
1133 if (!strcmp(name, "am57xx-beagle-x15-revc"))
1134 return 0;
Lokesh Vutla638e1c02016-11-25 11:14:20 +05301135 } else if (!strcmp(name, "am57xx-beagle-x15")) {
1136 return 0;
1137 }
1138 } else if (board_is_am572x_evm() &&
1139 !strcmp(name, "am57xx-beagle-x15")) {
Lokesh Vutla00bf8b22016-06-10 09:35:43 +05301140 return 0;
Lokesh Vutla638e1c02016-11-25 11:14:20 +05301141 } else if (board_is_am572x_idk() && !strcmp(name, "am572x-idk")) {
Schuyler Patton99519852016-06-10 09:35:45 +05301142 return 0;
Lokesh Vutla58a3c1b2017-12-29 11:47:57 +05301143 } else if (board_is_am574x_idk() && !strcmp(name, "am574x-idk")) {
1144 return 0;
Schuyler Pattonc665e272016-11-25 11:14:25 +05301145 } else if (board_is_am571x_idk() && !strcmp(name, "am571x-idk")) {
1146 return 0;
Caleb Robey940d6372020-01-02 08:17:27 -06001147 } else if (board_is_bbai() && !strcmp(name, "am5729-beagleboneai")) {
1148 return 0;
Lokesh Vutla638e1c02016-11-25 11:14:20 +05301149 }
1150
1151 return -1;
Lokesh Vutla00bf8b22016-06-10 09:35:43 +05301152}
1153#endif
Andreas Dannenberg5cf344b2016-06-27 09:19:22 -05001154
Andrew F. Davisd3555832019-02-11 08:00:08 -06001155#if CONFIG_IS_ENABLED(FASTBOOT) && !CONFIG_IS_ENABLED(ENV_IS_NOWHERE)
1156int fastboot_set_reboot_flag(void)
1157{
1158 printf("Setting reboot to fastboot flag ...\n");
1159 env_set("dofastboot", "1");
1160 env_save();
1161 return 0;
1162}
1163#endif
1164
Caleb Robey0dfcc932020-01-02 08:17:25 -06001165#ifdef CONFIG_SUPPORT_EMMC_BOOT
1166static int board_bootmode_has_emmc(void)
1167{
1168 /* Check that boot mode is same as BBAI */
1169 if (gd->arch.omap_boot_mode != 2)
1170 return -EIO;
1171
1172 return 0;
1173}
1174#endif
1175
Andreas Dannenberg5cf344b2016-06-27 09:19:22 -05001176#ifdef CONFIG_TI_SECURE_DEVICE
1177void board_fit_image_post_process(void **p_image, size_t *p_size)
1178{
1179 secure_boot_verify_image(p_image, p_size);
1180}
Andrew F. Davis7d250622016-11-29 16:33:26 -06001181
1182void board_tee_image_process(ulong tee_image, size_t tee_size)
1183{
1184 secure_tee_install((u32)tee_image);
1185}
1186
1187U_BOOT_FIT_LOADABLE_HANDLER(IH_TYPE_TEE, board_tee_image_process);
Andreas Dannenberg5cf344b2016-06-27 09:19:22 -05001188#endif