blob: 7528de3e5c3c9955b7f5e54f7a38ff0887d3d7a0 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Felipe Balbi4750eb62014-11-10 14:02:44 -06002/*
3 * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com
4 *
5 * Author: Felipe Balbi <balbi@ti.com>
6 *
7 * Based on board/ti/dra7xx/evm.c
Felipe Balbi4750eb62014-11-10 14:02:44 -06008 */
9
10#include <common.h>
Simon Glass79fd2142019-08-01 09:46:43 -060011#include <env.h>
Simon Glass3bbe70c2019-12-28 10:44:54 -070012#include <fdt_support.h>
Simon Glassa7b51302019-11-14 12:57:46 -070013#include <init.h>
Simon Glass9bc15642020-02-03 07:36:16 -070014#include <malloc.h>
Felipe Balbi4750eb62014-11-10 14:02:44 -060015#include <palmas.h>
16#include <sata.h>
Simon Glass36736182019-11-14 12:57:24 -070017#include <serial.h>
Felipe Balbi4750eb62014-11-10 14:02:44 -060018#include <usb.h>
Caleb Robey0dfcc932020-01-02 08:17:25 -060019#include <errno.h>
Felipe Balbi4750eb62014-11-10 14:02:44 -060020#include <asm/omap_common.h>
Andreas Dannenberg5cf344b2016-06-27 09:19:22 -050021#include <asm/omap_sec_common.h>
Felipe Balbi4750eb62014-11-10 14:02:44 -060022#include <asm/emif.h>
Lokesh Vutla9f150672015-06-16 20:36:05 +053023#include <asm/gpio.h>
24#include <asm/arch/gpio.h>
Felipe Balbi4750eb62014-11-10 14:02:44 -060025#include <asm/arch/clock.h>
Lokesh Vutlac3d39f92015-06-04 16:42:41 +053026#include <asm/arch/dra7xx_iodelay.h>
Felipe Balbi4750eb62014-11-10 14:02:44 -060027#include <asm/arch/sys_proto.h>
28#include <asm/arch/mmc_host_def.h>
29#include <asm/arch/sata.h>
30#include <asm/arch/gpio.h>
Kishon Vijay Abraham I5f19b2d2015-08-19 14:13:19 +053031#include <asm/arch/omap.h>
Kishon Vijay Abraham I5f19b2d2015-08-19 14:13:19 +053032#include <usb.h>
33#include <linux/usb/gadget.h>
34#include <dwc3-uboot.h>
35#include <dwc3-omap-uboot.h>
36#include <ti-usb-phy-uboot.h>
Kishon Vijay Abraham I110ed012018-01-30 16:01:52 +010037#include <mmc.h>
Tero Kristodfbc6b82019-09-27 19:14:27 +030038#include <dm/uclass.h>
Felipe Balbi4750eb62014-11-10 14:02:44 -060039
Kipisz, Steven161f1382016-02-24 12:30:58 -060040#include "../common/board_detect.h"
Felipe Balbi4750eb62014-11-10 14:02:44 -060041#include "mux_data.h"
42
Caleb Robey0dfcc932020-01-02 08:17:25 -060043#ifdef CONFIG_SUPPORT_EMMC_BOOT
44static int board_bootmode_has_emmc(void);
45#endif
46
Kipisz, Steven161f1382016-02-24 12:30:58 -060047#define board_is_x15() board_ti_is("BBRDX15_")
Lokesh Vutla638e1c02016-11-25 11:14:20 +053048#define board_is_x15_revb1() (board_ti_is("BBRDX15_") && \
Lokesh Vutlaab4f71e2017-07-16 19:59:18 +053049 !strncmp("B.10", board_ti_get_rev(), 3))
Lokesh Vutla816178b2017-07-16 19:59:19 +053050#define board_is_x15_revc() (board_ti_is("BBRDX15_") && \
51 !strncmp("C.00", board_ti_get_rev(), 3))
Kipisz, Steven161f1382016-02-24 12:30:58 -060052#define board_is_am572x_evm() board_ti_is("AM572PM_")
Nishanth Menona2aea1c2016-11-25 11:14:19 +053053#define board_is_am572x_evm_reva3() \
54 (board_ti_is("AM572PM_") && \
Lokesh Vutlaab4f71e2017-07-16 19:59:18 +053055 !strncmp("A.30", board_ti_get_rev(), 3))
Lokesh Vutla374aea02017-12-29 11:47:52 +053056#define board_is_am574x_idk() board_ti_is("AM574IDK")
Steve Kipisz0ac8cea2016-04-08 17:01:29 -050057#define board_is_am572x_idk() board_ti_is("AM572IDK")
Steve Kipiszc95cddd2016-11-25 11:14:24 +053058#define board_is_am571x_idk() board_ti_is("AM571IDK")
Caleb Robey940d6372020-01-02 08:17:27 -060059#define board_is_bbai() board_ti_is("BBONE-AI")
Kipisz, Steven161f1382016-02-24 12:30:58 -060060
Felipe Balbi4750eb62014-11-10 14:02:44 -060061#ifdef CONFIG_DRIVER_TI_CPSW
62#include <cpsw.h>
63#endif
64
65DECLARE_GLOBAL_DATA_PTR;
66
Roger Quadros26130592017-03-13 15:04:28 +020067#define GPIO_ETH_LCD GPIO_TO_PIN(2, 22)
Lokesh Vutla9f150672015-06-16 20:36:05 +053068/* GPIO 7_11 */
69#define GPIO_DDR_VTT_EN 203
70
Nishanth Menond0f399c2017-03-13 15:04:30 +020071/* Touch screen controller to identify the LCD */
72#define OSD_TS_FT_BUS_ADDRESS 0
73#define OSD_TS_FT_CHIP_ADDRESS 0x38
74#define OSD_TS_FT_REG_ID 0xA3
75/*
76 * Touchscreen IDs for various OSD panels
77 * Ref: http://www.osddisplays.com/TI/OSD101T2587-53TS_A.1.pdf
78 */
79/* Used on newer osd101t2587 Panels */
80#define OSD_TS_FT_ID_5x46 0x54
81/* Used on older osd101t2045 Panels */
82#define OSD_TS_FT_ID_5606 0x08
83
Kipisz, Steven161f1382016-02-24 12:30:58 -060084#define SYSINFO_BOARD_NAME_MAX_LEN 45
85
Keerthyee85ebe2016-11-30 15:02:53 +053086#define TPS65903X_PRIMARY_SECONDARY_PAD2 0xFB
87#define TPS65903X_PAD2_POWERHOLD_MASK 0x20
88
Felipe Balbi4750eb62014-11-10 14:02:44 -060089const struct omap_sysinfo sysinfo = {
Kipisz, Steven161f1382016-02-24 12:30:58 -060090 "Board: UNKNOWN(BeagleBoard X15?) REV UNKNOWN\n"
Felipe Balbi4750eb62014-11-10 14:02:44 -060091};
92
93static const struct dmm_lisa_map_regs beagle_x15_lisa_regs = {
94 .dmm_lisa_map_3 = 0x80740300,
95 .is_ma_present = 0x1
96};
97
Steve Kipiszc95cddd2016-11-25 11:14:24 +053098static const struct dmm_lisa_map_regs am571x_idk_lisa_regs = {
99 .dmm_lisa_map_3 = 0x80640100,
100 .is_ma_present = 0x1
101};
102
Lokesh Vutlacbd70db2017-12-29 11:47:54 +0530103static const struct dmm_lisa_map_regs am574x_idk_lisa_regs = {
104 .dmm_lisa_map_2 = 0xc0600200,
105 .dmm_lisa_map_3 = 0x80600100,
106 .is_ma_present = 0x1
107};
108
Caleb Robey940d6372020-01-02 08:17:27 -0600109static const struct dmm_lisa_map_regs bbai_lisa_regs = {
110 .dmm_lisa_map_3 = 0x80640100,
111 .is_ma_present = 0x1
112};
113
Felipe Balbi4750eb62014-11-10 14:02:44 -0600114void emif_get_dmm_regs(const struct dmm_lisa_map_regs **dmm_lisa_regs)
115{
Steve Kipiszc95cddd2016-11-25 11:14:24 +0530116 if (board_is_am571x_idk())
117 *dmm_lisa_regs = &am571x_idk_lisa_regs;
Lokesh Vutlacbd70db2017-12-29 11:47:54 +0530118 else if (board_is_am574x_idk())
119 *dmm_lisa_regs = &am574x_idk_lisa_regs;
Caleb Robey940d6372020-01-02 08:17:27 -0600120 else if (board_is_bbai())
121 *dmm_lisa_regs = &bbai_lisa_regs;
Steve Kipiszc95cddd2016-11-25 11:14:24 +0530122 else
123 *dmm_lisa_regs = &beagle_x15_lisa_regs;
Felipe Balbi4750eb62014-11-10 14:02:44 -0600124}
125
126static const struct emif_regs beagle_x15_emif1_ddr3_532mhz_emif_regs = {
Keerthy66dd8062016-05-24 11:45:07 +0530127 .sdram_config_init = 0x61851b32,
128 .sdram_config = 0x61851b32,
129 .sdram_config2 = 0x08000000,
130 .ref_ctrl = 0x000040F1,
131 .ref_ctrl_final = 0x00001035,
132 .sdram_tim1 = 0xcccf36ab,
133 .sdram_tim2 = 0x308f7fda,
134 .sdram_tim3 = 0x409f88a8,
135 .read_idle_ctrl = 0x00050000,
136 .zq_config = 0x5007190b,
137 .temp_alert_config = 0x00000000,
138 .emif_ddr_phy_ctlr_1_init = 0x0024400b,
139 .emif_ddr_phy_ctlr_1 = 0x0e24400b,
140 .emif_ddr_ext_phy_ctrl_1 = 0x10040100,
141 .emif_ddr_ext_phy_ctrl_2 = 0x00910091,
142 .emif_ddr_ext_phy_ctrl_3 = 0x00950095,
143 .emif_ddr_ext_phy_ctrl_4 = 0x009b009b,
144 .emif_ddr_ext_phy_ctrl_5 = 0x009e009e,
145 .emif_rd_wr_lvl_rmp_win = 0x00000000,
146 .emif_rd_wr_lvl_rmp_ctl = 0x80000000,
147 .emif_rd_wr_lvl_ctl = 0x00000000,
148 .emif_rd_wr_exec_thresh = 0x00000305
Felipe Balbi4750eb62014-11-10 14:02:44 -0600149};
150
Lokesh Vutla979d2c32015-06-03 14:43:21 +0530151/* Ext phy ctrl regs 1-35 */
Felipe Balbi4750eb62014-11-10 14:02:44 -0600152static const u32 beagle_x15_emif1_ddr3_ext_phy_ctrl_const_regs[] = {
Lokesh Vutla979d2c32015-06-03 14:43:21 +0530153 0x10040100,
Lokesh Vutla306b5972016-03-08 09:11:35 +0530154 0x00910091,
155 0x00950095,
156 0x009B009B,
157 0x009E009E,
158 0x00980098,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600159 0x00340034,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600160 0x00350035,
Lokesh Vutla306b5972016-03-08 09:11:35 +0530161 0x00340034,
162 0x00310031,
163 0x00340034,
164 0x007F007F,
165 0x007F007F,
166 0x007F007F,
167 0x007F007F,
168 0x007F007F,
169 0x00480048,
170 0x004A004A,
171 0x00520052,
172 0x00550055,
173 0x00500050,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600174 0x00000000,
175 0x00600020,
Lokesh Vutla979d2c32015-06-03 14:43:21 +0530176 0x40011080,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600177 0x08102040,
Lokesh Vutla306b5972016-03-08 09:11:35 +0530178 0x0,
179 0x0,
180 0x0,
181 0x0,
Lokesh Vutla51a0f1f2015-06-03 14:43:22 +0530182 0x0,
183 0x0,
184 0x0,
185 0x0,
Lokesh Vutla306b5972016-03-08 09:11:35 +0530186 0x0,
Lokesh Vutla51a0f1f2015-06-03 14:43:22 +0530187 0x0
Felipe Balbi4750eb62014-11-10 14:02:44 -0600188};
189
190static const struct emif_regs beagle_x15_emif2_ddr3_532mhz_emif_regs = {
Keerthy66dd8062016-05-24 11:45:07 +0530191 .sdram_config_init = 0x61851b32,
192 .sdram_config = 0x61851b32,
193 .sdram_config2 = 0x08000000,
194 .ref_ctrl = 0x000040F1,
195 .ref_ctrl_final = 0x00001035,
196 .sdram_tim1 = 0xcccf36b3,
197 .sdram_tim2 = 0x308f7fda,
198 .sdram_tim3 = 0x407f88a8,
199 .read_idle_ctrl = 0x00050000,
200 .zq_config = 0x5007190b,
201 .temp_alert_config = 0x00000000,
202 .emif_ddr_phy_ctlr_1_init = 0x0024400b,
203 .emif_ddr_phy_ctlr_1 = 0x0e24400b,
204 .emif_ddr_ext_phy_ctrl_1 = 0x10040100,
205 .emif_ddr_ext_phy_ctrl_2 = 0x00910091,
206 .emif_ddr_ext_phy_ctrl_3 = 0x00950095,
207 .emif_ddr_ext_phy_ctrl_4 = 0x009b009b,
208 .emif_ddr_ext_phy_ctrl_5 = 0x009e009e,
209 .emif_rd_wr_lvl_rmp_win = 0x00000000,
210 .emif_rd_wr_lvl_rmp_ctl = 0x80000000,
211 .emif_rd_wr_lvl_ctl = 0x00000000,
212 .emif_rd_wr_exec_thresh = 0x00000305
Felipe Balbi4750eb62014-11-10 14:02:44 -0600213};
214
215static const u32 beagle_x15_emif2_ddr3_ext_phy_ctrl_const_regs[] = {
Lokesh Vutla979d2c32015-06-03 14:43:21 +0530216 0x10040100,
Lokesh Vutla306b5972016-03-08 09:11:35 +0530217 0x00910091,
218 0x00950095,
219 0x009B009B,
220 0x009E009E,
221 0x00980098,
222 0x00340034,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600223 0x00350035,
Lokesh Vutla306b5972016-03-08 09:11:35 +0530224 0x00340034,
225 0x00310031,
226 0x00340034,
227 0x007F007F,
228 0x007F007F,
229 0x007F007F,
230 0x007F007F,
231 0x007F007F,
232 0x00480048,
233 0x004A004A,
234 0x00520052,
235 0x00550055,
236 0x00500050,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600237 0x00000000,
238 0x00600020,
Lokesh Vutla979d2c32015-06-03 14:43:21 +0530239 0x40011080,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600240 0x08102040,
Lokesh Vutla306b5972016-03-08 09:11:35 +0530241 0x0,
242 0x0,
243 0x0,
244 0x0,
245 0x0,
Lokesh Vutla51a0f1f2015-06-03 14:43:22 +0530246 0x0,
247 0x0,
248 0x0,
249 0x0,
250 0x0
Felipe Balbi4750eb62014-11-10 14:02:44 -0600251};
252
Steve Kipisz81c46742017-08-22 13:52:58 +0530253static const struct emif_regs am571x_emif1_ddr3_666mhz_emif_regs = {
254 .sdram_config_init = 0x61863332,
255 .sdram_config = 0x61863332,
256 .sdram_config2 = 0x08000000,
257 .ref_ctrl = 0x0000514d,
258 .ref_ctrl_final = 0x0000144a,
259 .sdram_tim1 = 0xd333887c,
Lokesh Vutlacbd70db2017-12-29 11:47:54 +0530260 .sdram_tim2 = 0x30b37fe3,
261 .sdram_tim3 = 0x409f8ad8,
Steve Kipisz81c46742017-08-22 13:52:58 +0530262 .read_idle_ctrl = 0x00050000,
263 .zq_config = 0x5007190b,
264 .temp_alert_config = 0x00000000,
265 .emif_ddr_phy_ctlr_1_init = 0x0024400f,
266 .emif_ddr_phy_ctlr_1 = 0x0e24400f,
267 .emif_ddr_ext_phy_ctrl_1 = 0x10040100,
268 .emif_ddr_ext_phy_ctrl_2 = 0x00910091,
269 .emif_ddr_ext_phy_ctrl_3 = 0x00950095,
270 .emif_ddr_ext_phy_ctrl_4 = 0x009b009b,
271 .emif_ddr_ext_phy_ctrl_5 = 0x009e009e,
272 .emif_rd_wr_lvl_rmp_win = 0x00000000,
273 .emif_rd_wr_lvl_rmp_ctl = 0x80000000,
274 .emif_rd_wr_lvl_ctl = 0x00000000,
275 .emif_rd_wr_exec_thresh = 0x00000305
276};
277
Lokesh Vutlacbd70db2017-12-29 11:47:54 +0530278static const struct emif_regs am574x_emif1_ddr3_666mhz_emif_ecc_regs = {
279 .sdram_config_init = 0x61863332,
280 .sdram_config = 0x61863332,
281 .sdram_config2 = 0x08000000,
282 .ref_ctrl = 0x0000514d,
283 .ref_ctrl_final = 0x0000144a,
284 .sdram_tim1 = 0xd333887c,
285 .sdram_tim2 = 0x30b37fe3,
286 .sdram_tim3 = 0x409f8ad8,
287 .read_idle_ctrl = 0x00050000,
288 .zq_config = 0x5007190b,
289 .temp_alert_config = 0x00000000,
290 .emif_ddr_phy_ctlr_1_init = 0x0024400f,
291 .emif_ddr_phy_ctlr_1 = 0x0e24400f,
292 .emif_ddr_ext_phy_ctrl_1 = 0x10040100,
293 .emif_ddr_ext_phy_ctrl_2 = 0x00910091,
294 .emif_ddr_ext_phy_ctrl_3 = 0x00950095,
295 .emif_ddr_ext_phy_ctrl_4 = 0x009b009b,
296 .emif_ddr_ext_phy_ctrl_5 = 0x009e009e,
297 .emif_rd_wr_lvl_rmp_win = 0x00000000,
298 .emif_rd_wr_lvl_rmp_ctl = 0x80000000,
299 .emif_rd_wr_lvl_ctl = 0x00000000,
300 .emif_rd_wr_exec_thresh = 0x00000305,
301 .emif_ecc_ctrl_reg = 0xD0000001,
302 .emif_ecc_address_range_1 = 0x3FFF0000,
303 .emif_ecc_address_range_2 = 0x00000000
304};
305
Felipe Balbi4750eb62014-11-10 14:02:44 -0600306void emif_get_reg_dump(u32 emif_nr, const struct emif_regs **regs)
307{
308 switch (emif_nr) {
309 case 1:
Steve Kipisz81c46742017-08-22 13:52:58 +0530310 if (board_is_am571x_idk())
311 *regs = &am571x_emif1_ddr3_666mhz_emif_regs;
Lokesh Vutlacbd70db2017-12-29 11:47:54 +0530312 else if (board_is_am574x_idk())
313 *regs = &am574x_emif1_ddr3_666mhz_emif_ecc_regs;
Steve Kipisz81c46742017-08-22 13:52:58 +0530314 else
315 *regs = &beagle_x15_emif1_ddr3_532mhz_emif_regs;
Felipe Balbi4750eb62014-11-10 14:02:44 -0600316 break;
317 case 2:
Lokesh Vutlacbd70db2017-12-29 11:47:54 +0530318 if (board_is_am574x_idk())
319 *regs = &am571x_emif1_ddr3_666mhz_emif_regs;
320 else
321 *regs = &beagle_x15_emif2_ddr3_532mhz_emif_regs;
Felipe Balbi4750eb62014-11-10 14:02:44 -0600322 break;
323 }
324}
325
326void emif_get_ext_phy_ctrl_const_regs(u32 emif_nr, const u32 **regs, u32 *size)
327{
328 switch (emif_nr) {
329 case 1:
330 *regs = beagle_x15_emif1_ddr3_ext_phy_ctrl_const_regs;
331 *size = ARRAY_SIZE(beagle_x15_emif1_ddr3_ext_phy_ctrl_const_regs);
332 break;
333 case 2:
334 *regs = beagle_x15_emif2_ddr3_ext_phy_ctrl_const_regs;
335 *size = ARRAY_SIZE(beagle_x15_emif2_ddr3_ext_phy_ctrl_const_regs);
336 break;
337 }
338}
339
340struct vcores_data beagle_x15_volts = {
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530341 .mpu.value[OPP_NOM] = VDD_MPU_DRA7_NOM,
342 .mpu.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_MPU_NOM,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600343 .mpu.efuse.reg_bits = DRA752_EFUSE_REGBITS,
344 .mpu.addr = TPS659038_REG_ADDR_SMPS12,
345 .mpu.pmic = &tps659038,
Keerthy66dd8062016-05-24 11:45:07 +0530346 .mpu.abb_tx_done_mask = OMAP_ABB_MPU_TXDONE_MASK,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600347
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530348 .eve.value[OPP_NOM] = VDD_EVE_DRA7_NOM,
349 .eve.value[OPP_OD] = VDD_EVE_DRA7_OD,
350 .eve.value[OPP_HIGH] = VDD_EVE_DRA7_HIGH,
351 .eve.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_DSPEVE_NOM,
352 .eve.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_DSPEVE_OD,
353 .eve.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_DSPEVE_HIGH,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600354 .eve.efuse.reg_bits = DRA752_EFUSE_REGBITS,
355 .eve.addr = TPS659038_REG_ADDR_SMPS45,
356 .eve.pmic = &tps659038,
Nishanth Menon59b92af2016-04-21 14:34:25 -0500357 .eve.abb_tx_done_mask = OMAP_ABB_EVE_TXDONE_MASK,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600358
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530359 .gpu.value[OPP_NOM] = VDD_GPU_DRA7_NOM,
360 .gpu.value[OPP_OD] = VDD_GPU_DRA7_OD,
361 .gpu.value[OPP_HIGH] = VDD_GPU_DRA7_HIGH,
362 .gpu.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_GPU_NOM,
363 .gpu.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_GPU_OD,
364 .gpu.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_GPU_HIGH,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600365 .gpu.efuse.reg_bits = DRA752_EFUSE_REGBITS,
366 .gpu.addr = TPS659038_REG_ADDR_SMPS45,
367 .gpu.pmic = &tps659038,
Nishanth Menon59b92af2016-04-21 14:34:25 -0500368 .gpu.abb_tx_done_mask = OMAP_ABB_GPU_TXDONE_MASK,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600369
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530370 .core.value[OPP_NOM] = VDD_CORE_DRA7_NOM,
371 .core.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_CORE_NOM,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600372 .core.efuse.reg_bits = DRA752_EFUSE_REGBITS,
373 .core.addr = TPS659038_REG_ADDR_SMPS6,
374 .core.pmic = &tps659038,
375
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530376 .iva.value[OPP_NOM] = VDD_IVA_DRA7_NOM,
377 .iva.value[OPP_OD] = VDD_IVA_DRA7_OD,
378 .iva.value[OPP_HIGH] = VDD_IVA_DRA7_HIGH,
379 .iva.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_IVA_NOM,
380 .iva.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_IVA_OD,
381 .iva.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_IVA_HIGH,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600382 .iva.efuse.reg_bits = DRA752_EFUSE_REGBITS,
383 .iva.addr = TPS659038_REG_ADDR_SMPS45,
384 .iva.pmic = &tps659038,
Nishanth Menon59b92af2016-04-21 14:34:25 -0500385 .iva.abb_tx_done_mask = OMAP_ABB_IVA_TXDONE_MASK,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600386};
387
Keerthy152e9932016-05-24 11:45:06 +0530388struct vcores_data am572x_idk_volts = {
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530389 .mpu.value[OPP_NOM] = VDD_MPU_DRA7_NOM,
390 .mpu.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_MPU_NOM,
Keerthy152e9932016-05-24 11:45:06 +0530391 .mpu.efuse.reg_bits = DRA752_EFUSE_REGBITS,
392 .mpu.addr = TPS659038_REG_ADDR_SMPS12,
393 .mpu.pmic = &tps659038,
394 .mpu.abb_tx_done_mask = OMAP_ABB_MPU_TXDONE_MASK,
395
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530396 .eve.value[OPP_NOM] = VDD_EVE_DRA7_NOM,
397 .eve.value[OPP_OD] = VDD_EVE_DRA7_OD,
398 .eve.value[OPP_HIGH] = VDD_EVE_DRA7_HIGH,
399 .eve.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_DSPEVE_NOM,
400 .eve.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_DSPEVE_OD,
401 .eve.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_DSPEVE_HIGH,
Keerthy152e9932016-05-24 11:45:06 +0530402 .eve.efuse.reg_bits = DRA752_EFUSE_REGBITS,
403 .eve.addr = TPS659038_REG_ADDR_SMPS45,
404 .eve.pmic = &tps659038,
405 .eve.abb_tx_done_mask = OMAP_ABB_EVE_TXDONE_MASK,
406
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530407 .gpu.value[OPP_NOM] = VDD_GPU_DRA7_NOM,
408 .gpu.value[OPP_OD] = VDD_GPU_DRA7_OD,
409 .gpu.value[OPP_HIGH] = VDD_GPU_DRA7_HIGH,
410 .gpu.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_GPU_NOM,
411 .gpu.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_GPU_OD,
412 .gpu.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_GPU_HIGH,
Keerthy152e9932016-05-24 11:45:06 +0530413 .gpu.efuse.reg_bits = DRA752_EFUSE_REGBITS,
414 .gpu.addr = TPS659038_REG_ADDR_SMPS6,
415 .gpu.pmic = &tps659038,
416 .gpu.abb_tx_done_mask = OMAP_ABB_GPU_TXDONE_MASK,
417
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530418 .core.value[OPP_NOM] = VDD_CORE_DRA7_NOM,
419 .core.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_CORE_NOM,
Keerthy152e9932016-05-24 11:45:06 +0530420 .core.efuse.reg_bits = DRA752_EFUSE_REGBITS,
421 .core.addr = TPS659038_REG_ADDR_SMPS7,
422 .core.pmic = &tps659038,
423
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530424 .iva.value[OPP_NOM] = VDD_IVA_DRA7_NOM,
425 .iva.value[OPP_OD] = VDD_IVA_DRA7_OD,
426 .iva.value[OPP_HIGH] = VDD_IVA_DRA7_HIGH,
427 .iva.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_IVA_NOM,
428 .iva.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_IVA_OD,
429 .iva.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_IVA_HIGH,
Keerthy152e9932016-05-24 11:45:06 +0530430 .iva.efuse.reg_bits = DRA752_EFUSE_REGBITS,
431 .iva.addr = TPS659038_REG_ADDR_SMPS8,
432 .iva.pmic = &tps659038,
433 .iva.abb_tx_done_mask = OMAP_ABB_IVA_TXDONE_MASK,
434};
435
Keerthy9cc2aee2017-05-25 15:37:34 +0530436struct vcores_data am571x_idk_volts = {
437 .mpu.value[OPP_NOM] = VDD_MPU_DRA7_NOM,
438 .mpu.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_MPU_NOM,
439 .mpu.efuse.reg_bits = DRA752_EFUSE_REGBITS,
440 .mpu.addr = TPS659038_REG_ADDR_SMPS12,
441 .mpu.pmic = &tps659038,
442 .mpu.abb_tx_done_mask = OMAP_ABB_MPU_TXDONE_MASK,
443
444 .eve.value[OPP_NOM] = VDD_EVE_DRA7_NOM,
445 .eve.value[OPP_OD] = VDD_EVE_DRA7_OD,
446 .eve.value[OPP_HIGH] = VDD_EVE_DRA7_HIGH,
447 .eve.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_DSPEVE_NOM,
448 .eve.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_DSPEVE_OD,
449 .eve.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_DSPEVE_HIGH,
450 .eve.efuse.reg_bits = DRA752_EFUSE_REGBITS,
451 .eve.addr = TPS659038_REG_ADDR_SMPS45,
452 .eve.pmic = &tps659038,
453 .eve.abb_tx_done_mask = OMAP_ABB_EVE_TXDONE_MASK,
454
455 .gpu.value[OPP_NOM] = VDD_GPU_DRA7_NOM,
456 .gpu.value[OPP_OD] = VDD_GPU_DRA7_OD,
457 .gpu.value[OPP_HIGH] = VDD_GPU_DRA7_HIGH,
458 .gpu.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_GPU_NOM,
459 .gpu.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_GPU_OD,
460 .gpu.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_GPU_HIGH,
461 .gpu.efuse.reg_bits = DRA752_EFUSE_REGBITS,
462 .gpu.addr = TPS659038_REG_ADDR_SMPS6,
463 .gpu.pmic = &tps659038,
464 .gpu.abb_tx_done_mask = OMAP_ABB_GPU_TXDONE_MASK,
465
466 .core.value[OPP_NOM] = VDD_CORE_DRA7_NOM,
467 .core.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_CORE_NOM,
468 .core.efuse.reg_bits = DRA752_EFUSE_REGBITS,
469 .core.addr = TPS659038_REG_ADDR_SMPS7,
470 .core.pmic = &tps659038,
471
472 .iva.value[OPP_NOM] = VDD_IVA_DRA7_NOM,
473 .iva.value[OPP_OD] = VDD_IVA_DRA7_OD,
474 .iva.value[OPP_HIGH] = VDD_IVA_DRA7_HIGH,
475 .iva.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_IVA_NOM,
476 .iva.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_IVA_OD,
477 .iva.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_IVA_HIGH,
478 .iva.efuse.reg_bits = DRA752_EFUSE_REGBITS,
479 .iva.addr = TPS659038_REG_ADDR_SMPS45,
480 .iva.pmic = &tps659038,
481 .iva.abb_tx_done_mask = OMAP_ABB_IVA_TXDONE_MASK,
482};
483
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530484int get_voltrail_opp(int rail_offset)
485{
486 int opp;
487
488 switch (rail_offset) {
489 case VOLT_MPU:
490 opp = DRA7_MPU_OPP;
491 break;
492 case VOLT_CORE:
493 opp = DRA7_CORE_OPP;
494 break;
495 case VOLT_GPU:
496 opp = DRA7_GPU_OPP;
497 break;
498 case VOLT_EVE:
499 opp = DRA7_DSPEVE_OPP;
500 break;
501 case VOLT_IVA:
502 opp = DRA7_IVA_OPP;
503 break;
504 default:
505 opp = OPP_NOM;
506 }
507
508 return opp;
509}
510
511
Kipisz, Steven161f1382016-02-24 12:30:58 -0600512#ifdef CONFIG_SPL_BUILD
513/* No env to setup for SPL */
514static inline void setup_board_eeprom_env(void) { }
515
516/* Override function to read eeprom information */
517void do_board_detect(void)
518{
519 int rc;
520
521 rc = ti_i2c_eeprom_am_get(CONFIG_EEPROM_BUS_ADDRESS,
522 CONFIG_EEPROM_CHIP_ADDRESS);
523 if (rc)
524 printf("ti_i2c_eeprom_init failed %d\n", rc);
Caleb Robey0dfcc932020-01-02 08:17:25 -0600525
526#ifdef CONFIG_SUPPORT_EMMC_BOOT
527 rc = board_bootmode_has_emmc();
528 if (!rc)
529 rc = ti_emmc_boardid_get();
530 if (rc)
531 printf("ti_emmc_boardid_get failed %d\n", rc);
532#endif
Kipisz, Steven161f1382016-02-24 12:30:58 -0600533}
534
535#else /* CONFIG_SPL_BUILD */
536
537/* Override function to read eeprom information: actual i2c read done by SPL*/
538void do_board_detect(void)
539{
540 char *bname = NULL;
541 int rc;
542
543 rc = ti_i2c_eeprom_am_get(CONFIG_EEPROM_BUS_ADDRESS,
544 CONFIG_EEPROM_CHIP_ADDRESS);
545 if (rc)
546 printf("ti_i2c_eeprom_init failed %d\n", rc);
547
Caleb Robey0dfcc932020-01-02 08:17:25 -0600548#ifdef CONFIG_SUPPORT_EMMC_BOOT
549 rc = board_bootmode_has_emmc();
550 if (!rc)
551 rc = ti_emmc_boardid_get();
552 if (rc)
553 printf("ti_emmc_boardid_get failed %d\n", rc);
554#endif
555
Kipisz, Steven161f1382016-02-24 12:30:58 -0600556 if (board_is_x15())
557 bname = "BeagleBoard X15";
558 else if (board_is_am572x_evm())
559 bname = "AM572x EVM";
Lokesh Vutla374aea02017-12-29 11:47:52 +0530560 else if (board_is_am574x_idk())
561 bname = "AM574x IDK";
Steve Kipisz0ac8cea2016-04-08 17:01:29 -0500562 else if (board_is_am572x_idk())
563 bname = "AM572x IDK";
Steve Kipiszc95cddd2016-11-25 11:14:24 +0530564 else if (board_is_am571x_idk())
565 bname = "AM571x IDK";
Caleb Robey940d6372020-01-02 08:17:27 -0600566 else if (board_is_bbai())
567 bname = "BeagleBone AI";
Kipisz, Steven161f1382016-02-24 12:30:58 -0600568
569 if (bname)
570 snprintf(sysinfo.board_string, SYSINFO_BOARD_NAME_MAX_LEN,
571 "Board: %s REV %s\n", bname, board_ti_get_rev());
572}
573
574static void setup_board_eeprom_env(void)
575{
576 char *name = "beagle_x15";
577 int rc;
578
579 rc = ti_i2c_eeprom_am_get(CONFIG_EEPROM_BUS_ADDRESS,
580 CONFIG_EEPROM_CHIP_ADDRESS);
581 if (rc)
582 goto invalid_eeprom;
583
Nishanth Menona2aea1c2016-11-25 11:14:19 +0530584 if (board_is_x15()) {
Lokesh Vutla638e1c02016-11-25 11:14:20 +0530585 if (board_is_x15_revb1())
586 name = "beagle_x15_revb1";
Lokesh Vutla816178b2017-07-16 19:59:19 +0530587 else if (board_is_x15_revc())
588 name = "beagle_x15_revc";
Lokesh Vutla638e1c02016-11-25 11:14:20 +0530589 else
590 name = "beagle_x15";
Nishanth Menona2aea1c2016-11-25 11:14:19 +0530591 } else if (board_is_am572x_evm()) {
592 if (board_is_am572x_evm_reva3())
593 name = "am57xx_evm_reva3";
594 else
595 name = "am57xx_evm";
Lokesh Vutla374aea02017-12-29 11:47:52 +0530596 } else if (board_is_am574x_idk()) {
597 name = "am574x_idk";
Nishanth Menona2aea1c2016-11-25 11:14:19 +0530598 } else if (board_is_am572x_idk()) {
Steve Kipisz0ac8cea2016-04-08 17:01:29 -0500599 name = "am572x_idk";
Steve Kipiszc95cddd2016-11-25 11:14:24 +0530600 } else if (board_is_am571x_idk()) {
601 name = "am571x_idk";
Caleb Robey940d6372020-01-02 08:17:27 -0600602 } else if (board_is_bbai()) {
603 name = "am5729_beagleboneai";
Nishanth Menona2aea1c2016-11-25 11:14:19 +0530604 } else {
Kipisz, Steven161f1382016-02-24 12:30:58 -0600605 printf("Unidentified board claims %s in eeprom header\n",
606 board_ti_get_name());
Nishanth Menona2aea1c2016-11-25 11:14:19 +0530607 }
Kipisz, Steven161f1382016-02-24 12:30:58 -0600608
609invalid_eeprom:
610 set_board_info_env(name);
611}
612
613#endif /* CONFIG_SPL_BUILD */
614
Keerthy152e9932016-05-24 11:45:06 +0530615void vcores_init(void)
616{
Lokesh Vutla6e9635c2017-12-29 11:47:53 +0530617 if (board_is_am572x_idk() || board_is_am574x_idk())
Keerthy152e9932016-05-24 11:45:06 +0530618 *omap_vcores = &am572x_idk_volts;
Keerthy9cc2aee2017-05-25 15:37:34 +0530619 else if (board_is_am571x_idk())
620 *omap_vcores = &am571x_idk_volts;
Keerthy152e9932016-05-24 11:45:06 +0530621 else
622 *omap_vcores = &beagle_x15_volts;
623}
624
Felipe Balbi4750eb62014-11-10 14:02:44 -0600625void hw_data_init(void)
626{
627 *prcm = &dra7xx_prcm;
Steve Kipisz81c46742017-08-22 13:52:58 +0530628 if (is_dra72x())
629 *dplls_data = &dra72x_dplls;
Lokesh Vutla6e9635c2017-12-29 11:47:53 +0530630 else if (is_dra76x())
631 *dplls_data = &dra76x_dplls;
Steve Kipisz81c46742017-08-22 13:52:58 +0530632 else
633 *dplls_data = &dra7xx_dplls;
Felipe Balbi4750eb62014-11-10 14:02:44 -0600634 *ctrl = &dra7xx_ctrl;
635}
636
Roger Quadros26130592017-03-13 15:04:28 +0200637bool am571x_idk_needs_lcd(void)
638{
639 bool needs_lcd;
640
641 gpio_request(GPIO_ETH_LCD, "nLCD_Detect");
642 if (gpio_get_value(GPIO_ETH_LCD))
643 needs_lcd = false;
644 else
645 needs_lcd = true;
646
647 gpio_free(GPIO_ETH_LCD);
648
649 return needs_lcd;
650}
651
Felipe Balbi4750eb62014-11-10 14:02:44 -0600652int board_init(void)
653{
654 gpmc_init();
655 gd->bd->bi_boot_params = (CONFIG_SYS_SDRAM_BASE + 0x100);
656
657 return 0;
658}
659
Nishanth Menond0f399c2017-03-13 15:04:30 +0200660void am57x_idk_lcd_detect(void)
Felipe Balbi4750eb62014-11-10 14:02:44 -0600661{
Nishanth Menond0f399c2017-03-13 15:04:30 +0200662 int r = -ENODEV;
663 char *idk_lcd = "no";
Jean-Jacques Hiblot184ec9a2018-12-07 14:50:50 +0100664 struct udevice *dev;
Nishanth Menond0f399c2017-03-13 15:04:30 +0200665
666 /* Only valid for IDKs */
Caleb Robey940d6372020-01-02 08:17:27 -0600667 if (board_is_x15() || board_is_am572x_evm() || board_is_bbai())
Nishanth Menond0f399c2017-03-13 15:04:30 +0200668 return;
669
670 /* Only AM571x IDK has gpio control detect.. so check that */
671 if (board_is_am571x_idk() && !am571x_idk_needs_lcd())
672 goto out;
673
Jean-Jacques Hiblot52a51512018-12-07 14:50:49 +0100674 r = i2c_get_chip_for_busnum(OSD_TS_FT_BUS_ADDRESS,
675 OSD_TS_FT_CHIP_ADDRESS, 1, &dev);
Nishanth Menond0f399c2017-03-13 15:04:30 +0200676 if (r) {
Jean-Jacques Hiblot52a51512018-12-07 14:50:49 +0100677 printf("%s: Failed to get I2C device %d/%d (ret %d)\n",
678 __func__, OSD_TS_FT_BUS_ADDRESS, OSD_TS_FT_CHIP_ADDRESS,
679 r);
Nishanth Menond0f399c2017-03-13 15:04:30 +0200680 /* AM572x IDK has no explicit settings for optional LCD kit */
Jean-Jacques Hiblot52a51512018-12-07 14:50:49 +0100681 if (board_is_am571x_idk())
Nishanth Menond0f399c2017-03-13 15:04:30 +0200682 printf("%s: Touch screen detect failed: %d!\n",
683 __func__, r);
Nishanth Menond0f399c2017-03-13 15:04:30 +0200684 goto out;
685 }
686
687 /* Read FT ID */
Jean-Jacques Hiblot52a51512018-12-07 14:50:49 +0100688 r = dm_i2c_reg_read(dev, OSD_TS_FT_REG_ID);
689 if (r < 0) {
Nishanth Menond0f399c2017-03-13 15:04:30 +0200690 printf("%s: Touch screen ID read %d:0x%02x[0x%02x] failed:%d\n",
691 __func__, OSD_TS_FT_BUS_ADDRESS, OSD_TS_FT_CHIP_ADDRESS,
692 OSD_TS_FT_REG_ID, r);
693 goto out;
694 }
695
Jean-Jacques Hiblot184ec9a2018-12-07 14:50:50 +0100696 switch (r) {
Nishanth Menond0f399c2017-03-13 15:04:30 +0200697 case OSD_TS_FT_ID_5606:
698 idk_lcd = "osd101t2045";
699 break;
700 case OSD_TS_FT_ID_5x46:
701 idk_lcd = "osd101t2587";
702 break;
703 default:
704 printf("%s: Unidentifed Touch screen ID 0x%02x\n",
Jean-Jacques Hiblot184ec9a2018-12-07 14:50:50 +0100705 __func__, r);
Nishanth Menond0f399c2017-03-13 15:04:30 +0200706 /* we will let default be "no lcd" */
707 }
708out:
Simon Glass6a38e412017-08-03 12:22:09 -0600709 env_set("idk_lcd", idk_lcd);
Nishanth Menond0f399c2017-03-13 15:04:30 +0200710 return;
711}
Roger Quadros26130592017-03-13 15:04:28 +0200712
Vignesh R98c5f632018-11-29 10:57:42 +0100713#if CONFIG_IS_ENABLED(DM_USB) && CONFIG_IS_ENABLED(OF_CONTROL)
714static int device_okay(const char *path)
715{
716 int node;
717
718 node = fdt_path_offset(gd->fdt_blob, path);
719 if (node < 0)
720 return 0;
721
722 return fdtdec_get_is_enabled(gd->fdt_blob, node);
723}
724#endif
725
Nishanth Menond0f399c2017-03-13 15:04:30 +0200726int board_late_init(void)
727{
Kipisz, Steven161f1382016-02-24 12:30:58 -0600728 setup_board_eeprom_env();
Keerthyee85ebe2016-11-30 15:02:53 +0530729 u8 val;
Tero Kristodfbc6b82019-09-27 19:14:27 +0300730 struct udevice *dev;
Kipisz, Steven161f1382016-02-24 12:30:58 -0600731
Felipe Balbi4750eb62014-11-10 14:02:44 -0600732 /*
733 * DEV_CTRL.DEV_ON = 1 please - else palmas switches off in 8 seconds
734 * This is the POWERHOLD-in-Low behavior.
735 */
736 palmas_i2c_write_u8(TPS65903X_CHIP_P1, 0xA0, 0x1);
Lokesh Vutla2c47e8c2016-11-29 11:58:02 +0530737
738 /*
739 * Default FIT boot on HS devices. Non FIT images are not allowed
740 * on HS devices.
741 */
742 if (get_device_type() == HS_DEVICE)
Simon Glass6a38e412017-08-03 12:22:09 -0600743 env_set("boot_fit", "1");
Lokesh Vutla2c47e8c2016-11-29 11:58:02 +0530744
Keerthyee85ebe2016-11-30 15:02:53 +0530745 /*
746 * Set the GPIO7 Pad to POWERHOLD. This has higher priority
747 * over DEV_CTRL.DEV_ON bit. This can be reset in case of
748 * PMIC Power off. So to be on the safer side set it back
749 * to POWERHOLD mode irrespective of the current state.
750 */
751 palmas_i2c_read_u8(TPS65903X_CHIP_P1, TPS65903X_PRIMARY_SECONDARY_PAD2,
752 &val);
753 val = val | TPS65903X_PAD2_POWERHOLD_MASK;
754 palmas_i2c_write_u8(TPS65903X_CHIP_P1, TPS65903X_PRIMARY_SECONDARY_PAD2,
755 val);
756
Semen Protsenko4b0721f2017-02-13 19:09:37 +0200757 omap_die_id_serial();
Semen Protsenkob72dccd2017-05-22 19:16:41 +0300758 omap_set_fastboot_vars();
Semen Protsenko4b0721f2017-02-13 19:09:37 +0200759
Nishanth Menond0f399c2017-03-13 15:04:30 +0200760 am57x_idk_lcd_detect();
Roger Quadros26130592017-03-13 15:04:28 +0200761
Tero Kristodfbc6b82019-09-27 19:14:27 +0300762 /* Just probe the potentially supported cdce913 device */
763 uclass_get_device(UCLASS_CLK, 0, &dev);
764
Caleb Robey940d6372020-01-02 08:17:27 -0600765 if (board_is_bbai())
766 env_set("console", "ttyS0,115200n8");
767
Roger Quadros26130592017-03-13 15:04:28 +0200768#if !defined(CONFIG_SPL_BUILD)
769 board_ti_set_ethaddr(2);
770#endif
771
Vignesh R98c5f632018-11-29 10:57:42 +0100772#if CONFIG_IS_ENABLED(DM_USB) && CONFIG_IS_ENABLED(OF_CONTROL)
773 if (device_okay("/ocp/omap_dwc3_1@48880000"))
774 enable_usb_clocks(0);
775 if (device_okay("/ocp/omap_dwc3_2@488c0000"))
776 enable_usb_clocks(1);
777#endif
Felipe Balbi4750eb62014-11-10 14:02:44 -0600778 return 0;
779}
780
Paul Kocialkowskia00b1e52016-02-27 19:18:56 +0100781void set_muxconf_regs(void)
Felipe Balbi4750eb62014-11-10 14:02:44 -0600782{
783 do_set_mux32((*ctrl)->control_padconf_core_base,
Lokesh Vutlac3d39f92015-06-04 16:42:41 +0530784 early_padconf, ARRAY_SIZE(early_padconf));
Caleb Robey0dfcc932020-01-02 08:17:25 -0600785
786#ifdef CONFIG_SUPPORT_EMMC_BOOT
787 do_set_mux32((*ctrl)->control_padconf_core_base,
788 emmc_padconf, ARRAY_SIZE(emmc_padconf));
789#endif
Felipe Balbi4750eb62014-11-10 14:02:44 -0600790}
791
Lokesh Vutlac3d39f92015-06-04 16:42:41 +0530792#ifdef CONFIG_IODELAY_RECALIBRATION
793void recalibrate_iodelay(void)
794{
Steve Kipisz0ac8cea2016-04-08 17:01:29 -0500795 const struct pad_conf_entry *pconf;
Lokesh Vutla3cb4c622017-06-05 14:48:16 +0530796 const struct iodelay_cfg_entry *iod, *delta_iod;
797 int pconf_sz, iod_sz, delta_iod_sz = 0;
Nishanth Menon8e3212e2016-11-25 11:14:22 +0530798 int ret;
Steve Kipisz0ac8cea2016-04-08 17:01:29 -0500799
Lokesh Vutla1e3425c2017-12-29 11:47:55 +0530800 if (board_is_am572x_idk()) {
Steve Kipisz0ac8cea2016-04-08 17:01:29 -0500801 pconf = core_padconf_array_essential_am572x_idk;
802 pconf_sz = ARRAY_SIZE(core_padconf_array_essential_am572x_idk);
803 iod = iodelay_cfg_array_am572x_idk;
804 iod_sz = ARRAY_SIZE(iodelay_cfg_array_am572x_idk);
Lokesh Vutla1e3425c2017-12-29 11:47:55 +0530805 } else if (board_is_am574x_idk()) {
806 pconf = core_padconf_array_essential_am574x_idk;
807 pconf_sz = ARRAY_SIZE(core_padconf_array_essential_am574x_idk);
808 iod = iodelay_cfg_array_am574x_idk;
809 iod_sz = ARRAY_SIZE(iodelay_cfg_array_am574x_idk);
Steve Kipiszc95cddd2016-11-25 11:14:24 +0530810 } else if (board_is_am571x_idk()) {
811 pconf = core_padconf_array_essential_am571x_idk;
812 pconf_sz = ARRAY_SIZE(core_padconf_array_essential_am571x_idk);
813 iod = iodelay_cfg_array_am571x_idk;
814 iod_sz = ARRAY_SIZE(iodelay_cfg_array_am571x_idk);
Caleb Robey940d6372020-01-02 08:17:27 -0600815 } else if (board_is_bbai()) {
816 pconf = core_padconf_array_essential_bbai;
817 pconf_sz = ARRAY_SIZE(core_padconf_array_essential_bbai);
818 iod = iodelay_cfg_array_bbai;
819 iod_sz = ARRAY_SIZE(iodelay_cfg_array_bbai);
Steve Kipisz0ac8cea2016-04-08 17:01:29 -0500820 } else {
821 /* Common for X15/GPEVM */
822 pconf = core_padconf_array_essential_x15;
823 pconf_sz = ARRAY_SIZE(core_padconf_array_essential_x15);
Nishanth Menon8e3212e2016-11-25 11:14:22 +0530824 /* There never was an SR1.0 X15.. So.. */
825 if (omap_revision() == DRA752_ES1_1) {
826 iod = iodelay_cfg_array_x15_sr1_1;
827 iod_sz = ARRAY_SIZE(iodelay_cfg_array_x15_sr1_1);
828 } else {
829 /* Since full production should switch to SR2.0 */
830 iod = iodelay_cfg_array_x15_sr2_0;
831 iod_sz = ARRAY_SIZE(iodelay_cfg_array_x15_sr2_0);
832 }
Steve Kipisz0ac8cea2016-04-08 17:01:29 -0500833 }
834
Nishanth Menon8e3212e2016-11-25 11:14:22 +0530835 /* Setup I/O isolation */
836 ret = __recalibrate_iodelay_start();
837 if (ret)
838 goto err;
839
840 /* Do the muxing here */
841 do_set_mux32((*ctrl)->control_padconf_core_base, pconf, pconf_sz);
842
843 /* Now do the weird minor deltas that should be safe */
844 if (board_is_x15() || board_is_am572x_evm()) {
Lokesh Vutla816178b2017-07-16 19:59:19 +0530845 if (board_is_x15_revb1() || board_is_am572x_evm_reva3() ||
846 board_is_x15_revc()) {
Nishanth Menon8e3212e2016-11-25 11:14:22 +0530847 pconf = core_padconf_array_delta_x15_sr2_0;
848 pconf_sz = ARRAY_SIZE(core_padconf_array_delta_x15_sr2_0);
849 } else {
850 pconf = core_padconf_array_delta_x15_sr1_1;
851 pconf_sz = ARRAY_SIZE(core_padconf_array_delta_x15_sr1_1);
852 }
853 do_set_mux32((*ctrl)->control_padconf_core_base, pconf, pconf_sz);
854 }
855
Roger Quadros26130592017-03-13 15:04:28 +0200856 if (board_is_am571x_idk()) {
857 if (am571x_idk_needs_lcd()) {
858 pconf = core_padconf_array_vout_am571x_idk;
859 pconf_sz = ARRAY_SIZE(core_padconf_array_vout_am571x_idk);
Lokesh Vutla3cb4c622017-06-05 14:48:16 +0530860 delta_iod = iodelay_cfg_array_am571x_idk_4port;
861 delta_iod_sz = ARRAY_SIZE(iodelay_cfg_array_am571x_idk_4port);
862
Roger Quadros26130592017-03-13 15:04:28 +0200863 } else {
864 pconf = core_padconf_array_icss1eth_am571x_idk;
865 pconf_sz = ARRAY_SIZE(core_padconf_array_icss1eth_am571x_idk);
866 }
867 do_set_mux32((*ctrl)->control_padconf_core_base, pconf, pconf_sz);
868 }
869
Nishanth Menon8e3212e2016-11-25 11:14:22 +0530870 /* Setup IOdelay configuration */
871 ret = do_set_iodelay((*ctrl)->iodelay_config_base, iod, iod_sz);
Lokesh Vutla3cb4c622017-06-05 14:48:16 +0530872 if (delta_iod_sz)
873 ret = do_set_iodelay((*ctrl)->iodelay_config_base, delta_iod,
874 delta_iod_sz);
875
Nishanth Menon8e3212e2016-11-25 11:14:22 +0530876err:
877 /* Closeup.. remove isolation */
878 __recalibrate_iodelay_end(ret);
Lokesh Vutlac3d39f92015-06-04 16:42:41 +0530879}
880#endif
881
Masahiro Yamada0a780172017-05-09 20:31:39 +0900882#if defined(CONFIG_MMC)
Felipe Balbi4750eb62014-11-10 14:02:44 -0600883int board_mmc_init(bd_t *bis)
884{
885 omap_mmc_init(0, 0, 0, -1, -1);
886 omap_mmc_init(1, 0, 0, -1, -1);
887 return 0;
888}
Kishon Vijay Abraham I110ed012018-01-30 16:01:52 +0100889
890static const struct mmc_platform_fixups am57x_es1_1_mmc1_fixups = {
891 .hw_rev = "rev11",
892 .unsupported_caps = MMC_CAP(MMC_HS_200) |
893 MMC_CAP(UHS_SDR104),
894 .max_freq = 96000000,
895};
896
897static const struct mmc_platform_fixups am57x_es1_1_mmc23_fixups = {
898 .hw_rev = "rev11",
899 .unsupported_caps = MMC_CAP(MMC_HS_200) |
900 MMC_CAP(UHS_SDR104) |
901 MMC_CAP(UHS_SDR50),
902 .max_freq = 48000000,
903};
904
905const struct mmc_platform_fixups *platform_fixups_mmc(uint32_t addr)
906{
907 switch (omap_revision()) {
908 case DRA752_ES1_0:
909 case DRA752_ES1_1:
910 if (addr == OMAP_HSMMC1_BASE)
911 return &am57x_es1_1_mmc1_fixups;
912 else
913 return &am57x_es1_1_mmc23_fixups;
914 default:
915 return NULL;
916 }
917}
Felipe Balbi4750eb62014-11-10 14:02:44 -0600918#endif
919
920#if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_OS_BOOT)
921int spl_start_uboot(void)
922{
923 /* break into full u-boot on 'c' */
924 if (serial_tstc() && serial_getc() == 'c')
925 return 1;
926
927#ifdef CONFIG_SPL_ENV_SUPPORT
928 env_init();
Simon Glass17539572017-08-03 12:22:07 -0600929 env_load();
Simon Glass22c34c22017-08-03 12:22:13 -0600930 if (env_get_yesno("boot_os") != 1)
Felipe Balbi4750eb62014-11-10 14:02:44 -0600931 return 1;
932#endif
933
934 return 0;
935}
936#endif
937
938#ifdef CONFIG_DRIVER_TI_CPSW
939
940/* Delay value to add to calibrated value */
941#define RGMII0_TXCTL_DLY_VAL ((0x3 << 5) + 0x8)
942#define RGMII0_TXD0_DLY_VAL ((0x3 << 5) + 0x8)
943#define RGMII0_TXD1_DLY_VAL ((0x3 << 5) + 0x2)
944#define RGMII0_TXD2_DLY_VAL ((0x4 << 5) + 0x0)
945#define RGMII0_TXD3_DLY_VAL ((0x4 << 5) + 0x0)
946#define VIN2A_D13_DLY_VAL ((0x3 << 5) + 0x8)
947#define VIN2A_D17_DLY_VAL ((0x3 << 5) + 0x8)
948#define VIN2A_D16_DLY_VAL ((0x3 << 5) + 0x2)
949#define VIN2A_D15_DLY_VAL ((0x4 << 5) + 0x0)
950#define VIN2A_D14_DLY_VAL ((0x4 << 5) + 0x0)
951
952static void cpsw_control(int enabled)
953{
954 /* VTP can be added here */
955}
956
957static struct cpsw_slave_data cpsw_slaves[] = {
958 {
959 .slave_reg_ofs = 0x208,
960 .sliver_reg_ofs = 0xd80,
961 .phy_addr = 1,
962 },
963 {
964 .slave_reg_ofs = 0x308,
965 .sliver_reg_ofs = 0xdc0,
966 .phy_addr = 2,
967 },
968};
969
970static struct cpsw_platform_data cpsw_data = {
971 .mdio_base = CPSW_MDIO_BASE,
972 .cpsw_base = CPSW_BASE,
973 .mdio_div = 0xff,
974 .channels = 8,
975 .cpdma_reg_ofs = 0x800,
976 .slaves = 1,
977 .slave_data = cpsw_slaves,
978 .ale_reg_ofs = 0xd00,
979 .ale_entries = 1024,
980 .host_port_reg_ofs = 0x108,
981 .hw_stats_reg_ofs = 0x900,
982 .bd_ram_ofs = 0x2000,
983 .mac_control = (1 << 5),
984 .control = cpsw_control,
985 .host_port_num = 0,
986 .version = CPSW_CTRL_VERSION_2,
987};
988
Roger Quadros64217a22016-03-18 13:18:12 +0200989static u64 mac_to_u64(u8 mac[6])
990{
991 int i;
992 u64 addr = 0;
993
994 for (i = 0; i < 6; i++) {
995 addr <<= 8;
996 addr |= mac[i];
997 }
998
999 return addr;
1000}
1001
1002static void u64_to_mac(u64 addr, u8 mac[6])
1003{
1004 mac[5] = addr;
1005 mac[4] = addr >> 8;
1006 mac[3] = addr >> 16;
1007 mac[2] = addr >> 24;
1008 mac[1] = addr >> 32;
1009 mac[0] = addr >> 40;
1010}
1011
Felipe Balbi4750eb62014-11-10 14:02:44 -06001012int board_eth_init(bd_t *bis)
1013{
1014 int ret;
1015 uint8_t mac_addr[6];
1016 uint32_t mac_hi, mac_lo;
1017 uint32_t ctrl_val;
Roger Quadros64217a22016-03-18 13:18:12 +02001018 int i;
1019 u64 mac1, mac2;
1020 u8 mac_addr1[6], mac_addr2[6];
1021 int num_macs;
Felipe Balbi4750eb62014-11-10 14:02:44 -06001022
1023 /* try reading mac address from efuse */
1024 mac_lo = readl((*ctrl)->control_core_mac_id_0_lo);
1025 mac_hi = readl((*ctrl)->control_core_mac_id_0_hi);
1026 mac_addr[0] = (mac_hi & 0xFF0000) >> 16;
1027 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
1028 mac_addr[2] = mac_hi & 0xFF;
1029 mac_addr[3] = (mac_lo & 0xFF0000) >> 16;
1030 mac_addr[4] = (mac_lo & 0xFF00) >> 8;
1031 mac_addr[5] = mac_lo & 0xFF;
1032
Simon Glass64b723f2017-08-03 12:22:12 -06001033 if (!env_get("ethaddr")) {
Felipe Balbi4750eb62014-11-10 14:02:44 -06001034 printf("<ethaddr> not set. Validating first E-fuse MAC\n");
1035
Joe Hershberger8ecdbed2015-04-08 01:41:04 -05001036 if (is_valid_ethaddr(mac_addr))
Simon Glass8551d552017-08-03 12:22:11 -06001037 eth_env_set_enetaddr("ethaddr", mac_addr);
Felipe Balbi4750eb62014-11-10 14:02:44 -06001038 }
1039
1040 mac_lo = readl((*ctrl)->control_core_mac_id_1_lo);
1041 mac_hi = readl((*ctrl)->control_core_mac_id_1_hi);
1042 mac_addr[0] = (mac_hi & 0xFF0000) >> 16;
1043 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
1044 mac_addr[2] = mac_hi & 0xFF;
1045 mac_addr[3] = (mac_lo & 0xFF0000) >> 16;
1046 mac_addr[4] = (mac_lo & 0xFF00) >> 8;
1047 mac_addr[5] = mac_lo & 0xFF;
1048
Simon Glass64b723f2017-08-03 12:22:12 -06001049 if (!env_get("eth1addr")) {
Joe Hershberger8ecdbed2015-04-08 01:41:04 -05001050 if (is_valid_ethaddr(mac_addr))
Simon Glass8551d552017-08-03 12:22:11 -06001051 eth_env_set_enetaddr("eth1addr", mac_addr);
Felipe Balbi4750eb62014-11-10 14:02:44 -06001052 }
1053
1054 ctrl_val = readl((*ctrl)->control_core_control_io1) & (~0x33);
1055 ctrl_val |= 0x22;
1056 writel(ctrl_val, (*ctrl)->control_core_control_io1);
1057
Steve Kipiszc95cddd2016-11-25 11:14:24 +05301058 /* The phy address for the AM57xx IDK are different than x15 */
Lokesh Vutla6e9635c2017-12-29 11:47:53 +05301059 if (board_is_am572x_idk() || board_is_am571x_idk() ||
1060 board_is_am574x_idk()) {
Steve Kipisz0ac8cea2016-04-08 17:01:29 -05001061 cpsw_data.slave_data[0].phy_addr = 0;
1062 cpsw_data.slave_data[1].phy_addr = 1;
1063 }
1064
Felipe Balbi4750eb62014-11-10 14:02:44 -06001065 ret = cpsw_register(&cpsw_data);
1066 if (ret < 0)
1067 printf("Error %d registering CPSW switch\n", ret);
1068
Roger Quadros64217a22016-03-18 13:18:12 +02001069 /*
1070 * Export any Ethernet MAC addresses from EEPROM.
1071 * On AM57xx the 2 MAC addresses define the address range
1072 */
1073 board_ti_get_eth_mac_addr(0, mac_addr1);
1074 board_ti_get_eth_mac_addr(1, mac_addr2);
1075
1076 if (is_valid_ethaddr(mac_addr1) && is_valid_ethaddr(mac_addr2)) {
1077 mac1 = mac_to_u64(mac_addr1);
1078 mac2 = mac_to_u64(mac_addr2);
1079
1080 /* must contain an address range */
1081 num_macs = mac2 - mac1 + 1;
1082 /* <= 50 to protect against user programming error */
1083 if (num_macs > 0 && num_macs <= 50) {
1084 for (i = 0; i < num_macs; i++) {
1085 u64_to_mac(mac1 + i, mac_addr);
1086 if (is_valid_ethaddr(mac_addr)) {
Simon Glass8551d552017-08-03 12:22:11 -06001087 eth_env_set_enetaddr_by_index("eth",
1088 i + 2,
1089 mac_addr);
Roger Quadros64217a22016-03-18 13:18:12 +02001090 }
1091 }
1092 }
1093 }
1094
Felipe Balbi4750eb62014-11-10 14:02:44 -06001095 return ret;
1096}
1097#endif
Lokesh Vutla9f150672015-06-16 20:36:05 +05301098
1099#ifdef CONFIG_BOARD_EARLY_INIT_F
1100/* VTT regulator enable */
1101static inline void vtt_regulator_enable(void)
1102{
1103 if (omap_hw_init_context() == OMAP_INIT_CONTEXT_UBOOT_AFTER_SPL)
1104 return;
1105
1106 gpio_request(GPIO_DDR_VTT_EN, "ddr_vtt_en");
1107 gpio_direction_output(GPIO_DDR_VTT_EN, 1);
1108}
1109
1110int board_early_init_f(void)
1111{
1112 vtt_regulator_enable();
1113 return 0;
1114}
1115#endif
Daniel Allred7ceffb22016-05-19 19:10:54 -05001116
1117#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
1118int ft_board_setup(void *blob, bd_t *bd)
1119{
1120 ft_cpu_setup(blob, bd);
1121
1122 return 0;
1123}
1124#endif
Lokesh Vutla00bf8b22016-06-10 09:35:43 +05301125
1126#ifdef CONFIG_SPL_LOAD_FIT
1127int board_fit_config_name_match(const char *name)
1128{
Lokesh Vutla638e1c02016-11-25 11:14:20 +05301129 if (board_is_x15()) {
1130 if (board_is_x15_revb1()) {
1131 if (!strcmp(name, "am57xx-beagle-x15-revb1"))
1132 return 0;
Lokesh Vutlaf35589c2017-08-23 11:39:06 +05301133 } else if (board_is_x15_revc()) {
1134 if (!strcmp(name, "am57xx-beagle-x15-revc"))
1135 return 0;
Lokesh Vutla638e1c02016-11-25 11:14:20 +05301136 } else if (!strcmp(name, "am57xx-beagle-x15")) {
1137 return 0;
1138 }
1139 } else if (board_is_am572x_evm() &&
1140 !strcmp(name, "am57xx-beagle-x15")) {
Lokesh Vutla00bf8b22016-06-10 09:35:43 +05301141 return 0;
Lokesh Vutla638e1c02016-11-25 11:14:20 +05301142 } else if (board_is_am572x_idk() && !strcmp(name, "am572x-idk")) {
Schuyler Patton99519852016-06-10 09:35:45 +05301143 return 0;
Lokesh Vutla58a3c1b2017-12-29 11:47:57 +05301144 } else if (board_is_am574x_idk() && !strcmp(name, "am574x-idk")) {
1145 return 0;
Schuyler Pattonc665e272016-11-25 11:14:25 +05301146 } else if (board_is_am571x_idk() && !strcmp(name, "am571x-idk")) {
1147 return 0;
Caleb Robey940d6372020-01-02 08:17:27 -06001148 } else if (board_is_bbai() && !strcmp(name, "am5729-beagleboneai")) {
1149 return 0;
Lokesh Vutla638e1c02016-11-25 11:14:20 +05301150 }
1151
1152 return -1;
Lokesh Vutla00bf8b22016-06-10 09:35:43 +05301153}
1154#endif
Andreas Dannenberg5cf344b2016-06-27 09:19:22 -05001155
Andrew F. Davisd3555832019-02-11 08:00:08 -06001156#if CONFIG_IS_ENABLED(FASTBOOT) && !CONFIG_IS_ENABLED(ENV_IS_NOWHERE)
1157int fastboot_set_reboot_flag(void)
1158{
1159 printf("Setting reboot to fastboot flag ...\n");
1160 env_set("dofastboot", "1");
1161 env_save();
1162 return 0;
1163}
1164#endif
1165
Caleb Robey0dfcc932020-01-02 08:17:25 -06001166#ifdef CONFIG_SUPPORT_EMMC_BOOT
1167static int board_bootmode_has_emmc(void)
1168{
1169 /* Check that boot mode is same as BBAI */
1170 if (gd->arch.omap_boot_mode != 2)
1171 return -EIO;
1172
1173 return 0;
1174}
1175#endif
1176
Andreas Dannenberg5cf344b2016-06-27 09:19:22 -05001177#ifdef CONFIG_TI_SECURE_DEVICE
1178void board_fit_image_post_process(void **p_image, size_t *p_size)
1179{
1180 secure_boot_verify_image(p_image, p_size);
1181}
Andrew F. Davis7d250622016-11-29 16:33:26 -06001182
1183void board_tee_image_process(ulong tee_image, size_t tee_size)
1184{
1185 secure_tee_install((u32)tee_image);
1186}
1187
1188U_BOOT_FIT_LOADABLE_HANDLER(IH_TYPE_TEE, board_tee_image_process);
Andreas Dannenberg5cf344b2016-06-27 09:19:22 -05001189#endif