blob: cc5e64c987989d53ebdf6da52ba342aa6f923053 [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/*
Nishanth Menoneaa39c62023-11-01 15:56:03 -05003 * Copyright (C) 2014 Texas Instruments Incorporated - https://www.ti.com
Felipe Balbi4750eb62014-11-10 14:02:44 -06004 *
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
Tom Rinidec7ea02024-05-20 13:35:03 -060010#include <config.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 Glassa7b51302019-11-14 12:57:46 -070014#include <init.h>
Simon Glass9bc15642020-02-03 07:36:16 -070015#include <malloc.h>
Simon Glass274e0b02020-05-10 11:39:56 -060016#include <net.h>
Felipe Balbi4750eb62014-11-10 14:02:44 -060017#include <palmas.h>
18#include <sata.h>
Simon Glass36736182019-11-14 12:57:24 -070019#include <serial.h>
Felipe Balbi4750eb62014-11-10 14:02:44 -060020#include <usb.h>
Caleb Robey0dfcc932020-01-02 08:17:25 -060021#include <errno.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060022#include <asm/global_data.h>
Felipe Balbi4750eb62014-11-10 14:02:44 -060023#include <asm/omap_common.h>
24#include <asm/emif.h>
Lokesh Vutla9f150672015-06-16 20:36:05 +053025#include <asm/gpio.h>
26#include <asm/arch/gpio.h>
Felipe Balbi4750eb62014-11-10 14:02:44 -060027#include <asm/arch/clock.h>
Lokesh Vutlac3d39f92015-06-04 16:42:41 +053028#include <asm/arch/dra7xx_iodelay.h>
Felipe Balbi4750eb62014-11-10 14:02:44 -060029#include <asm/arch/sys_proto.h>
30#include <asm/arch/mmc_host_def.h>
31#include <asm/arch/sata.h>
32#include <asm/arch/gpio.h>
Kishon Vijay Abraham I5f19b2d2015-08-19 14:13:19 +053033#include <asm/arch/omap.h>
Kishon Vijay Abraham I5f19b2d2015-08-19 14:13:19 +053034#include <usb.h>
35#include <linux/usb/gadget.h>
36#include <dwc3-uboot.h>
37#include <dwc3-omap-uboot.h>
38#include <ti-usb-phy-uboot.h>
Kishon Vijay Abraham I110ed012018-01-30 16:01:52 +010039#include <mmc.h>
Tero Kristodfbc6b82019-09-27 19:14:27 +030040#include <dm/uclass.h>
Roger Quadros8835eee2020-02-10 11:59:24 +020041#include <hang.h>
Felipe Balbi4750eb62014-11-10 14:02:44 -060042
Kipisz, Steven161f1382016-02-24 12:30:58 -060043#include "../common/board_detect.h"
Kory Maincent66fd9ec2021-05-04 19:31:25 +020044#include "../common/cape_detect.h"
Felipe Balbi4750eb62014-11-10 14:02:44 -060045#include "mux_data.h"
46
Caleb Robey0dfcc932020-01-02 08:17:25 -060047#ifdef CONFIG_SUPPORT_EMMC_BOOT
48static int board_bootmode_has_emmc(void);
49#endif
50
Kipisz, Steven161f1382016-02-24 12:30:58 -060051#define board_is_x15() board_ti_is("BBRDX15_")
Lokesh Vutla638e1c02016-11-25 11:14:20 +053052#define board_is_x15_revb1() (board_ti_is("BBRDX15_") && \
Lokesh Vutlaab4f71e2017-07-16 19:59:18 +053053 !strncmp("B.10", board_ti_get_rev(), 3))
Lokesh Vutla816178b2017-07-16 19:59:19 +053054#define board_is_x15_revc() (board_ti_is("BBRDX15_") && \
55 !strncmp("C.00", board_ti_get_rev(), 3))
Kipisz, Steven161f1382016-02-24 12:30:58 -060056#define board_is_am572x_evm() board_ti_is("AM572PM_")
Nishanth Menona2aea1c2016-11-25 11:14:19 +053057#define board_is_am572x_evm_reva3() \
58 (board_ti_is("AM572PM_") && \
Lokesh Vutlaab4f71e2017-07-16 19:59:18 +053059 !strncmp("A.30", board_ti_get_rev(), 3))
Lokesh Vutla374aea02017-12-29 11:47:52 +053060#define board_is_am574x_idk() board_ti_is("AM574IDK")
Steve Kipisz0ac8cea2016-04-08 17:01:29 -050061#define board_is_am572x_idk() board_ti_is("AM572IDK")
Steve Kipiszc95cddd2016-11-25 11:14:24 +053062#define board_is_am571x_idk() board_ti_is("AM571IDK")
Caleb Robey940d6372020-01-02 08:17:27 -060063#define board_is_bbai() board_ti_is("BBONE-AI")
Kipisz, Steven161f1382016-02-24 12:30:58 -060064
Luca Ceresoli93f6bc22020-05-21 15:06:25 +020065#define board_is_ti_idk() board_is_am574x_idk() || \
66 board_is_am572x_idk() || \
67 board_is_am571x_idk()
68
Felipe Balbi4750eb62014-11-10 14:02:44 -060069#ifdef CONFIG_DRIVER_TI_CPSW
70#include <cpsw.h>
71#endif
72
73DECLARE_GLOBAL_DATA_PTR;
74
Roger Quadros26130592017-03-13 15:04:28 +020075#define GPIO_ETH_LCD GPIO_TO_PIN(2, 22)
Luca Ceresoliacea16b2020-05-21 15:06:24 +020076#define GPIO_DDR_VTT_EN GPIO_TO_PIN(7, 11)
Lokesh Vutla9f150672015-06-16 20:36:05 +053077
Nishanth Menond0f399c2017-03-13 15:04:30 +020078/* Touch screen controller to identify the LCD */
79#define OSD_TS_FT_BUS_ADDRESS 0
80#define OSD_TS_FT_CHIP_ADDRESS 0x38
81#define OSD_TS_FT_REG_ID 0xA3
82/*
83 * Touchscreen IDs for various OSD panels
84 * Ref: http://www.osddisplays.com/TI/OSD101T2587-53TS_A.1.pdf
85 */
86/* Used on newer osd101t2587 Panels */
87#define OSD_TS_FT_ID_5x46 0x54
88/* Used on older osd101t2045 Panels */
89#define OSD_TS_FT_ID_5606 0x08
90
Kipisz, Steven161f1382016-02-24 12:30:58 -060091#define SYSINFO_BOARD_NAME_MAX_LEN 45
92
Keerthyee85ebe2016-11-30 15:02:53 +053093#define TPS65903X_PRIMARY_SECONDARY_PAD2 0xFB
94#define TPS65903X_PAD2_POWERHOLD_MASK 0x20
95
Felipe Balbi4750eb62014-11-10 14:02:44 -060096const struct omap_sysinfo sysinfo = {
Kipisz, Steven161f1382016-02-24 12:30:58 -060097 "Board: UNKNOWN(BeagleBoard X15?) REV UNKNOWN\n"
Felipe Balbi4750eb62014-11-10 14:02:44 -060098};
99
100static const struct dmm_lisa_map_regs beagle_x15_lisa_regs = {
101 .dmm_lisa_map_3 = 0x80740300,
102 .is_ma_present = 0x1
103};
104
Steve Kipiszc95cddd2016-11-25 11:14:24 +0530105static const struct dmm_lisa_map_regs am571x_idk_lisa_regs = {
106 .dmm_lisa_map_3 = 0x80640100,
107 .is_ma_present = 0x1
108};
109
Lokesh Vutlacbd70db2017-12-29 11:47:54 +0530110static const struct dmm_lisa_map_regs am574x_idk_lisa_regs = {
111 .dmm_lisa_map_2 = 0xc0600200,
112 .dmm_lisa_map_3 = 0x80600100,
113 .is_ma_present = 0x1
114};
115
Caleb Robey940d6372020-01-02 08:17:27 -0600116static const struct dmm_lisa_map_regs bbai_lisa_regs = {
117 .dmm_lisa_map_3 = 0x80640100,
118 .is_ma_present = 0x1
119};
120
Felipe Balbi4750eb62014-11-10 14:02:44 -0600121void emif_get_dmm_regs(const struct dmm_lisa_map_regs **dmm_lisa_regs)
122{
Steve Kipiszc95cddd2016-11-25 11:14:24 +0530123 if (board_is_am571x_idk())
124 *dmm_lisa_regs = &am571x_idk_lisa_regs;
Lokesh Vutlacbd70db2017-12-29 11:47:54 +0530125 else if (board_is_am574x_idk())
126 *dmm_lisa_regs = &am574x_idk_lisa_regs;
Caleb Robey940d6372020-01-02 08:17:27 -0600127 else if (board_is_bbai())
128 *dmm_lisa_regs = &bbai_lisa_regs;
Steve Kipiszc95cddd2016-11-25 11:14:24 +0530129 else
130 *dmm_lisa_regs = &beagle_x15_lisa_regs;
Felipe Balbi4750eb62014-11-10 14:02:44 -0600131}
132
133static const struct emif_regs beagle_x15_emif1_ddr3_532mhz_emif_regs = {
Keerthy66dd8062016-05-24 11:45:07 +0530134 .sdram_config_init = 0x61851b32,
135 .sdram_config = 0x61851b32,
136 .sdram_config2 = 0x08000000,
137 .ref_ctrl = 0x000040F1,
138 .ref_ctrl_final = 0x00001035,
139 .sdram_tim1 = 0xcccf36ab,
140 .sdram_tim2 = 0x308f7fda,
141 .sdram_tim3 = 0x409f88a8,
142 .read_idle_ctrl = 0x00050000,
143 .zq_config = 0x5007190b,
144 .temp_alert_config = 0x00000000,
Wolfgang Denk62fb2b42021-09-27 17:42:39 +0200145 .emif_ddr_phy_ctlr_1_init = 0x0024400b,
Keerthy66dd8062016-05-24 11:45:07 +0530146 .emif_ddr_phy_ctlr_1 = 0x0e24400b,
Wolfgang Denk62fb2b42021-09-27 17:42:39 +0200147 .emif_ddr_ext_phy_ctrl_1 = 0x10040100,
148 .emif_ddr_ext_phy_ctrl_2 = 0x00910091,
149 .emif_ddr_ext_phy_ctrl_3 = 0x00950095,
150 .emif_ddr_ext_phy_ctrl_4 = 0x009b009b,
151 .emif_ddr_ext_phy_ctrl_5 = 0x009e009e,
Keerthy66dd8062016-05-24 11:45:07 +0530152 .emif_rd_wr_lvl_rmp_win = 0x00000000,
153 .emif_rd_wr_lvl_rmp_ctl = 0x80000000,
154 .emif_rd_wr_lvl_ctl = 0x00000000,
155 .emif_rd_wr_exec_thresh = 0x00000305
Felipe Balbi4750eb62014-11-10 14:02:44 -0600156};
157
Lokesh Vutla979d2c32015-06-03 14:43:21 +0530158/* Ext phy ctrl regs 1-35 */
Felipe Balbi4750eb62014-11-10 14:02:44 -0600159static const u32 beagle_x15_emif1_ddr3_ext_phy_ctrl_const_regs[] = {
Lokesh Vutla979d2c32015-06-03 14:43:21 +0530160 0x10040100,
Lokesh Vutla306b5972016-03-08 09:11:35 +0530161 0x00910091,
162 0x00950095,
163 0x009B009B,
164 0x009E009E,
165 0x00980098,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600166 0x00340034,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600167 0x00350035,
Lokesh Vutla306b5972016-03-08 09:11:35 +0530168 0x00340034,
169 0x00310031,
170 0x00340034,
171 0x007F007F,
172 0x007F007F,
173 0x007F007F,
174 0x007F007F,
175 0x007F007F,
176 0x00480048,
177 0x004A004A,
178 0x00520052,
179 0x00550055,
180 0x00500050,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600181 0x00000000,
182 0x00600020,
Lokesh Vutla979d2c32015-06-03 14:43:21 +0530183 0x40011080,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600184 0x08102040,
Lokesh Vutla306b5972016-03-08 09:11:35 +0530185 0x0,
186 0x0,
187 0x0,
188 0x0,
Lokesh Vutla51a0f1f2015-06-03 14:43:22 +0530189 0x0,
190 0x0,
191 0x0,
192 0x0,
Lokesh Vutla306b5972016-03-08 09:11:35 +0530193 0x0,
Lokesh Vutla51a0f1f2015-06-03 14:43:22 +0530194 0x0
Felipe Balbi4750eb62014-11-10 14:02:44 -0600195};
196
197static const struct emif_regs beagle_x15_emif2_ddr3_532mhz_emif_regs = {
Keerthy66dd8062016-05-24 11:45:07 +0530198 .sdram_config_init = 0x61851b32,
199 .sdram_config = 0x61851b32,
200 .sdram_config2 = 0x08000000,
201 .ref_ctrl = 0x000040F1,
202 .ref_ctrl_final = 0x00001035,
203 .sdram_tim1 = 0xcccf36b3,
204 .sdram_tim2 = 0x308f7fda,
205 .sdram_tim3 = 0x407f88a8,
206 .read_idle_ctrl = 0x00050000,
207 .zq_config = 0x5007190b,
208 .temp_alert_config = 0x00000000,
Wolfgang Denk62fb2b42021-09-27 17:42:39 +0200209 .emif_ddr_phy_ctlr_1_init = 0x0024400b,
Keerthy66dd8062016-05-24 11:45:07 +0530210 .emif_ddr_phy_ctlr_1 = 0x0e24400b,
Wolfgang Denk62fb2b42021-09-27 17:42:39 +0200211 .emif_ddr_ext_phy_ctrl_1 = 0x10040100,
212 .emif_ddr_ext_phy_ctrl_2 = 0x00910091,
213 .emif_ddr_ext_phy_ctrl_3 = 0x00950095,
214 .emif_ddr_ext_phy_ctrl_4 = 0x009b009b,
215 .emif_ddr_ext_phy_ctrl_5 = 0x009e009e,
Keerthy66dd8062016-05-24 11:45:07 +0530216 .emif_rd_wr_lvl_rmp_win = 0x00000000,
217 .emif_rd_wr_lvl_rmp_ctl = 0x80000000,
218 .emif_rd_wr_lvl_ctl = 0x00000000,
219 .emif_rd_wr_exec_thresh = 0x00000305
Felipe Balbi4750eb62014-11-10 14:02:44 -0600220};
221
222static const u32 beagle_x15_emif2_ddr3_ext_phy_ctrl_const_regs[] = {
Lokesh Vutla979d2c32015-06-03 14:43:21 +0530223 0x10040100,
Lokesh Vutla306b5972016-03-08 09:11:35 +0530224 0x00910091,
225 0x00950095,
226 0x009B009B,
227 0x009E009E,
228 0x00980098,
229 0x00340034,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600230 0x00350035,
Lokesh Vutla306b5972016-03-08 09:11:35 +0530231 0x00340034,
232 0x00310031,
233 0x00340034,
234 0x007F007F,
235 0x007F007F,
236 0x007F007F,
237 0x007F007F,
238 0x007F007F,
239 0x00480048,
240 0x004A004A,
241 0x00520052,
242 0x00550055,
243 0x00500050,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600244 0x00000000,
245 0x00600020,
Lokesh Vutla979d2c32015-06-03 14:43:21 +0530246 0x40011080,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600247 0x08102040,
Lokesh Vutla306b5972016-03-08 09:11:35 +0530248 0x0,
249 0x0,
250 0x0,
251 0x0,
252 0x0,
Lokesh Vutla51a0f1f2015-06-03 14:43:22 +0530253 0x0,
254 0x0,
255 0x0,
256 0x0,
257 0x0
Felipe Balbi4750eb62014-11-10 14:02:44 -0600258};
259
Steve Kipisz81c46742017-08-22 13:52:58 +0530260static const struct emif_regs am571x_emif1_ddr3_666mhz_emif_regs = {
261 .sdram_config_init = 0x61863332,
262 .sdram_config = 0x61863332,
263 .sdram_config2 = 0x08000000,
264 .ref_ctrl = 0x0000514d,
265 .ref_ctrl_final = 0x0000144a,
266 .sdram_tim1 = 0xd333887c,
Lokesh Vutlacbd70db2017-12-29 11:47:54 +0530267 .sdram_tim2 = 0x30b37fe3,
268 .sdram_tim3 = 0x409f8ad8,
Steve Kipisz81c46742017-08-22 13:52:58 +0530269 .read_idle_ctrl = 0x00050000,
270 .zq_config = 0x5007190b,
271 .temp_alert_config = 0x00000000,
272 .emif_ddr_phy_ctlr_1_init = 0x0024400f,
273 .emif_ddr_phy_ctlr_1 = 0x0e24400f,
274 .emif_ddr_ext_phy_ctrl_1 = 0x10040100,
275 .emif_ddr_ext_phy_ctrl_2 = 0x00910091,
276 .emif_ddr_ext_phy_ctrl_3 = 0x00950095,
277 .emif_ddr_ext_phy_ctrl_4 = 0x009b009b,
278 .emif_ddr_ext_phy_ctrl_5 = 0x009e009e,
279 .emif_rd_wr_lvl_rmp_win = 0x00000000,
280 .emif_rd_wr_lvl_rmp_ctl = 0x80000000,
281 .emif_rd_wr_lvl_ctl = 0x00000000,
282 .emif_rd_wr_exec_thresh = 0x00000305
283};
284
Lokesh Vutlacbd70db2017-12-29 11:47:54 +0530285static const struct emif_regs am574x_emif1_ddr3_666mhz_emif_ecc_regs = {
286 .sdram_config_init = 0x61863332,
287 .sdram_config = 0x61863332,
288 .sdram_config2 = 0x08000000,
289 .ref_ctrl = 0x0000514d,
290 .ref_ctrl_final = 0x0000144a,
291 .sdram_tim1 = 0xd333887c,
292 .sdram_tim2 = 0x30b37fe3,
293 .sdram_tim3 = 0x409f8ad8,
294 .read_idle_ctrl = 0x00050000,
295 .zq_config = 0x5007190b,
296 .temp_alert_config = 0x00000000,
297 .emif_ddr_phy_ctlr_1_init = 0x0024400f,
298 .emif_ddr_phy_ctlr_1 = 0x0e24400f,
299 .emif_ddr_ext_phy_ctrl_1 = 0x10040100,
300 .emif_ddr_ext_phy_ctrl_2 = 0x00910091,
301 .emif_ddr_ext_phy_ctrl_3 = 0x00950095,
302 .emif_ddr_ext_phy_ctrl_4 = 0x009b009b,
303 .emif_ddr_ext_phy_ctrl_5 = 0x009e009e,
304 .emif_rd_wr_lvl_rmp_win = 0x00000000,
305 .emif_rd_wr_lvl_rmp_ctl = 0x80000000,
306 .emif_rd_wr_lvl_ctl = 0x00000000,
307 .emif_rd_wr_exec_thresh = 0x00000305,
308 .emif_ecc_ctrl_reg = 0xD0000001,
309 .emif_ecc_address_range_1 = 0x3FFF0000,
310 .emif_ecc_address_range_2 = 0x00000000
311};
312
Felipe Balbi4750eb62014-11-10 14:02:44 -0600313void emif_get_reg_dump(u32 emif_nr, const struct emif_regs **regs)
314{
315 switch (emif_nr) {
316 case 1:
Steve Kipisz81c46742017-08-22 13:52:58 +0530317 if (board_is_am571x_idk())
318 *regs = &am571x_emif1_ddr3_666mhz_emif_regs;
Lokesh Vutlacbd70db2017-12-29 11:47:54 +0530319 else if (board_is_am574x_idk())
320 *regs = &am574x_emif1_ddr3_666mhz_emif_ecc_regs;
Steve Kipisz81c46742017-08-22 13:52:58 +0530321 else
322 *regs = &beagle_x15_emif1_ddr3_532mhz_emif_regs;
Felipe Balbi4750eb62014-11-10 14:02:44 -0600323 break;
324 case 2:
Lokesh Vutlacbd70db2017-12-29 11:47:54 +0530325 if (board_is_am574x_idk())
326 *regs = &am571x_emif1_ddr3_666mhz_emif_regs;
327 else
328 *regs = &beagle_x15_emif2_ddr3_532mhz_emif_regs;
Felipe Balbi4750eb62014-11-10 14:02:44 -0600329 break;
330 }
331}
332
333void emif_get_ext_phy_ctrl_const_regs(u32 emif_nr, const u32 **regs, u32 *size)
334{
335 switch (emif_nr) {
336 case 1:
337 *regs = beagle_x15_emif1_ddr3_ext_phy_ctrl_const_regs;
338 *size = ARRAY_SIZE(beagle_x15_emif1_ddr3_ext_phy_ctrl_const_regs);
339 break;
340 case 2:
341 *regs = beagle_x15_emif2_ddr3_ext_phy_ctrl_const_regs;
342 *size = ARRAY_SIZE(beagle_x15_emif2_ddr3_ext_phy_ctrl_const_regs);
343 break;
344 }
345}
346
347struct vcores_data beagle_x15_volts = {
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530348 .mpu.value[OPP_NOM] = VDD_MPU_DRA7_NOM,
349 .mpu.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_MPU_NOM,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600350 .mpu.efuse.reg_bits = DRA752_EFUSE_REGBITS,
351 .mpu.addr = TPS659038_REG_ADDR_SMPS12,
352 .mpu.pmic = &tps659038,
Keerthy66dd8062016-05-24 11:45:07 +0530353 .mpu.abb_tx_done_mask = OMAP_ABB_MPU_TXDONE_MASK,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600354
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530355 .eve.value[OPP_NOM] = VDD_EVE_DRA7_NOM,
356 .eve.value[OPP_OD] = VDD_EVE_DRA7_OD,
357 .eve.value[OPP_HIGH] = VDD_EVE_DRA7_HIGH,
358 .eve.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_DSPEVE_NOM,
359 .eve.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_DSPEVE_OD,
360 .eve.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_DSPEVE_HIGH,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600361 .eve.efuse.reg_bits = DRA752_EFUSE_REGBITS,
362 .eve.addr = TPS659038_REG_ADDR_SMPS45,
363 .eve.pmic = &tps659038,
Nishanth Menon59b92af2016-04-21 14:34:25 -0500364 .eve.abb_tx_done_mask = OMAP_ABB_EVE_TXDONE_MASK,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600365
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530366 .gpu.value[OPP_NOM] = VDD_GPU_DRA7_NOM,
367 .gpu.value[OPP_OD] = VDD_GPU_DRA7_OD,
368 .gpu.value[OPP_HIGH] = VDD_GPU_DRA7_HIGH,
369 .gpu.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_GPU_NOM,
370 .gpu.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_GPU_OD,
371 .gpu.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_GPU_HIGH,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600372 .gpu.efuse.reg_bits = DRA752_EFUSE_REGBITS,
373 .gpu.addr = TPS659038_REG_ADDR_SMPS45,
374 .gpu.pmic = &tps659038,
Nishanth Menon59b92af2016-04-21 14:34:25 -0500375 .gpu.abb_tx_done_mask = OMAP_ABB_GPU_TXDONE_MASK,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600376
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530377 .core.value[OPP_NOM] = VDD_CORE_DRA7_NOM,
378 .core.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_CORE_NOM,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600379 .core.efuse.reg_bits = DRA752_EFUSE_REGBITS,
380 .core.addr = TPS659038_REG_ADDR_SMPS6,
381 .core.pmic = &tps659038,
382
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530383 .iva.value[OPP_NOM] = VDD_IVA_DRA7_NOM,
384 .iva.value[OPP_OD] = VDD_IVA_DRA7_OD,
385 .iva.value[OPP_HIGH] = VDD_IVA_DRA7_HIGH,
386 .iva.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_IVA_NOM,
387 .iva.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_IVA_OD,
388 .iva.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_IVA_HIGH,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600389 .iva.efuse.reg_bits = DRA752_EFUSE_REGBITS,
390 .iva.addr = TPS659038_REG_ADDR_SMPS45,
391 .iva.pmic = &tps659038,
Nishanth Menon59b92af2016-04-21 14:34:25 -0500392 .iva.abb_tx_done_mask = OMAP_ABB_IVA_TXDONE_MASK,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600393};
394
Keerthy152e9932016-05-24 11:45:06 +0530395struct vcores_data am572x_idk_volts = {
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530396 .mpu.value[OPP_NOM] = VDD_MPU_DRA7_NOM,
397 .mpu.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_MPU_NOM,
Keerthy152e9932016-05-24 11:45:06 +0530398 .mpu.efuse.reg_bits = DRA752_EFUSE_REGBITS,
399 .mpu.addr = TPS659038_REG_ADDR_SMPS12,
400 .mpu.pmic = &tps659038,
401 .mpu.abb_tx_done_mask = OMAP_ABB_MPU_TXDONE_MASK,
402
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530403 .eve.value[OPP_NOM] = VDD_EVE_DRA7_NOM,
404 .eve.value[OPP_OD] = VDD_EVE_DRA7_OD,
405 .eve.value[OPP_HIGH] = VDD_EVE_DRA7_HIGH,
406 .eve.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_DSPEVE_NOM,
407 .eve.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_DSPEVE_OD,
408 .eve.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_DSPEVE_HIGH,
Keerthy152e9932016-05-24 11:45:06 +0530409 .eve.efuse.reg_bits = DRA752_EFUSE_REGBITS,
410 .eve.addr = TPS659038_REG_ADDR_SMPS45,
411 .eve.pmic = &tps659038,
412 .eve.abb_tx_done_mask = OMAP_ABB_EVE_TXDONE_MASK,
413
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530414 .gpu.value[OPP_NOM] = VDD_GPU_DRA7_NOM,
415 .gpu.value[OPP_OD] = VDD_GPU_DRA7_OD,
416 .gpu.value[OPP_HIGH] = VDD_GPU_DRA7_HIGH,
417 .gpu.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_GPU_NOM,
418 .gpu.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_GPU_OD,
419 .gpu.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_GPU_HIGH,
Keerthy152e9932016-05-24 11:45:06 +0530420 .gpu.efuse.reg_bits = DRA752_EFUSE_REGBITS,
421 .gpu.addr = TPS659038_REG_ADDR_SMPS6,
422 .gpu.pmic = &tps659038,
423 .gpu.abb_tx_done_mask = OMAP_ABB_GPU_TXDONE_MASK,
424
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530425 .core.value[OPP_NOM] = VDD_CORE_DRA7_NOM,
426 .core.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_CORE_NOM,
Keerthy152e9932016-05-24 11:45:06 +0530427 .core.efuse.reg_bits = DRA752_EFUSE_REGBITS,
428 .core.addr = TPS659038_REG_ADDR_SMPS7,
429 .core.pmic = &tps659038,
430
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530431 .iva.value[OPP_NOM] = VDD_IVA_DRA7_NOM,
432 .iva.value[OPP_OD] = VDD_IVA_DRA7_OD,
433 .iva.value[OPP_HIGH] = VDD_IVA_DRA7_HIGH,
434 .iva.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_IVA_NOM,
435 .iva.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_IVA_OD,
436 .iva.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_IVA_HIGH,
Keerthy152e9932016-05-24 11:45:06 +0530437 .iva.efuse.reg_bits = DRA752_EFUSE_REGBITS,
438 .iva.addr = TPS659038_REG_ADDR_SMPS8,
439 .iva.pmic = &tps659038,
440 .iva.abb_tx_done_mask = OMAP_ABB_IVA_TXDONE_MASK,
441};
442
Keerthy9cc2aee2017-05-25 15:37:34 +0530443struct vcores_data am571x_idk_volts = {
444 .mpu.value[OPP_NOM] = VDD_MPU_DRA7_NOM,
445 .mpu.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_MPU_NOM,
446 .mpu.efuse.reg_bits = DRA752_EFUSE_REGBITS,
447 .mpu.addr = TPS659038_REG_ADDR_SMPS12,
448 .mpu.pmic = &tps659038,
449 .mpu.abb_tx_done_mask = OMAP_ABB_MPU_TXDONE_MASK,
450
451 .eve.value[OPP_NOM] = VDD_EVE_DRA7_NOM,
452 .eve.value[OPP_OD] = VDD_EVE_DRA7_OD,
453 .eve.value[OPP_HIGH] = VDD_EVE_DRA7_HIGH,
454 .eve.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_DSPEVE_NOM,
455 .eve.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_DSPEVE_OD,
456 .eve.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_DSPEVE_HIGH,
457 .eve.efuse.reg_bits = DRA752_EFUSE_REGBITS,
458 .eve.addr = TPS659038_REG_ADDR_SMPS45,
459 .eve.pmic = &tps659038,
460 .eve.abb_tx_done_mask = OMAP_ABB_EVE_TXDONE_MASK,
461
462 .gpu.value[OPP_NOM] = VDD_GPU_DRA7_NOM,
463 .gpu.value[OPP_OD] = VDD_GPU_DRA7_OD,
464 .gpu.value[OPP_HIGH] = VDD_GPU_DRA7_HIGH,
465 .gpu.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_GPU_NOM,
466 .gpu.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_GPU_OD,
467 .gpu.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_GPU_HIGH,
468 .gpu.efuse.reg_bits = DRA752_EFUSE_REGBITS,
469 .gpu.addr = TPS659038_REG_ADDR_SMPS6,
470 .gpu.pmic = &tps659038,
471 .gpu.abb_tx_done_mask = OMAP_ABB_GPU_TXDONE_MASK,
472
473 .core.value[OPP_NOM] = VDD_CORE_DRA7_NOM,
474 .core.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_CORE_NOM,
475 .core.efuse.reg_bits = DRA752_EFUSE_REGBITS,
476 .core.addr = TPS659038_REG_ADDR_SMPS7,
477 .core.pmic = &tps659038,
478
479 .iva.value[OPP_NOM] = VDD_IVA_DRA7_NOM,
480 .iva.value[OPP_OD] = VDD_IVA_DRA7_OD,
481 .iva.value[OPP_HIGH] = VDD_IVA_DRA7_HIGH,
482 .iva.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_IVA_NOM,
483 .iva.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_IVA_OD,
484 .iva.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_IVA_HIGH,
485 .iva.efuse.reg_bits = DRA752_EFUSE_REGBITS,
486 .iva.addr = TPS659038_REG_ADDR_SMPS45,
487 .iva.pmic = &tps659038,
488 .iva.abb_tx_done_mask = OMAP_ABB_IVA_TXDONE_MASK,
489};
490
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530491int get_voltrail_opp(int rail_offset)
492{
493 int opp;
494
495 switch (rail_offset) {
496 case VOLT_MPU:
497 opp = DRA7_MPU_OPP;
498 break;
499 case VOLT_CORE:
500 opp = DRA7_CORE_OPP;
501 break;
502 case VOLT_GPU:
503 opp = DRA7_GPU_OPP;
504 break;
505 case VOLT_EVE:
506 opp = DRA7_DSPEVE_OPP;
507 break;
508 case VOLT_IVA:
509 opp = DRA7_IVA_OPP;
510 break;
511 default:
512 opp = OPP_NOM;
513 }
514
515 return opp;
516}
517
Kipisz, Steven161f1382016-02-24 12:30:58 -0600518#ifdef CONFIG_SPL_BUILD
519/* No env to setup for SPL */
520static inline void setup_board_eeprom_env(void) { }
521
522/* Override function to read eeprom information */
523void do_board_detect(void)
524{
525 int rc;
526
527 rc = ti_i2c_eeprom_am_get(CONFIG_EEPROM_BUS_ADDRESS,
528 CONFIG_EEPROM_CHIP_ADDRESS);
529 if (rc)
530 printf("ti_i2c_eeprom_init failed %d\n", rc);
Caleb Robey0dfcc932020-01-02 08:17:25 -0600531
532#ifdef CONFIG_SUPPORT_EMMC_BOOT
533 rc = board_bootmode_has_emmc();
534 if (!rc)
535 rc = ti_emmc_boardid_get();
536 if (rc)
537 printf("ti_emmc_boardid_get failed %d\n", rc);
538#endif
Kipisz, Steven161f1382016-02-24 12:30:58 -0600539}
540
541#else /* CONFIG_SPL_BUILD */
542
543/* Override function to read eeprom information: actual i2c read done by SPL*/
544void do_board_detect(void)
545{
546 char *bname = NULL;
547 int rc;
548
549 rc = ti_i2c_eeprom_am_get(CONFIG_EEPROM_BUS_ADDRESS,
550 CONFIG_EEPROM_CHIP_ADDRESS);
551 if (rc)
552 printf("ti_i2c_eeprom_init failed %d\n", rc);
553
Caleb Robey0dfcc932020-01-02 08:17:25 -0600554#ifdef CONFIG_SUPPORT_EMMC_BOOT
555 rc = board_bootmode_has_emmc();
556 if (!rc)
557 rc = ti_emmc_boardid_get();
558 if (rc)
559 printf("ti_emmc_boardid_get failed %d\n", rc);
560#endif
561
Kipisz, Steven161f1382016-02-24 12:30:58 -0600562 if (board_is_x15())
563 bname = "BeagleBoard X15";
564 else if (board_is_am572x_evm())
565 bname = "AM572x EVM";
Lokesh Vutla374aea02017-12-29 11:47:52 +0530566 else if (board_is_am574x_idk())
567 bname = "AM574x IDK";
Steve Kipisz0ac8cea2016-04-08 17:01:29 -0500568 else if (board_is_am572x_idk())
569 bname = "AM572x IDK";
Steve Kipiszc95cddd2016-11-25 11:14:24 +0530570 else if (board_is_am571x_idk())
571 bname = "AM571x IDK";
Caleb Robey940d6372020-01-02 08:17:27 -0600572 else if (board_is_bbai())
573 bname = "BeagleBone AI";
Kipisz, Steven161f1382016-02-24 12:30:58 -0600574
575 if (bname)
576 snprintf(sysinfo.board_string, SYSINFO_BOARD_NAME_MAX_LEN,
577 "Board: %s REV %s\n", bname, board_ti_get_rev());
578}
579
580static void setup_board_eeprom_env(void)
581{
582 char *name = "beagle_x15";
583 int rc;
584
585 rc = ti_i2c_eeprom_am_get(CONFIG_EEPROM_BUS_ADDRESS,
586 CONFIG_EEPROM_CHIP_ADDRESS);
587 if (rc)
588 goto invalid_eeprom;
589
Nishanth Menona2aea1c2016-11-25 11:14:19 +0530590 if (board_is_x15()) {
Lokesh Vutla638e1c02016-11-25 11:14:20 +0530591 if (board_is_x15_revb1())
592 name = "beagle_x15_revb1";
Lokesh Vutla816178b2017-07-16 19:59:19 +0530593 else if (board_is_x15_revc())
594 name = "beagle_x15_revc";
Lokesh Vutla638e1c02016-11-25 11:14:20 +0530595 else
596 name = "beagle_x15";
Nishanth Menona2aea1c2016-11-25 11:14:19 +0530597 } else if (board_is_am572x_evm()) {
598 if (board_is_am572x_evm_reva3())
599 name = "am57xx_evm_reva3";
600 else
601 name = "am57xx_evm";
Lokesh Vutla374aea02017-12-29 11:47:52 +0530602 } else if (board_is_am574x_idk()) {
603 name = "am574x_idk";
Nishanth Menona2aea1c2016-11-25 11:14:19 +0530604 } else if (board_is_am572x_idk()) {
Steve Kipisz0ac8cea2016-04-08 17:01:29 -0500605 name = "am572x_idk";
Steve Kipiszc95cddd2016-11-25 11:14:24 +0530606 } else if (board_is_am571x_idk()) {
607 name = "am571x_idk";
Caleb Robey940d6372020-01-02 08:17:27 -0600608 } else if (board_is_bbai()) {
609 name = "am5729_beagleboneai";
Nishanth Menona2aea1c2016-11-25 11:14:19 +0530610 } else {
Kipisz, Steven161f1382016-02-24 12:30:58 -0600611 printf("Unidentified board claims %s in eeprom header\n",
612 board_ti_get_name());
Nishanth Menona2aea1c2016-11-25 11:14:19 +0530613 }
Kipisz, Steven161f1382016-02-24 12:30:58 -0600614
615invalid_eeprom:
616 set_board_info_env(name);
617}
618
619#endif /* CONFIG_SPL_BUILD */
620
Keerthy152e9932016-05-24 11:45:06 +0530621void vcores_init(void)
622{
Lokesh Vutla6e9635c2017-12-29 11:47:53 +0530623 if (board_is_am572x_idk() || board_is_am574x_idk())
Keerthy152e9932016-05-24 11:45:06 +0530624 *omap_vcores = &am572x_idk_volts;
Keerthy9cc2aee2017-05-25 15:37:34 +0530625 else if (board_is_am571x_idk())
626 *omap_vcores = &am571x_idk_volts;
Keerthy152e9932016-05-24 11:45:06 +0530627 else
628 *omap_vcores = &beagle_x15_volts;
629}
630
Felipe Balbi4750eb62014-11-10 14:02:44 -0600631void hw_data_init(void)
632{
633 *prcm = &dra7xx_prcm;
Steve Kipisz81c46742017-08-22 13:52:58 +0530634 if (is_dra72x())
635 *dplls_data = &dra72x_dplls;
Lokesh Vutla6e9635c2017-12-29 11:47:53 +0530636 else if (is_dra76x())
637 *dplls_data = &dra76x_dplls;
Steve Kipisz81c46742017-08-22 13:52:58 +0530638 else
639 *dplls_data = &dra7xx_dplls;
Felipe Balbi4750eb62014-11-10 14:02:44 -0600640 *ctrl = &dra7xx_ctrl;
641}
642
Roger Quadros26130592017-03-13 15:04:28 +0200643bool am571x_idk_needs_lcd(void)
644{
645 bool needs_lcd;
646
647 gpio_request(GPIO_ETH_LCD, "nLCD_Detect");
648 if (gpio_get_value(GPIO_ETH_LCD))
649 needs_lcd = false;
650 else
651 needs_lcd = true;
652
653 gpio_free(GPIO_ETH_LCD);
654
655 return needs_lcd;
656}
657
Felipe Balbi4750eb62014-11-10 14:02:44 -0600658int board_init(void)
659{
660 gpmc_init();
Tom Rinibb4dd962022-11-16 13:10:37 -0500661 gd->bd->bi_boot_params = (CFG_SYS_SDRAM_BASE + 0x100);
Felipe Balbi4750eb62014-11-10 14:02:44 -0600662
663 return 0;
664}
665
Nishanth Menond0f399c2017-03-13 15:04:30 +0200666void am57x_idk_lcd_detect(void)
Felipe Balbi4750eb62014-11-10 14:02:44 -0600667{
Nishanth Menond0f399c2017-03-13 15:04:30 +0200668 int r = -ENODEV;
669 char *idk_lcd = "no";
Jean-Jacques Hiblot184ec9a2018-12-07 14:50:50 +0100670 struct udevice *dev;
Nishanth Menond0f399c2017-03-13 15:04:30 +0200671
672 /* Only valid for IDKs */
Luca Ceresoli93f6bc22020-05-21 15:06:25 +0200673 if (!board_is_ti_idk())
Nishanth Menond0f399c2017-03-13 15:04:30 +0200674 return;
675
676 /* Only AM571x IDK has gpio control detect.. so check that */
677 if (board_is_am571x_idk() && !am571x_idk_needs_lcd())
678 goto out;
679
Jean-Jacques Hiblot52a51512018-12-07 14:50:49 +0100680 r = i2c_get_chip_for_busnum(OSD_TS_FT_BUS_ADDRESS,
681 OSD_TS_FT_CHIP_ADDRESS, 1, &dev);
Nishanth Menond0f399c2017-03-13 15:04:30 +0200682 if (r) {
Jean-Jacques Hiblot52a51512018-12-07 14:50:49 +0100683 printf("%s: Failed to get I2C device %d/%d (ret %d)\n",
684 __func__, OSD_TS_FT_BUS_ADDRESS, OSD_TS_FT_CHIP_ADDRESS,
685 r);
Nishanth Menond0f399c2017-03-13 15:04:30 +0200686 /* AM572x IDK has no explicit settings for optional LCD kit */
Jean-Jacques Hiblot52a51512018-12-07 14:50:49 +0100687 if (board_is_am571x_idk())
Nishanth Menond0f399c2017-03-13 15:04:30 +0200688 printf("%s: Touch screen detect failed: %d!\n",
689 __func__, r);
Nishanth Menond0f399c2017-03-13 15:04:30 +0200690 goto out;
691 }
692
693 /* Read FT ID */
Jean-Jacques Hiblot52a51512018-12-07 14:50:49 +0100694 r = dm_i2c_reg_read(dev, OSD_TS_FT_REG_ID);
695 if (r < 0) {
Nishanth Menond0f399c2017-03-13 15:04:30 +0200696 printf("%s: Touch screen ID read %d:0x%02x[0x%02x] failed:%d\n",
697 __func__, OSD_TS_FT_BUS_ADDRESS, OSD_TS_FT_CHIP_ADDRESS,
698 OSD_TS_FT_REG_ID, r);
699 goto out;
700 }
701
Jean-Jacques Hiblot184ec9a2018-12-07 14:50:50 +0100702 switch (r) {
Nishanth Menond0f399c2017-03-13 15:04:30 +0200703 case OSD_TS_FT_ID_5606:
704 idk_lcd = "osd101t2045";
705 break;
706 case OSD_TS_FT_ID_5x46:
707 idk_lcd = "osd101t2587";
708 break;
709 default:
710 printf("%s: Unidentifed Touch screen ID 0x%02x\n",
Jean-Jacques Hiblot184ec9a2018-12-07 14:50:50 +0100711 __func__, r);
Nishanth Menond0f399c2017-03-13 15:04:30 +0200712 /* we will let default be "no lcd" */
713 }
714out:
Simon Glass6a38e412017-08-03 12:22:09 -0600715 env_set("idk_lcd", idk_lcd);
Roger Quadros8835eee2020-02-10 11:59:24 +0200716
717 /*
718 * On AM571x_IDK, no Display with J51 set to LCD is considered as an
719 * invalid configuration and we prevent boot to get user attention.
720 */
721 if (board_is_am571x_idk() && am571x_idk_needs_lcd() &&
722 !strncmp(idk_lcd, "no", 2)) {
723 printf("%s: Invalid HW configuration: display not detected/supported but J51 is set. Remove J51 to boot without display.\n",
724 __func__);
725 hang();
726 }
727
Nishanth Menond0f399c2017-03-13 15:04:30 +0200728 return;
729}
Roger Quadros26130592017-03-13 15:04:28 +0200730
Vignesh R98c5f632018-11-29 10:57:42 +0100731#if CONFIG_IS_ENABLED(DM_USB) && CONFIG_IS_ENABLED(OF_CONTROL)
732static int device_okay(const char *path)
733{
734 int node;
735
736 node = fdt_path_offset(gd->fdt_blob, path);
737 if (node < 0)
738 return 0;
739
740 return fdtdec_get_is_enabled(gd->fdt_blob, node);
741}
742#endif
743
Nishanth Menond0f399c2017-03-13 15:04:30 +0200744int board_late_init(void)
745{
Kipisz, Steven161f1382016-02-24 12:30:58 -0600746 setup_board_eeprom_env();
Keerthyee85ebe2016-11-30 15:02:53 +0530747 u8 val;
Tero Kristodfbc6b82019-09-27 19:14:27 +0300748 struct udevice *dev;
Kipisz, Steven161f1382016-02-24 12:30:58 -0600749
Felipe Balbi4750eb62014-11-10 14:02:44 -0600750 /*
751 * DEV_CTRL.DEV_ON = 1 please - else palmas switches off in 8 seconds
752 * This is the POWERHOLD-in-Low behavior.
753 */
754 palmas_i2c_write_u8(TPS65903X_CHIP_P1, 0xA0, 0x1);
Lokesh Vutla2c47e8c2016-11-29 11:58:02 +0530755
756 /*
757 * Default FIT boot on HS devices. Non FIT images are not allowed
758 * on HS devices.
759 */
760 if (get_device_type() == HS_DEVICE)
Simon Glass6a38e412017-08-03 12:22:09 -0600761 env_set("boot_fit", "1");
Lokesh Vutla2c47e8c2016-11-29 11:58:02 +0530762
Keerthyee85ebe2016-11-30 15:02:53 +0530763 /*
764 * Set the GPIO7 Pad to POWERHOLD. This has higher priority
765 * over DEV_CTRL.DEV_ON bit. This can be reset in case of
766 * PMIC Power off. So to be on the safer side set it back
767 * to POWERHOLD mode irrespective of the current state.
768 */
769 palmas_i2c_read_u8(TPS65903X_CHIP_P1, TPS65903X_PRIMARY_SECONDARY_PAD2,
770 &val);
771 val = val | TPS65903X_PAD2_POWERHOLD_MASK;
772 palmas_i2c_write_u8(TPS65903X_CHIP_P1, TPS65903X_PRIMARY_SECONDARY_PAD2,
773 val);
774
Semen Protsenko4b0721f2017-02-13 19:09:37 +0200775 omap_die_id_serial();
Semen Protsenkob72dccd2017-05-22 19:16:41 +0300776 omap_set_fastboot_vars();
Semen Protsenko4b0721f2017-02-13 19:09:37 +0200777
Nishanth Menond0f399c2017-03-13 15:04:30 +0200778 am57x_idk_lcd_detect();
Roger Quadros26130592017-03-13 15:04:28 +0200779
Tero Kristodfbc6b82019-09-27 19:14:27 +0300780 /* Just probe the potentially supported cdce913 device */
781 uclass_get_device(UCLASS_CLK, 0, &dev);
782
Caleb Robey940d6372020-01-02 08:17:27 -0600783 if (board_is_bbai())
784 env_set("console", "ttyS0,115200n8");
785
Roger Quadros26130592017-03-13 15:04:28 +0200786#if !defined(CONFIG_SPL_BUILD)
787 board_ti_set_ethaddr(2);
788#endif
789
Vignesh R98c5f632018-11-29 10:57:42 +0100790#if CONFIG_IS_ENABLED(DM_USB) && CONFIG_IS_ENABLED(OF_CONTROL)
791 if (device_okay("/ocp/omap_dwc3_1@48880000"))
792 enable_usb_clocks(0);
793 if (device_okay("/ocp/omap_dwc3_2@488c0000"))
794 enable_usb_clocks(1);
795#endif
Felipe Balbi4750eb62014-11-10 14:02:44 -0600796 return 0;
797}
798
Paul Kocialkowskia00b1e52016-02-27 19:18:56 +0100799void set_muxconf_regs(void)
Felipe Balbi4750eb62014-11-10 14:02:44 -0600800{
801 do_set_mux32((*ctrl)->control_padconf_core_base,
Lokesh Vutlac3d39f92015-06-04 16:42:41 +0530802 early_padconf, ARRAY_SIZE(early_padconf));
Caleb Robey0dfcc932020-01-02 08:17:25 -0600803
804#ifdef CONFIG_SUPPORT_EMMC_BOOT
805 do_set_mux32((*ctrl)->control_padconf_core_base,
806 emmc_padconf, ARRAY_SIZE(emmc_padconf));
807#endif
Felipe Balbi4750eb62014-11-10 14:02:44 -0600808}
809
Lokesh Vutlac3d39f92015-06-04 16:42:41 +0530810#ifdef CONFIG_IODELAY_RECALIBRATION
811void recalibrate_iodelay(void)
812{
Steve Kipisz0ac8cea2016-04-08 17:01:29 -0500813 const struct pad_conf_entry *pconf;
Lokesh Vutla3cb4c622017-06-05 14:48:16 +0530814 const struct iodelay_cfg_entry *iod, *delta_iod;
815 int pconf_sz, iod_sz, delta_iod_sz = 0;
Nishanth Menon8e3212e2016-11-25 11:14:22 +0530816 int ret;
Steve Kipisz0ac8cea2016-04-08 17:01:29 -0500817
Lokesh Vutla1e3425c2017-12-29 11:47:55 +0530818 if (board_is_am572x_idk()) {
Steve Kipisz0ac8cea2016-04-08 17:01:29 -0500819 pconf = core_padconf_array_essential_am572x_idk;
820 pconf_sz = ARRAY_SIZE(core_padconf_array_essential_am572x_idk);
821 iod = iodelay_cfg_array_am572x_idk;
822 iod_sz = ARRAY_SIZE(iodelay_cfg_array_am572x_idk);
Lokesh Vutla1e3425c2017-12-29 11:47:55 +0530823 } else if (board_is_am574x_idk()) {
824 pconf = core_padconf_array_essential_am574x_idk;
825 pconf_sz = ARRAY_SIZE(core_padconf_array_essential_am574x_idk);
826 iod = iodelay_cfg_array_am574x_idk;
827 iod_sz = ARRAY_SIZE(iodelay_cfg_array_am574x_idk);
Steve Kipiszc95cddd2016-11-25 11:14:24 +0530828 } else if (board_is_am571x_idk()) {
829 pconf = core_padconf_array_essential_am571x_idk;
830 pconf_sz = ARRAY_SIZE(core_padconf_array_essential_am571x_idk);
831 iod = iodelay_cfg_array_am571x_idk;
832 iod_sz = ARRAY_SIZE(iodelay_cfg_array_am571x_idk);
Caleb Robey940d6372020-01-02 08:17:27 -0600833 } else if (board_is_bbai()) {
834 pconf = core_padconf_array_essential_bbai;
835 pconf_sz = ARRAY_SIZE(core_padconf_array_essential_bbai);
836 iod = iodelay_cfg_array_bbai;
837 iod_sz = ARRAY_SIZE(iodelay_cfg_array_bbai);
Steve Kipisz0ac8cea2016-04-08 17:01:29 -0500838 } else {
839 /* Common for X15/GPEVM */
840 pconf = core_padconf_array_essential_x15;
841 pconf_sz = ARRAY_SIZE(core_padconf_array_essential_x15);
Nishanth Menon8e3212e2016-11-25 11:14:22 +0530842 /* There never was an SR1.0 X15.. So.. */
843 if (omap_revision() == DRA752_ES1_1) {
844 iod = iodelay_cfg_array_x15_sr1_1;
845 iod_sz = ARRAY_SIZE(iodelay_cfg_array_x15_sr1_1);
846 } else {
847 /* Since full production should switch to SR2.0 */
848 iod = iodelay_cfg_array_x15_sr2_0;
849 iod_sz = ARRAY_SIZE(iodelay_cfg_array_x15_sr2_0);
850 }
Steve Kipisz0ac8cea2016-04-08 17:01:29 -0500851 }
852
Nishanth Menon8e3212e2016-11-25 11:14:22 +0530853 /* Setup I/O isolation */
854 ret = __recalibrate_iodelay_start();
855 if (ret)
856 goto err;
857
858 /* Do the muxing here */
859 do_set_mux32((*ctrl)->control_padconf_core_base, pconf, pconf_sz);
860
861 /* Now do the weird minor deltas that should be safe */
862 if (board_is_x15() || board_is_am572x_evm()) {
Lokesh Vutla816178b2017-07-16 19:59:19 +0530863 if (board_is_x15_revb1() || board_is_am572x_evm_reva3() ||
864 board_is_x15_revc()) {
Nishanth Menon8e3212e2016-11-25 11:14:22 +0530865 pconf = core_padconf_array_delta_x15_sr2_0;
866 pconf_sz = ARRAY_SIZE(core_padconf_array_delta_x15_sr2_0);
867 } else {
868 pconf = core_padconf_array_delta_x15_sr1_1;
869 pconf_sz = ARRAY_SIZE(core_padconf_array_delta_x15_sr1_1);
870 }
871 do_set_mux32((*ctrl)->control_padconf_core_base, pconf, pconf_sz);
872 }
873
Roger Quadros26130592017-03-13 15:04:28 +0200874 if (board_is_am571x_idk()) {
875 if (am571x_idk_needs_lcd()) {
876 pconf = core_padconf_array_vout_am571x_idk;
877 pconf_sz = ARRAY_SIZE(core_padconf_array_vout_am571x_idk);
Lokesh Vutla3cb4c622017-06-05 14:48:16 +0530878 delta_iod = iodelay_cfg_array_am571x_idk_4port;
879 delta_iod_sz = ARRAY_SIZE(iodelay_cfg_array_am571x_idk_4port);
880
Roger Quadros26130592017-03-13 15:04:28 +0200881 } else {
882 pconf = core_padconf_array_icss1eth_am571x_idk;
883 pconf_sz = ARRAY_SIZE(core_padconf_array_icss1eth_am571x_idk);
884 }
885 do_set_mux32((*ctrl)->control_padconf_core_base, pconf, pconf_sz);
886 }
887
Nishanth Menon8e3212e2016-11-25 11:14:22 +0530888 /* Setup IOdelay configuration */
889 ret = do_set_iodelay((*ctrl)->iodelay_config_base, iod, iod_sz);
Lokesh Vutla3cb4c622017-06-05 14:48:16 +0530890 if (delta_iod_sz)
891 ret = do_set_iodelay((*ctrl)->iodelay_config_base, delta_iod,
892 delta_iod_sz);
893
Nishanth Menon8e3212e2016-11-25 11:14:22 +0530894err:
895 /* Closeup.. remove isolation */
896 __recalibrate_iodelay_end(ret);
Lokesh Vutlac3d39f92015-06-04 16:42:41 +0530897}
898#endif
899
Masahiro Yamada0a780172017-05-09 20:31:39 +0900900#if defined(CONFIG_MMC)
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900901int board_mmc_init(struct bd_info *bis)
Felipe Balbi4750eb62014-11-10 14:02:44 -0600902{
903 omap_mmc_init(0, 0, 0, -1, -1);
904 omap_mmc_init(1, 0, 0, -1, -1);
905 return 0;
906}
Kishon Vijay Abraham I110ed012018-01-30 16:01:52 +0100907
908static const struct mmc_platform_fixups am57x_es1_1_mmc1_fixups = {
909 .hw_rev = "rev11",
910 .unsupported_caps = MMC_CAP(MMC_HS_200) |
911 MMC_CAP(UHS_SDR104),
912 .max_freq = 96000000,
913};
914
915static const struct mmc_platform_fixups am57x_es1_1_mmc23_fixups = {
916 .hw_rev = "rev11",
917 .unsupported_caps = MMC_CAP(MMC_HS_200) |
918 MMC_CAP(UHS_SDR104) |
919 MMC_CAP(UHS_SDR50),
920 .max_freq = 48000000,
921};
922
923const struct mmc_platform_fixups *platform_fixups_mmc(uint32_t addr)
924{
925 switch (omap_revision()) {
926 case DRA752_ES1_0:
927 case DRA752_ES1_1:
928 if (addr == OMAP_HSMMC1_BASE)
929 return &am57x_es1_1_mmc1_fixups;
930 else
931 return &am57x_es1_1_mmc23_fixups;
932 default:
933 return NULL;
934 }
935}
Felipe Balbi4750eb62014-11-10 14:02:44 -0600936#endif
937
938#if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_OS_BOOT)
939int spl_start_uboot(void)
940{
941 /* break into full u-boot on 'c' */
942 if (serial_tstc() && serial_getc() == 'c')
943 return 1;
944
945#ifdef CONFIG_SPL_ENV_SUPPORT
946 env_init();
Simon Glass17539572017-08-03 12:22:07 -0600947 env_load();
Simon Glass22c34c22017-08-03 12:22:13 -0600948 if (env_get_yesno("boot_os") != 1)
Felipe Balbi4750eb62014-11-10 14:02:44 -0600949 return 1;
950#endif
951
952 return 0;
953}
954#endif
955
956#ifdef CONFIG_DRIVER_TI_CPSW
957
958/* Delay value to add to calibrated value */
959#define RGMII0_TXCTL_DLY_VAL ((0x3 << 5) + 0x8)
960#define RGMII0_TXD0_DLY_VAL ((0x3 << 5) + 0x8)
961#define RGMII0_TXD1_DLY_VAL ((0x3 << 5) + 0x2)
962#define RGMII0_TXD2_DLY_VAL ((0x4 << 5) + 0x0)
963#define RGMII0_TXD3_DLY_VAL ((0x4 << 5) + 0x0)
964#define VIN2A_D13_DLY_VAL ((0x3 << 5) + 0x8)
965#define VIN2A_D17_DLY_VAL ((0x3 << 5) + 0x8)
966#define VIN2A_D16_DLY_VAL ((0x3 << 5) + 0x2)
967#define VIN2A_D15_DLY_VAL ((0x4 << 5) + 0x0)
968#define VIN2A_D14_DLY_VAL ((0x4 << 5) + 0x0)
969
970static void cpsw_control(int enabled)
971{
972 /* VTP can be added here */
973}
974
975static struct cpsw_slave_data cpsw_slaves[] = {
976 {
977 .slave_reg_ofs = 0x208,
978 .sliver_reg_ofs = 0xd80,
979 .phy_addr = 1,
980 },
981 {
982 .slave_reg_ofs = 0x308,
983 .sliver_reg_ofs = 0xdc0,
984 .phy_addr = 2,
985 },
986};
987
988static struct cpsw_platform_data cpsw_data = {
989 .mdio_base = CPSW_MDIO_BASE,
990 .cpsw_base = CPSW_BASE,
991 .mdio_div = 0xff,
992 .channels = 8,
993 .cpdma_reg_ofs = 0x800,
994 .slaves = 1,
995 .slave_data = cpsw_slaves,
996 .ale_reg_ofs = 0xd00,
997 .ale_entries = 1024,
998 .host_port_reg_ofs = 0x108,
999 .hw_stats_reg_ofs = 0x900,
1000 .bd_ram_ofs = 0x2000,
1001 .mac_control = (1 << 5),
1002 .control = cpsw_control,
1003 .host_port_num = 0,
1004 .version = CPSW_CTRL_VERSION_2,
1005};
1006
Roger Quadros64217a22016-03-18 13:18:12 +02001007static u64 mac_to_u64(u8 mac[6])
1008{
1009 int i;
1010 u64 addr = 0;
1011
1012 for (i = 0; i < 6; i++) {
1013 addr <<= 8;
1014 addr |= mac[i];
1015 }
1016
1017 return addr;
1018}
1019
1020static void u64_to_mac(u64 addr, u8 mac[6])
1021{
1022 mac[5] = addr;
1023 mac[4] = addr >> 8;
1024 mac[3] = addr >> 16;
1025 mac[2] = addr >> 24;
1026 mac[1] = addr >> 32;
1027 mac[0] = addr >> 40;
1028}
1029
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +09001030int board_eth_init(struct bd_info *bis)
Felipe Balbi4750eb62014-11-10 14:02:44 -06001031{
1032 int ret;
1033 uint8_t mac_addr[6];
1034 uint32_t mac_hi, mac_lo;
1035 uint32_t ctrl_val;
Roger Quadros64217a22016-03-18 13:18:12 +02001036 int i;
1037 u64 mac1, mac2;
1038 u8 mac_addr1[6], mac_addr2[6];
1039 int num_macs;
Felipe Balbi4750eb62014-11-10 14:02:44 -06001040
1041 /* try reading mac address from efuse */
1042 mac_lo = readl((*ctrl)->control_core_mac_id_0_lo);
1043 mac_hi = readl((*ctrl)->control_core_mac_id_0_hi);
1044 mac_addr[0] = (mac_hi & 0xFF0000) >> 16;
1045 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
1046 mac_addr[2] = mac_hi & 0xFF;
1047 mac_addr[3] = (mac_lo & 0xFF0000) >> 16;
1048 mac_addr[4] = (mac_lo & 0xFF00) >> 8;
1049 mac_addr[5] = mac_lo & 0xFF;
1050
Simon Glass64b723f2017-08-03 12:22:12 -06001051 if (!env_get("ethaddr")) {
Felipe Balbi4750eb62014-11-10 14:02:44 -06001052 printf("<ethaddr> not set. Validating first E-fuse MAC\n");
1053
Joe Hershberger8ecdbed2015-04-08 01:41:04 -05001054 if (is_valid_ethaddr(mac_addr))
Simon Glass8551d552017-08-03 12:22:11 -06001055 eth_env_set_enetaddr("ethaddr", mac_addr);
Felipe Balbi4750eb62014-11-10 14:02:44 -06001056 }
1057
1058 mac_lo = readl((*ctrl)->control_core_mac_id_1_lo);
1059 mac_hi = readl((*ctrl)->control_core_mac_id_1_hi);
1060 mac_addr[0] = (mac_hi & 0xFF0000) >> 16;
1061 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
1062 mac_addr[2] = mac_hi & 0xFF;
1063 mac_addr[3] = (mac_lo & 0xFF0000) >> 16;
1064 mac_addr[4] = (mac_lo & 0xFF00) >> 8;
1065 mac_addr[5] = mac_lo & 0xFF;
1066
Simon Glass64b723f2017-08-03 12:22:12 -06001067 if (!env_get("eth1addr")) {
Joe Hershberger8ecdbed2015-04-08 01:41:04 -05001068 if (is_valid_ethaddr(mac_addr))
Simon Glass8551d552017-08-03 12:22:11 -06001069 eth_env_set_enetaddr("eth1addr", mac_addr);
Felipe Balbi4750eb62014-11-10 14:02:44 -06001070 }
1071
1072 ctrl_val = readl((*ctrl)->control_core_control_io1) & (~0x33);
1073 ctrl_val |= 0x22;
1074 writel(ctrl_val, (*ctrl)->control_core_control_io1);
1075
Steve Kipiszc95cddd2016-11-25 11:14:24 +05301076 /* The phy address for the AM57xx IDK are different than x15 */
Lokesh Vutla6e9635c2017-12-29 11:47:53 +05301077 if (board_is_am572x_idk() || board_is_am571x_idk() ||
1078 board_is_am574x_idk()) {
Steve Kipisz0ac8cea2016-04-08 17:01:29 -05001079 cpsw_data.slave_data[0].phy_addr = 0;
1080 cpsw_data.slave_data[1].phy_addr = 1;
1081 }
1082
Felipe Balbi4750eb62014-11-10 14:02:44 -06001083 ret = cpsw_register(&cpsw_data);
1084 if (ret < 0)
1085 printf("Error %d registering CPSW switch\n", ret);
1086
Roger Quadros64217a22016-03-18 13:18:12 +02001087 /*
1088 * Export any Ethernet MAC addresses from EEPROM.
1089 * On AM57xx the 2 MAC addresses define the address range
1090 */
1091 board_ti_get_eth_mac_addr(0, mac_addr1);
1092 board_ti_get_eth_mac_addr(1, mac_addr2);
1093
1094 if (is_valid_ethaddr(mac_addr1) && is_valid_ethaddr(mac_addr2)) {
1095 mac1 = mac_to_u64(mac_addr1);
1096 mac2 = mac_to_u64(mac_addr2);
1097
1098 /* must contain an address range */
1099 num_macs = mac2 - mac1 + 1;
1100 /* <= 50 to protect against user programming error */
1101 if (num_macs > 0 && num_macs <= 50) {
1102 for (i = 0; i < num_macs; i++) {
1103 u64_to_mac(mac1 + i, mac_addr);
1104 if (is_valid_ethaddr(mac_addr)) {
Simon Glass8551d552017-08-03 12:22:11 -06001105 eth_env_set_enetaddr_by_index("eth",
1106 i + 2,
1107 mac_addr);
Roger Quadros64217a22016-03-18 13:18:12 +02001108 }
1109 }
1110 }
1111 }
1112
Felipe Balbi4750eb62014-11-10 14:02:44 -06001113 return ret;
1114}
1115#endif
Lokesh Vutla9f150672015-06-16 20:36:05 +05301116
1117#ifdef CONFIG_BOARD_EARLY_INIT_F
1118/* VTT regulator enable */
1119static inline void vtt_regulator_enable(void)
1120{
1121 if (omap_hw_init_context() == OMAP_INIT_CONTEXT_UBOOT_AFTER_SPL)
1122 return;
1123
1124 gpio_request(GPIO_DDR_VTT_EN, "ddr_vtt_en");
1125 gpio_direction_output(GPIO_DDR_VTT_EN, 1);
1126}
1127
1128int board_early_init_f(void)
1129{
1130 vtt_regulator_enable();
1131 return 0;
1132}
1133#endif
Daniel Allred7ceffb22016-05-19 19:10:54 -05001134
1135#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +09001136int ft_board_setup(void *blob, struct bd_info *bd)
Daniel Allred7ceffb22016-05-19 19:10:54 -05001137{
1138 ft_cpu_setup(blob, bd);
1139
1140 return 0;
1141}
1142#endif
Lokesh Vutla00bf8b22016-06-10 09:35:43 +05301143
1144#ifdef CONFIG_SPL_LOAD_FIT
1145int board_fit_config_name_match(const char *name)
1146{
Lokesh Vutla638e1c02016-11-25 11:14:20 +05301147 if (board_is_x15()) {
1148 if (board_is_x15_revb1()) {
1149 if (!strcmp(name, "am57xx-beagle-x15-revb1"))
1150 return 0;
Lokesh Vutlaf35589c2017-08-23 11:39:06 +05301151 } else if (board_is_x15_revc()) {
1152 if (!strcmp(name, "am57xx-beagle-x15-revc"))
1153 return 0;
Lokesh Vutla638e1c02016-11-25 11:14:20 +05301154 } else if (!strcmp(name, "am57xx-beagle-x15")) {
1155 return 0;
1156 }
1157 } else if (board_is_am572x_evm() &&
1158 !strcmp(name, "am57xx-beagle-x15")) {
Lokesh Vutla00bf8b22016-06-10 09:35:43 +05301159 return 0;
Lokesh Vutla638e1c02016-11-25 11:14:20 +05301160 } else if (board_is_am572x_idk() && !strcmp(name, "am572x-idk")) {
Schuyler Patton99519852016-06-10 09:35:45 +05301161 return 0;
Lokesh Vutla58a3c1b2017-12-29 11:47:57 +05301162 } else if (board_is_am574x_idk() && !strcmp(name, "am574x-idk")) {
1163 return 0;
Schuyler Pattonc665e272016-11-25 11:14:25 +05301164 } else if (board_is_am571x_idk() && !strcmp(name, "am571x-idk")) {
1165 return 0;
Caleb Robey940d6372020-01-02 08:17:27 -06001166 } else if (board_is_bbai() && !strcmp(name, "am5729-beagleboneai")) {
1167 return 0;
Lokesh Vutla638e1c02016-11-25 11:14:20 +05301168 }
1169
1170 return -1;
Lokesh Vutla00bf8b22016-06-10 09:35:43 +05301171}
1172#endif
Andreas Dannenberg5cf344b2016-06-27 09:19:22 -05001173
Simon Glass96c0d2b2023-02-05 17:54:10 -07001174#if IS_ENABLED(CONFIG_FASTBOOT) && !CONFIG_IS_ENABLED(ENV_IS_NOWHERE)
Roman Kovalivskyi1bb13422020-07-28 23:35:32 +03001175int fastboot_set_reboot_flag(enum fastboot_reboot_reason reason)
Andrew F. Davisd3555832019-02-11 08:00:08 -06001176{
Roman Kovalivskyi1bb13422020-07-28 23:35:32 +03001177 if (reason != FASTBOOT_REBOOT_REASON_BOOTLOADER)
1178 return -ENOTSUPP;
1179
Andrew F. Davisd3555832019-02-11 08:00:08 -06001180 printf("Setting reboot to fastboot flag ...\n");
1181 env_set("dofastboot", "1");
1182 env_save();
1183 return 0;
1184}
1185#endif
1186
Caleb Robey0dfcc932020-01-02 08:17:25 -06001187#ifdef CONFIG_SUPPORT_EMMC_BOOT
1188static int board_bootmode_has_emmc(void)
1189{
1190 /* Check that boot mode is same as BBAI */
1191 if (gd->arch.omap_boot_mode != 2)
1192 return -EIO;
1193
1194 return 0;
1195}
1196#endif