blob: c755821b74f9d55abc00a32754c84212b08d0ad1 [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 Glassa7b51302019-11-14 12:57:46 -070012#include <init.h>
Felipe Balbi4750eb62014-11-10 14:02:44 -060013#include <palmas.h>
14#include <sata.h>
Simon Glass36736182019-11-14 12:57:24 -070015#include <serial.h>
Felipe Balbi4750eb62014-11-10 14:02:44 -060016#include <usb.h>
17#include <asm/omap_common.h>
Andreas Dannenberg5cf344b2016-06-27 09:19:22 -050018#include <asm/omap_sec_common.h>
Felipe Balbi4750eb62014-11-10 14:02:44 -060019#include <asm/emif.h>
Lokesh Vutla9f150672015-06-16 20:36:05 +053020#include <asm/gpio.h>
21#include <asm/arch/gpio.h>
Felipe Balbi4750eb62014-11-10 14:02:44 -060022#include <asm/arch/clock.h>
Lokesh Vutlac3d39f92015-06-04 16:42:41 +053023#include <asm/arch/dra7xx_iodelay.h>
Felipe Balbi4750eb62014-11-10 14:02:44 -060024#include <asm/arch/sys_proto.h>
25#include <asm/arch/mmc_host_def.h>
26#include <asm/arch/sata.h>
27#include <asm/arch/gpio.h>
Kishon Vijay Abraham I5f19b2d2015-08-19 14:13:19 +053028#include <asm/arch/omap.h>
Kishon Vijay Abraham I5f19b2d2015-08-19 14:13:19 +053029#include <usb.h>
30#include <linux/usb/gadget.h>
31#include <dwc3-uboot.h>
32#include <dwc3-omap-uboot.h>
33#include <ti-usb-phy-uboot.h>
Kishon Vijay Abraham I110ed012018-01-30 16:01:52 +010034#include <mmc.h>
Tero Kristodfbc6b82019-09-27 19:14:27 +030035#include <dm/uclass.h>
Felipe Balbi4750eb62014-11-10 14:02:44 -060036
Kipisz, Steven161f1382016-02-24 12:30:58 -060037#include "../common/board_detect.h"
Felipe Balbi4750eb62014-11-10 14:02:44 -060038#include "mux_data.h"
39
Kipisz, Steven161f1382016-02-24 12:30:58 -060040#define board_is_x15() board_ti_is("BBRDX15_")
Lokesh Vutla638e1c02016-11-25 11:14:20 +053041#define board_is_x15_revb1() (board_ti_is("BBRDX15_") && \
Lokesh Vutlaab4f71e2017-07-16 19:59:18 +053042 !strncmp("B.10", board_ti_get_rev(), 3))
Lokesh Vutla816178b2017-07-16 19:59:19 +053043#define board_is_x15_revc() (board_ti_is("BBRDX15_") && \
44 !strncmp("C.00", board_ti_get_rev(), 3))
Kipisz, Steven161f1382016-02-24 12:30:58 -060045#define board_is_am572x_evm() board_ti_is("AM572PM_")
Nishanth Menona2aea1c2016-11-25 11:14:19 +053046#define board_is_am572x_evm_reva3() \
47 (board_ti_is("AM572PM_") && \
Lokesh Vutlaab4f71e2017-07-16 19:59:18 +053048 !strncmp("A.30", board_ti_get_rev(), 3))
Lokesh Vutla374aea02017-12-29 11:47:52 +053049#define board_is_am574x_idk() board_ti_is("AM574IDK")
Steve Kipisz0ac8cea2016-04-08 17:01:29 -050050#define board_is_am572x_idk() board_ti_is("AM572IDK")
Steve Kipiszc95cddd2016-11-25 11:14:24 +053051#define board_is_am571x_idk() board_ti_is("AM571IDK")
Kipisz, Steven161f1382016-02-24 12:30:58 -060052
Felipe Balbi4750eb62014-11-10 14:02:44 -060053#ifdef CONFIG_DRIVER_TI_CPSW
54#include <cpsw.h>
55#endif
56
57DECLARE_GLOBAL_DATA_PTR;
58
Roger Quadros26130592017-03-13 15:04:28 +020059#define GPIO_ETH_LCD GPIO_TO_PIN(2, 22)
Lokesh Vutla9f150672015-06-16 20:36:05 +053060/* GPIO 7_11 */
61#define GPIO_DDR_VTT_EN 203
62
Nishanth Menond0f399c2017-03-13 15:04:30 +020063/* Touch screen controller to identify the LCD */
64#define OSD_TS_FT_BUS_ADDRESS 0
65#define OSD_TS_FT_CHIP_ADDRESS 0x38
66#define OSD_TS_FT_REG_ID 0xA3
67/*
68 * Touchscreen IDs for various OSD panels
69 * Ref: http://www.osddisplays.com/TI/OSD101T2587-53TS_A.1.pdf
70 */
71/* Used on newer osd101t2587 Panels */
72#define OSD_TS_FT_ID_5x46 0x54
73/* Used on older osd101t2045 Panels */
74#define OSD_TS_FT_ID_5606 0x08
75
Kipisz, Steven161f1382016-02-24 12:30:58 -060076#define SYSINFO_BOARD_NAME_MAX_LEN 45
77
Keerthyee85ebe2016-11-30 15:02:53 +053078#define TPS65903X_PRIMARY_SECONDARY_PAD2 0xFB
79#define TPS65903X_PAD2_POWERHOLD_MASK 0x20
80
Felipe Balbi4750eb62014-11-10 14:02:44 -060081const struct omap_sysinfo sysinfo = {
Kipisz, Steven161f1382016-02-24 12:30:58 -060082 "Board: UNKNOWN(BeagleBoard X15?) REV UNKNOWN\n"
Felipe Balbi4750eb62014-11-10 14:02:44 -060083};
84
85static const struct dmm_lisa_map_regs beagle_x15_lisa_regs = {
86 .dmm_lisa_map_3 = 0x80740300,
87 .is_ma_present = 0x1
88};
89
Steve Kipiszc95cddd2016-11-25 11:14:24 +053090static const struct dmm_lisa_map_regs am571x_idk_lisa_regs = {
91 .dmm_lisa_map_3 = 0x80640100,
92 .is_ma_present = 0x1
93};
94
Lokesh Vutlacbd70db2017-12-29 11:47:54 +053095static const struct dmm_lisa_map_regs am574x_idk_lisa_regs = {
96 .dmm_lisa_map_2 = 0xc0600200,
97 .dmm_lisa_map_3 = 0x80600100,
98 .is_ma_present = 0x1
99};
100
Felipe Balbi4750eb62014-11-10 14:02:44 -0600101void emif_get_dmm_regs(const struct dmm_lisa_map_regs **dmm_lisa_regs)
102{
Steve Kipiszc95cddd2016-11-25 11:14:24 +0530103 if (board_is_am571x_idk())
104 *dmm_lisa_regs = &am571x_idk_lisa_regs;
Lokesh Vutlacbd70db2017-12-29 11:47:54 +0530105 else if (board_is_am574x_idk())
106 *dmm_lisa_regs = &am574x_idk_lisa_regs;
Steve Kipiszc95cddd2016-11-25 11:14:24 +0530107 else
108 *dmm_lisa_regs = &beagle_x15_lisa_regs;
Felipe Balbi4750eb62014-11-10 14:02:44 -0600109}
110
111static const struct emif_regs beagle_x15_emif1_ddr3_532mhz_emif_regs = {
Keerthy66dd8062016-05-24 11:45:07 +0530112 .sdram_config_init = 0x61851b32,
113 .sdram_config = 0x61851b32,
114 .sdram_config2 = 0x08000000,
115 .ref_ctrl = 0x000040F1,
116 .ref_ctrl_final = 0x00001035,
117 .sdram_tim1 = 0xcccf36ab,
118 .sdram_tim2 = 0x308f7fda,
119 .sdram_tim3 = 0x409f88a8,
120 .read_idle_ctrl = 0x00050000,
121 .zq_config = 0x5007190b,
122 .temp_alert_config = 0x00000000,
123 .emif_ddr_phy_ctlr_1_init = 0x0024400b,
124 .emif_ddr_phy_ctlr_1 = 0x0e24400b,
125 .emif_ddr_ext_phy_ctrl_1 = 0x10040100,
126 .emif_ddr_ext_phy_ctrl_2 = 0x00910091,
127 .emif_ddr_ext_phy_ctrl_3 = 0x00950095,
128 .emif_ddr_ext_phy_ctrl_4 = 0x009b009b,
129 .emif_ddr_ext_phy_ctrl_5 = 0x009e009e,
130 .emif_rd_wr_lvl_rmp_win = 0x00000000,
131 .emif_rd_wr_lvl_rmp_ctl = 0x80000000,
132 .emif_rd_wr_lvl_ctl = 0x00000000,
133 .emif_rd_wr_exec_thresh = 0x00000305
Felipe Balbi4750eb62014-11-10 14:02:44 -0600134};
135
Lokesh Vutla979d2c32015-06-03 14:43:21 +0530136/* Ext phy ctrl regs 1-35 */
Felipe Balbi4750eb62014-11-10 14:02:44 -0600137static const u32 beagle_x15_emif1_ddr3_ext_phy_ctrl_const_regs[] = {
Lokesh Vutla979d2c32015-06-03 14:43:21 +0530138 0x10040100,
Lokesh Vutla306b5972016-03-08 09:11:35 +0530139 0x00910091,
140 0x00950095,
141 0x009B009B,
142 0x009E009E,
143 0x00980098,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600144 0x00340034,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600145 0x00350035,
Lokesh Vutla306b5972016-03-08 09:11:35 +0530146 0x00340034,
147 0x00310031,
148 0x00340034,
149 0x007F007F,
150 0x007F007F,
151 0x007F007F,
152 0x007F007F,
153 0x007F007F,
154 0x00480048,
155 0x004A004A,
156 0x00520052,
157 0x00550055,
158 0x00500050,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600159 0x00000000,
160 0x00600020,
Lokesh Vutla979d2c32015-06-03 14:43:21 +0530161 0x40011080,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600162 0x08102040,
Lokesh Vutla306b5972016-03-08 09:11:35 +0530163 0x0,
164 0x0,
165 0x0,
166 0x0,
Lokesh Vutla51a0f1f2015-06-03 14:43:22 +0530167 0x0,
168 0x0,
169 0x0,
170 0x0,
Lokesh Vutla306b5972016-03-08 09:11:35 +0530171 0x0,
Lokesh Vutla51a0f1f2015-06-03 14:43:22 +0530172 0x0
Felipe Balbi4750eb62014-11-10 14:02:44 -0600173};
174
175static const struct emif_regs beagle_x15_emif2_ddr3_532mhz_emif_regs = {
Keerthy66dd8062016-05-24 11:45:07 +0530176 .sdram_config_init = 0x61851b32,
177 .sdram_config = 0x61851b32,
178 .sdram_config2 = 0x08000000,
179 .ref_ctrl = 0x000040F1,
180 .ref_ctrl_final = 0x00001035,
181 .sdram_tim1 = 0xcccf36b3,
182 .sdram_tim2 = 0x308f7fda,
183 .sdram_tim3 = 0x407f88a8,
184 .read_idle_ctrl = 0x00050000,
185 .zq_config = 0x5007190b,
186 .temp_alert_config = 0x00000000,
187 .emif_ddr_phy_ctlr_1_init = 0x0024400b,
188 .emif_ddr_phy_ctlr_1 = 0x0e24400b,
189 .emif_ddr_ext_phy_ctrl_1 = 0x10040100,
190 .emif_ddr_ext_phy_ctrl_2 = 0x00910091,
191 .emif_ddr_ext_phy_ctrl_3 = 0x00950095,
192 .emif_ddr_ext_phy_ctrl_4 = 0x009b009b,
193 .emif_ddr_ext_phy_ctrl_5 = 0x009e009e,
194 .emif_rd_wr_lvl_rmp_win = 0x00000000,
195 .emif_rd_wr_lvl_rmp_ctl = 0x80000000,
196 .emif_rd_wr_lvl_ctl = 0x00000000,
197 .emif_rd_wr_exec_thresh = 0x00000305
Felipe Balbi4750eb62014-11-10 14:02:44 -0600198};
199
200static const u32 beagle_x15_emif2_ddr3_ext_phy_ctrl_const_regs[] = {
Lokesh Vutla979d2c32015-06-03 14:43:21 +0530201 0x10040100,
Lokesh Vutla306b5972016-03-08 09:11:35 +0530202 0x00910091,
203 0x00950095,
204 0x009B009B,
205 0x009E009E,
206 0x00980098,
207 0x00340034,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600208 0x00350035,
Lokesh Vutla306b5972016-03-08 09:11:35 +0530209 0x00340034,
210 0x00310031,
211 0x00340034,
212 0x007F007F,
213 0x007F007F,
214 0x007F007F,
215 0x007F007F,
216 0x007F007F,
217 0x00480048,
218 0x004A004A,
219 0x00520052,
220 0x00550055,
221 0x00500050,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600222 0x00000000,
223 0x00600020,
Lokesh Vutla979d2c32015-06-03 14:43:21 +0530224 0x40011080,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600225 0x08102040,
Lokesh Vutla306b5972016-03-08 09:11:35 +0530226 0x0,
227 0x0,
228 0x0,
229 0x0,
230 0x0,
Lokesh Vutla51a0f1f2015-06-03 14:43:22 +0530231 0x0,
232 0x0,
233 0x0,
234 0x0,
235 0x0
Felipe Balbi4750eb62014-11-10 14:02:44 -0600236};
237
Steve Kipisz81c46742017-08-22 13:52:58 +0530238static const struct emif_regs am571x_emif1_ddr3_666mhz_emif_regs = {
239 .sdram_config_init = 0x61863332,
240 .sdram_config = 0x61863332,
241 .sdram_config2 = 0x08000000,
242 .ref_ctrl = 0x0000514d,
243 .ref_ctrl_final = 0x0000144a,
244 .sdram_tim1 = 0xd333887c,
Lokesh Vutlacbd70db2017-12-29 11:47:54 +0530245 .sdram_tim2 = 0x30b37fe3,
246 .sdram_tim3 = 0x409f8ad8,
Steve Kipisz81c46742017-08-22 13:52:58 +0530247 .read_idle_ctrl = 0x00050000,
248 .zq_config = 0x5007190b,
249 .temp_alert_config = 0x00000000,
250 .emif_ddr_phy_ctlr_1_init = 0x0024400f,
251 .emif_ddr_phy_ctlr_1 = 0x0e24400f,
252 .emif_ddr_ext_phy_ctrl_1 = 0x10040100,
253 .emif_ddr_ext_phy_ctrl_2 = 0x00910091,
254 .emif_ddr_ext_phy_ctrl_3 = 0x00950095,
255 .emif_ddr_ext_phy_ctrl_4 = 0x009b009b,
256 .emif_ddr_ext_phy_ctrl_5 = 0x009e009e,
257 .emif_rd_wr_lvl_rmp_win = 0x00000000,
258 .emif_rd_wr_lvl_rmp_ctl = 0x80000000,
259 .emif_rd_wr_lvl_ctl = 0x00000000,
260 .emif_rd_wr_exec_thresh = 0x00000305
261};
262
Lokesh Vutlacbd70db2017-12-29 11:47:54 +0530263static const struct emif_regs am574x_emif1_ddr3_666mhz_emif_ecc_regs = {
264 .sdram_config_init = 0x61863332,
265 .sdram_config = 0x61863332,
266 .sdram_config2 = 0x08000000,
267 .ref_ctrl = 0x0000514d,
268 .ref_ctrl_final = 0x0000144a,
269 .sdram_tim1 = 0xd333887c,
270 .sdram_tim2 = 0x30b37fe3,
271 .sdram_tim3 = 0x409f8ad8,
272 .read_idle_ctrl = 0x00050000,
273 .zq_config = 0x5007190b,
274 .temp_alert_config = 0x00000000,
275 .emif_ddr_phy_ctlr_1_init = 0x0024400f,
276 .emif_ddr_phy_ctlr_1 = 0x0e24400f,
277 .emif_ddr_ext_phy_ctrl_1 = 0x10040100,
278 .emif_ddr_ext_phy_ctrl_2 = 0x00910091,
279 .emif_ddr_ext_phy_ctrl_3 = 0x00950095,
280 .emif_ddr_ext_phy_ctrl_4 = 0x009b009b,
281 .emif_ddr_ext_phy_ctrl_5 = 0x009e009e,
282 .emif_rd_wr_lvl_rmp_win = 0x00000000,
283 .emif_rd_wr_lvl_rmp_ctl = 0x80000000,
284 .emif_rd_wr_lvl_ctl = 0x00000000,
285 .emif_rd_wr_exec_thresh = 0x00000305,
286 .emif_ecc_ctrl_reg = 0xD0000001,
287 .emif_ecc_address_range_1 = 0x3FFF0000,
288 .emif_ecc_address_range_2 = 0x00000000
289};
290
Felipe Balbi4750eb62014-11-10 14:02:44 -0600291void emif_get_reg_dump(u32 emif_nr, const struct emif_regs **regs)
292{
293 switch (emif_nr) {
294 case 1:
Steve Kipisz81c46742017-08-22 13:52:58 +0530295 if (board_is_am571x_idk())
296 *regs = &am571x_emif1_ddr3_666mhz_emif_regs;
Lokesh Vutlacbd70db2017-12-29 11:47:54 +0530297 else if (board_is_am574x_idk())
298 *regs = &am574x_emif1_ddr3_666mhz_emif_ecc_regs;
Steve Kipisz81c46742017-08-22 13:52:58 +0530299 else
300 *regs = &beagle_x15_emif1_ddr3_532mhz_emif_regs;
Felipe Balbi4750eb62014-11-10 14:02:44 -0600301 break;
302 case 2:
Lokesh Vutlacbd70db2017-12-29 11:47:54 +0530303 if (board_is_am574x_idk())
304 *regs = &am571x_emif1_ddr3_666mhz_emif_regs;
305 else
306 *regs = &beagle_x15_emif2_ddr3_532mhz_emif_regs;
Felipe Balbi4750eb62014-11-10 14:02:44 -0600307 break;
308 }
309}
310
311void emif_get_ext_phy_ctrl_const_regs(u32 emif_nr, const u32 **regs, u32 *size)
312{
313 switch (emif_nr) {
314 case 1:
315 *regs = beagle_x15_emif1_ddr3_ext_phy_ctrl_const_regs;
316 *size = ARRAY_SIZE(beagle_x15_emif1_ddr3_ext_phy_ctrl_const_regs);
317 break;
318 case 2:
319 *regs = beagle_x15_emif2_ddr3_ext_phy_ctrl_const_regs;
320 *size = ARRAY_SIZE(beagle_x15_emif2_ddr3_ext_phy_ctrl_const_regs);
321 break;
322 }
323}
324
325struct vcores_data beagle_x15_volts = {
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530326 .mpu.value[OPP_NOM] = VDD_MPU_DRA7_NOM,
327 .mpu.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_MPU_NOM,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600328 .mpu.efuse.reg_bits = DRA752_EFUSE_REGBITS,
329 .mpu.addr = TPS659038_REG_ADDR_SMPS12,
330 .mpu.pmic = &tps659038,
Keerthy66dd8062016-05-24 11:45:07 +0530331 .mpu.abb_tx_done_mask = OMAP_ABB_MPU_TXDONE_MASK,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600332
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530333 .eve.value[OPP_NOM] = VDD_EVE_DRA7_NOM,
334 .eve.value[OPP_OD] = VDD_EVE_DRA7_OD,
335 .eve.value[OPP_HIGH] = VDD_EVE_DRA7_HIGH,
336 .eve.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_DSPEVE_NOM,
337 .eve.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_DSPEVE_OD,
338 .eve.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_DSPEVE_HIGH,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600339 .eve.efuse.reg_bits = DRA752_EFUSE_REGBITS,
340 .eve.addr = TPS659038_REG_ADDR_SMPS45,
341 .eve.pmic = &tps659038,
Nishanth Menon59b92af2016-04-21 14:34:25 -0500342 .eve.abb_tx_done_mask = OMAP_ABB_EVE_TXDONE_MASK,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600343
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530344 .gpu.value[OPP_NOM] = VDD_GPU_DRA7_NOM,
345 .gpu.value[OPP_OD] = VDD_GPU_DRA7_OD,
346 .gpu.value[OPP_HIGH] = VDD_GPU_DRA7_HIGH,
347 .gpu.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_GPU_NOM,
348 .gpu.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_GPU_OD,
349 .gpu.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_GPU_HIGH,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600350 .gpu.efuse.reg_bits = DRA752_EFUSE_REGBITS,
351 .gpu.addr = TPS659038_REG_ADDR_SMPS45,
352 .gpu.pmic = &tps659038,
Nishanth Menon59b92af2016-04-21 14:34:25 -0500353 .gpu.abb_tx_done_mask = OMAP_ABB_GPU_TXDONE_MASK,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600354
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530355 .core.value[OPP_NOM] = VDD_CORE_DRA7_NOM,
356 .core.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_CORE_NOM,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600357 .core.efuse.reg_bits = DRA752_EFUSE_REGBITS,
358 .core.addr = TPS659038_REG_ADDR_SMPS6,
359 .core.pmic = &tps659038,
360
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530361 .iva.value[OPP_NOM] = VDD_IVA_DRA7_NOM,
362 .iva.value[OPP_OD] = VDD_IVA_DRA7_OD,
363 .iva.value[OPP_HIGH] = VDD_IVA_DRA7_HIGH,
364 .iva.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_IVA_NOM,
365 .iva.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_IVA_OD,
366 .iva.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_IVA_HIGH,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600367 .iva.efuse.reg_bits = DRA752_EFUSE_REGBITS,
368 .iva.addr = TPS659038_REG_ADDR_SMPS45,
369 .iva.pmic = &tps659038,
Nishanth Menon59b92af2016-04-21 14:34:25 -0500370 .iva.abb_tx_done_mask = OMAP_ABB_IVA_TXDONE_MASK,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600371};
372
Keerthy152e9932016-05-24 11:45:06 +0530373struct vcores_data am572x_idk_volts = {
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530374 .mpu.value[OPP_NOM] = VDD_MPU_DRA7_NOM,
375 .mpu.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_MPU_NOM,
Keerthy152e9932016-05-24 11:45:06 +0530376 .mpu.efuse.reg_bits = DRA752_EFUSE_REGBITS,
377 .mpu.addr = TPS659038_REG_ADDR_SMPS12,
378 .mpu.pmic = &tps659038,
379 .mpu.abb_tx_done_mask = OMAP_ABB_MPU_TXDONE_MASK,
380
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530381 .eve.value[OPP_NOM] = VDD_EVE_DRA7_NOM,
382 .eve.value[OPP_OD] = VDD_EVE_DRA7_OD,
383 .eve.value[OPP_HIGH] = VDD_EVE_DRA7_HIGH,
384 .eve.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_DSPEVE_NOM,
385 .eve.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_DSPEVE_OD,
386 .eve.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_DSPEVE_HIGH,
Keerthy152e9932016-05-24 11:45:06 +0530387 .eve.efuse.reg_bits = DRA752_EFUSE_REGBITS,
388 .eve.addr = TPS659038_REG_ADDR_SMPS45,
389 .eve.pmic = &tps659038,
390 .eve.abb_tx_done_mask = OMAP_ABB_EVE_TXDONE_MASK,
391
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530392 .gpu.value[OPP_NOM] = VDD_GPU_DRA7_NOM,
393 .gpu.value[OPP_OD] = VDD_GPU_DRA7_OD,
394 .gpu.value[OPP_HIGH] = VDD_GPU_DRA7_HIGH,
395 .gpu.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_GPU_NOM,
396 .gpu.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_GPU_OD,
397 .gpu.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_GPU_HIGH,
Keerthy152e9932016-05-24 11:45:06 +0530398 .gpu.efuse.reg_bits = DRA752_EFUSE_REGBITS,
399 .gpu.addr = TPS659038_REG_ADDR_SMPS6,
400 .gpu.pmic = &tps659038,
401 .gpu.abb_tx_done_mask = OMAP_ABB_GPU_TXDONE_MASK,
402
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530403 .core.value[OPP_NOM] = VDD_CORE_DRA7_NOM,
404 .core.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_CORE_NOM,
Keerthy152e9932016-05-24 11:45:06 +0530405 .core.efuse.reg_bits = DRA752_EFUSE_REGBITS,
406 .core.addr = TPS659038_REG_ADDR_SMPS7,
407 .core.pmic = &tps659038,
408
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530409 .iva.value[OPP_NOM] = VDD_IVA_DRA7_NOM,
410 .iva.value[OPP_OD] = VDD_IVA_DRA7_OD,
411 .iva.value[OPP_HIGH] = VDD_IVA_DRA7_HIGH,
412 .iva.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_IVA_NOM,
413 .iva.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_IVA_OD,
414 .iva.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_IVA_HIGH,
Keerthy152e9932016-05-24 11:45:06 +0530415 .iva.efuse.reg_bits = DRA752_EFUSE_REGBITS,
416 .iva.addr = TPS659038_REG_ADDR_SMPS8,
417 .iva.pmic = &tps659038,
418 .iva.abb_tx_done_mask = OMAP_ABB_IVA_TXDONE_MASK,
419};
420
Keerthy9cc2aee2017-05-25 15:37:34 +0530421struct vcores_data am571x_idk_volts = {
422 .mpu.value[OPP_NOM] = VDD_MPU_DRA7_NOM,
423 .mpu.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_MPU_NOM,
424 .mpu.efuse.reg_bits = DRA752_EFUSE_REGBITS,
425 .mpu.addr = TPS659038_REG_ADDR_SMPS12,
426 .mpu.pmic = &tps659038,
427 .mpu.abb_tx_done_mask = OMAP_ABB_MPU_TXDONE_MASK,
428
429 .eve.value[OPP_NOM] = VDD_EVE_DRA7_NOM,
430 .eve.value[OPP_OD] = VDD_EVE_DRA7_OD,
431 .eve.value[OPP_HIGH] = VDD_EVE_DRA7_HIGH,
432 .eve.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_DSPEVE_NOM,
433 .eve.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_DSPEVE_OD,
434 .eve.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_DSPEVE_HIGH,
435 .eve.efuse.reg_bits = DRA752_EFUSE_REGBITS,
436 .eve.addr = TPS659038_REG_ADDR_SMPS45,
437 .eve.pmic = &tps659038,
438 .eve.abb_tx_done_mask = OMAP_ABB_EVE_TXDONE_MASK,
439
440 .gpu.value[OPP_NOM] = VDD_GPU_DRA7_NOM,
441 .gpu.value[OPP_OD] = VDD_GPU_DRA7_OD,
442 .gpu.value[OPP_HIGH] = VDD_GPU_DRA7_HIGH,
443 .gpu.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_GPU_NOM,
444 .gpu.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_GPU_OD,
445 .gpu.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_GPU_HIGH,
446 .gpu.efuse.reg_bits = DRA752_EFUSE_REGBITS,
447 .gpu.addr = TPS659038_REG_ADDR_SMPS6,
448 .gpu.pmic = &tps659038,
449 .gpu.abb_tx_done_mask = OMAP_ABB_GPU_TXDONE_MASK,
450
451 .core.value[OPP_NOM] = VDD_CORE_DRA7_NOM,
452 .core.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_CORE_NOM,
453 .core.efuse.reg_bits = DRA752_EFUSE_REGBITS,
454 .core.addr = TPS659038_REG_ADDR_SMPS7,
455 .core.pmic = &tps659038,
456
457 .iva.value[OPP_NOM] = VDD_IVA_DRA7_NOM,
458 .iva.value[OPP_OD] = VDD_IVA_DRA7_OD,
459 .iva.value[OPP_HIGH] = VDD_IVA_DRA7_HIGH,
460 .iva.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_IVA_NOM,
461 .iva.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_IVA_OD,
462 .iva.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_IVA_HIGH,
463 .iva.efuse.reg_bits = DRA752_EFUSE_REGBITS,
464 .iva.addr = TPS659038_REG_ADDR_SMPS45,
465 .iva.pmic = &tps659038,
466 .iva.abb_tx_done_mask = OMAP_ABB_IVA_TXDONE_MASK,
467};
468
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530469int get_voltrail_opp(int rail_offset)
470{
471 int opp;
472
473 switch (rail_offset) {
474 case VOLT_MPU:
475 opp = DRA7_MPU_OPP;
476 break;
477 case VOLT_CORE:
478 opp = DRA7_CORE_OPP;
479 break;
480 case VOLT_GPU:
481 opp = DRA7_GPU_OPP;
482 break;
483 case VOLT_EVE:
484 opp = DRA7_DSPEVE_OPP;
485 break;
486 case VOLT_IVA:
487 opp = DRA7_IVA_OPP;
488 break;
489 default:
490 opp = OPP_NOM;
491 }
492
493 return opp;
494}
495
496
Kipisz, Steven161f1382016-02-24 12:30:58 -0600497#ifdef CONFIG_SPL_BUILD
498/* No env to setup for SPL */
499static inline void setup_board_eeprom_env(void) { }
500
501/* Override function to read eeprom information */
502void do_board_detect(void)
503{
504 int rc;
505
506 rc = ti_i2c_eeprom_am_get(CONFIG_EEPROM_BUS_ADDRESS,
507 CONFIG_EEPROM_CHIP_ADDRESS);
508 if (rc)
509 printf("ti_i2c_eeprom_init failed %d\n", rc);
510}
511
512#else /* CONFIG_SPL_BUILD */
513
514/* Override function to read eeprom information: actual i2c read done by SPL*/
515void do_board_detect(void)
516{
517 char *bname = NULL;
518 int rc;
519
520 rc = ti_i2c_eeprom_am_get(CONFIG_EEPROM_BUS_ADDRESS,
521 CONFIG_EEPROM_CHIP_ADDRESS);
522 if (rc)
523 printf("ti_i2c_eeprom_init failed %d\n", rc);
524
525 if (board_is_x15())
526 bname = "BeagleBoard X15";
527 else if (board_is_am572x_evm())
528 bname = "AM572x EVM";
Lokesh Vutla374aea02017-12-29 11:47:52 +0530529 else if (board_is_am574x_idk())
530 bname = "AM574x IDK";
Steve Kipisz0ac8cea2016-04-08 17:01:29 -0500531 else if (board_is_am572x_idk())
532 bname = "AM572x IDK";
Steve Kipiszc95cddd2016-11-25 11:14:24 +0530533 else if (board_is_am571x_idk())
534 bname = "AM571x IDK";
Kipisz, Steven161f1382016-02-24 12:30:58 -0600535
536 if (bname)
537 snprintf(sysinfo.board_string, SYSINFO_BOARD_NAME_MAX_LEN,
538 "Board: %s REV %s\n", bname, board_ti_get_rev());
539}
540
541static void setup_board_eeprom_env(void)
542{
543 char *name = "beagle_x15";
544 int rc;
545
546 rc = ti_i2c_eeprom_am_get(CONFIG_EEPROM_BUS_ADDRESS,
547 CONFIG_EEPROM_CHIP_ADDRESS);
548 if (rc)
549 goto invalid_eeprom;
550
Nishanth Menona2aea1c2016-11-25 11:14:19 +0530551 if (board_is_x15()) {
Lokesh Vutla638e1c02016-11-25 11:14:20 +0530552 if (board_is_x15_revb1())
553 name = "beagle_x15_revb1";
Lokesh Vutla816178b2017-07-16 19:59:19 +0530554 else if (board_is_x15_revc())
555 name = "beagle_x15_revc";
Lokesh Vutla638e1c02016-11-25 11:14:20 +0530556 else
557 name = "beagle_x15";
Nishanth Menona2aea1c2016-11-25 11:14:19 +0530558 } else if (board_is_am572x_evm()) {
559 if (board_is_am572x_evm_reva3())
560 name = "am57xx_evm_reva3";
561 else
562 name = "am57xx_evm";
Lokesh Vutla374aea02017-12-29 11:47:52 +0530563 } else if (board_is_am574x_idk()) {
564 name = "am574x_idk";
Nishanth Menona2aea1c2016-11-25 11:14:19 +0530565 } else if (board_is_am572x_idk()) {
Steve Kipisz0ac8cea2016-04-08 17:01:29 -0500566 name = "am572x_idk";
Steve Kipiszc95cddd2016-11-25 11:14:24 +0530567 } else if (board_is_am571x_idk()) {
568 name = "am571x_idk";
Nishanth Menona2aea1c2016-11-25 11:14:19 +0530569 } else {
Kipisz, Steven161f1382016-02-24 12:30:58 -0600570 printf("Unidentified board claims %s in eeprom header\n",
571 board_ti_get_name());
Nishanth Menona2aea1c2016-11-25 11:14:19 +0530572 }
Kipisz, Steven161f1382016-02-24 12:30:58 -0600573
574invalid_eeprom:
575 set_board_info_env(name);
576}
577
578#endif /* CONFIG_SPL_BUILD */
579
Keerthy152e9932016-05-24 11:45:06 +0530580void vcores_init(void)
581{
Lokesh Vutla6e9635c2017-12-29 11:47:53 +0530582 if (board_is_am572x_idk() || board_is_am574x_idk())
Keerthy152e9932016-05-24 11:45:06 +0530583 *omap_vcores = &am572x_idk_volts;
Keerthy9cc2aee2017-05-25 15:37:34 +0530584 else if (board_is_am571x_idk())
585 *omap_vcores = &am571x_idk_volts;
Keerthy152e9932016-05-24 11:45:06 +0530586 else
587 *omap_vcores = &beagle_x15_volts;
588}
589
Felipe Balbi4750eb62014-11-10 14:02:44 -0600590void hw_data_init(void)
591{
592 *prcm = &dra7xx_prcm;
Steve Kipisz81c46742017-08-22 13:52:58 +0530593 if (is_dra72x())
594 *dplls_data = &dra72x_dplls;
Lokesh Vutla6e9635c2017-12-29 11:47:53 +0530595 else if (is_dra76x())
596 *dplls_data = &dra76x_dplls;
Steve Kipisz81c46742017-08-22 13:52:58 +0530597 else
598 *dplls_data = &dra7xx_dplls;
Felipe Balbi4750eb62014-11-10 14:02:44 -0600599 *ctrl = &dra7xx_ctrl;
600}
601
Roger Quadros26130592017-03-13 15:04:28 +0200602bool am571x_idk_needs_lcd(void)
603{
604 bool needs_lcd;
605
606 gpio_request(GPIO_ETH_LCD, "nLCD_Detect");
607 if (gpio_get_value(GPIO_ETH_LCD))
608 needs_lcd = false;
609 else
610 needs_lcd = true;
611
612 gpio_free(GPIO_ETH_LCD);
613
614 return needs_lcd;
615}
616
Felipe Balbi4750eb62014-11-10 14:02:44 -0600617int board_init(void)
618{
619 gpmc_init();
620 gd->bd->bi_boot_params = (CONFIG_SYS_SDRAM_BASE + 0x100);
621
622 return 0;
623}
624
Nishanth Menond0f399c2017-03-13 15:04:30 +0200625void am57x_idk_lcd_detect(void)
Felipe Balbi4750eb62014-11-10 14:02:44 -0600626{
Nishanth Menond0f399c2017-03-13 15:04:30 +0200627 int r = -ENODEV;
628 char *idk_lcd = "no";
Jean-Jacques Hiblot184ec9a2018-12-07 14:50:50 +0100629 struct udevice *dev;
Nishanth Menond0f399c2017-03-13 15:04:30 +0200630
631 /* Only valid for IDKs */
632 if (board_is_x15() || board_is_am572x_evm())
633 return;
634
635 /* Only AM571x IDK has gpio control detect.. so check that */
636 if (board_is_am571x_idk() && !am571x_idk_needs_lcd())
637 goto out;
638
Jean-Jacques Hiblot52a51512018-12-07 14:50:49 +0100639 r = i2c_get_chip_for_busnum(OSD_TS_FT_BUS_ADDRESS,
640 OSD_TS_FT_CHIP_ADDRESS, 1, &dev);
Nishanth Menond0f399c2017-03-13 15:04:30 +0200641 if (r) {
Jean-Jacques Hiblot52a51512018-12-07 14:50:49 +0100642 printf("%s: Failed to get I2C device %d/%d (ret %d)\n",
643 __func__, OSD_TS_FT_BUS_ADDRESS, OSD_TS_FT_CHIP_ADDRESS,
644 r);
Nishanth Menond0f399c2017-03-13 15:04:30 +0200645 /* AM572x IDK has no explicit settings for optional LCD kit */
Jean-Jacques Hiblot52a51512018-12-07 14:50:49 +0100646 if (board_is_am571x_idk())
Nishanth Menond0f399c2017-03-13 15:04:30 +0200647 printf("%s: Touch screen detect failed: %d!\n",
648 __func__, r);
Nishanth Menond0f399c2017-03-13 15:04:30 +0200649 goto out;
650 }
651
652 /* Read FT ID */
Jean-Jacques Hiblot52a51512018-12-07 14:50:49 +0100653 r = dm_i2c_reg_read(dev, OSD_TS_FT_REG_ID);
654 if (r < 0) {
Nishanth Menond0f399c2017-03-13 15:04:30 +0200655 printf("%s: Touch screen ID read %d:0x%02x[0x%02x] failed:%d\n",
656 __func__, OSD_TS_FT_BUS_ADDRESS, OSD_TS_FT_CHIP_ADDRESS,
657 OSD_TS_FT_REG_ID, r);
658 goto out;
659 }
660
Jean-Jacques Hiblot184ec9a2018-12-07 14:50:50 +0100661 switch (r) {
Nishanth Menond0f399c2017-03-13 15:04:30 +0200662 case OSD_TS_FT_ID_5606:
663 idk_lcd = "osd101t2045";
664 break;
665 case OSD_TS_FT_ID_5x46:
666 idk_lcd = "osd101t2587";
667 break;
668 default:
669 printf("%s: Unidentifed Touch screen ID 0x%02x\n",
Jean-Jacques Hiblot184ec9a2018-12-07 14:50:50 +0100670 __func__, r);
Nishanth Menond0f399c2017-03-13 15:04:30 +0200671 /* we will let default be "no lcd" */
672 }
673out:
Simon Glass6a38e412017-08-03 12:22:09 -0600674 env_set("idk_lcd", idk_lcd);
Nishanth Menond0f399c2017-03-13 15:04:30 +0200675 return;
676}
Roger Quadros26130592017-03-13 15:04:28 +0200677
Vignesh R98c5f632018-11-29 10:57:42 +0100678#if CONFIG_IS_ENABLED(DM_USB) && CONFIG_IS_ENABLED(OF_CONTROL)
679static int device_okay(const char *path)
680{
681 int node;
682
683 node = fdt_path_offset(gd->fdt_blob, path);
684 if (node < 0)
685 return 0;
686
687 return fdtdec_get_is_enabled(gd->fdt_blob, node);
688}
689#endif
690
Nishanth Menond0f399c2017-03-13 15:04:30 +0200691int board_late_init(void)
692{
Kipisz, Steven161f1382016-02-24 12:30:58 -0600693 setup_board_eeprom_env();
Keerthyee85ebe2016-11-30 15:02:53 +0530694 u8 val;
Tero Kristodfbc6b82019-09-27 19:14:27 +0300695 struct udevice *dev;
Kipisz, Steven161f1382016-02-24 12:30:58 -0600696
Felipe Balbi4750eb62014-11-10 14:02:44 -0600697 /*
698 * DEV_CTRL.DEV_ON = 1 please - else palmas switches off in 8 seconds
699 * This is the POWERHOLD-in-Low behavior.
700 */
701 palmas_i2c_write_u8(TPS65903X_CHIP_P1, 0xA0, 0x1);
Lokesh Vutla2c47e8c2016-11-29 11:58:02 +0530702
703 /*
704 * Default FIT boot on HS devices. Non FIT images are not allowed
705 * on HS devices.
706 */
707 if (get_device_type() == HS_DEVICE)
Simon Glass6a38e412017-08-03 12:22:09 -0600708 env_set("boot_fit", "1");
Lokesh Vutla2c47e8c2016-11-29 11:58:02 +0530709
Keerthyee85ebe2016-11-30 15:02:53 +0530710 /*
711 * Set the GPIO7 Pad to POWERHOLD. This has higher priority
712 * over DEV_CTRL.DEV_ON bit. This can be reset in case of
713 * PMIC Power off. So to be on the safer side set it back
714 * to POWERHOLD mode irrespective of the current state.
715 */
716 palmas_i2c_read_u8(TPS65903X_CHIP_P1, TPS65903X_PRIMARY_SECONDARY_PAD2,
717 &val);
718 val = val | TPS65903X_PAD2_POWERHOLD_MASK;
719 palmas_i2c_write_u8(TPS65903X_CHIP_P1, TPS65903X_PRIMARY_SECONDARY_PAD2,
720 val);
721
Semen Protsenko4b0721f2017-02-13 19:09:37 +0200722 omap_die_id_serial();
Semen Protsenkob72dccd2017-05-22 19:16:41 +0300723 omap_set_fastboot_vars();
Semen Protsenko4b0721f2017-02-13 19:09:37 +0200724
Nishanth Menond0f399c2017-03-13 15:04:30 +0200725 am57x_idk_lcd_detect();
Roger Quadros26130592017-03-13 15:04:28 +0200726
Tero Kristodfbc6b82019-09-27 19:14:27 +0300727 /* Just probe the potentially supported cdce913 device */
728 uclass_get_device(UCLASS_CLK, 0, &dev);
729
Roger Quadros26130592017-03-13 15:04:28 +0200730#if !defined(CONFIG_SPL_BUILD)
731 board_ti_set_ethaddr(2);
732#endif
733
Vignesh R98c5f632018-11-29 10:57:42 +0100734#if CONFIG_IS_ENABLED(DM_USB) && CONFIG_IS_ENABLED(OF_CONTROL)
735 if (device_okay("/ocp/omap_dwc3_1@48880000"))
736 enable_usb_clocks(0);
737 if (device_okay("/ocp/omap_dwc3_2@488c0000"))
738 enable_usb_clocks(1);
739#endif
Felipe Balbi4750eb62014-11-10 14:02:44 -0600740 return 0;
741}
742
Paul Kocialkowskia00b1e52016-02-27 19:18:56 +0100743void set_muxconf_regs(void)
Felipe Balbi4750eb62014-11-10 14:02:44 -0600744{
745 do_set_mux32((*ctrl)->control_padconf_core_base,
Lokesh Vutlac3d39f92015-06-04 16:42:41 +0530746 early_padconf, ARRAY_SIZE(early_padconf));
Felipe Balbi4750eb62014-11-10 14:02:44 -0600747}
748
Lokesh Vutlac3d39f92015-06-04 16:42:41 +0530749#ifdef CONFIG_IODELAY_RECALIBRATION
750void recalibrate_iodelay(void)
751{
Steve Kipisz0ac8cea2016-04-08 17:01:29 -0500752 const struct pad_conf_entry *pconf;
Lokesh Vutla3cb4c622017-06-05 14:48:16 +0530753 const struct iodelay_cfg_entry *iod, *delta_iod;
754 int pconf_sz, iod_sz, delta_iod_sz = 0;
Nishanth Menon8e3212e2016-11-25 11:14:22 +0530755 int ret;
Steve Kipisz0ac8cea2016-04-08 17:01:29 -0500756
Lokesh Vutla1e3425c2017-12-29 11:47:55 +0530757 if (board_is_am572x_idk()) {
Steve Kipisz0ac8cea2016-04-08 17:01:29 -0500758 pconf = core_padconf_array_essential_am572x_idk;
759 pconf_sz = ARRAY_SIZE(core_padconf_array_essential_am572x_idk);
760 iod = iodelay_cfg_array_am572x_idk;
761 iod_sz = ARRAY_SIZE(iodelay_cfg_array_am572x_idk);
Lokesh Vutla1e3425c2017-12-29 11:47:55 +0530762 } else if (board_is_am574x_idk()) {
763 pconf = core_padconf_array_essential_am574x_idk;
764 pconf_sz = ARRAY_SIZE(core_padconf_array_essential_am574x_idk);
765 iod = iodelay_cfg_array_am574x_idk;
766 iod_sz = ARRAY_SIZE(iodelay_cfg_array_am574x_idk);
Steve Kipiszc95cddd2016-11-25 11:14:24 +0530767 } else if (board_is_am571x_idk()) {
768 pconf = core_padconf_array_essential_am571x_idk;
769 pconf_sz = ARRAY_SIZE(core_padconf_array_essential_am571x_idk);
770 iod = iodelay_cfg_array_am571x_idk;
771 iod_sz = ARRAY_SIZE(iodelay_cfg_array_am571x_idk);
Steve Kipisz0ac8cea2016-04-08 17:01:29 -0500772 } else {
773 /* Common for X15/GPEVM */
774 pconf = core_padconf_array_essential_x15;
775 pconf_sz = ARRAY_SIZE(core_padconf_array_essential_x15);
Nishanth Menon8e3212e2016-11-25 11:14:22 +0530776 /* There never was an SR1.0 X15.. So.. */
777 if (omap_revision() == DRA752_ES1_1) {
778 iod = iodelay_cfg_array_x15_sr1_1;
779 iod_sz = ARRAY_SIZE(iodelay_cfg_array_x15_sr1_1);
780 } else {
781 /* Since full production should switch to SR2.0 */
782 iod = iodelay_cfg_array_x15_sr2_0;
783 iod_sz = ARRAY_SIZE(iodelay_cfg_array_x15_sr2_0);
784 }
Steve Kipisz0ac8cea2016-04-08 17:01:29 -0500785 }
786
Nishanth Menon8e3212e2016-11-25 11:14:22 +0530787 /* Setup I/O isolation */
788 ret = __recalibrate_iodelay_start();
789 if (ret)
790 goto err;
791
792 /* Do the muxing here */
793 do_set_mux32((*ctrl)->control_padconf_core_base, pconf, pconf_sz);
794
795 /* Now do the weird minor deltas that should be safe */
796 if (board_is_x15() || board_is_am572x_evm()) {
Lokesh Vutla816178b2017-07-16 19:59:19 +0530797 if (board_is_x15_revb1() || board_is_am572x_evm_reva3() ||
798 board_is_x15_revc()) {
Nishanth Menon8e3212e2016-11-25 11:14:22 +0530799 pconf = core_padconf_array_delta_x15_sr2_0;
800 pconf_sz = ARRAY_SIZE(core_padconf_array_delta_x15_sr2_0);
801 } else {
802 pconf = core_padconf_array_delta_x15_sr1_1;
803 pconf_sz = ARRAY_SIZE(core_padconf_array_delta_x15_sr1_1);
804 }
805 do_set_mux32((*ctrl)->control_padconf_core_base, pconf, pconf_sz);
806 }
807
Roger Quadros26130592017-03-13 15:04:28 +0200808 if (board_is_am571x_idk()) {
809 if (am571x_idk_needs_lcd()) {
810 pconf = core_padconf_array_vout_am571x_idk;
811 pconf_sz = ARRAY_SIZE(core_padconf_array_vout_am571x_idk);
Lokesh Vutla3cb4c622017-06-05 14:48:16 +0530812 delta_iod = iodelay_cfg_array_am571x_idk_4port;
813 delta_iod_sz = ARRAY_SIZE(iodelay_cfg_array_am571x_idk_4port);
814
Roger Quadros26130592017-03-13 15:04:28 +0200815 } else {
816 pconf = core_padconf_array_icss1eth_am571x_idk;
817 pconf_sz = ARRAY_SIZE(core_padconf_array_icss1eth_am571x_idk);
818 }
819 do_set_mux32((*ctrl)->control_padconf_core_base, pconf, pconf_sz);
820 }
821
Nishanth Menon8e3212e2016-11-25 11:14:22 +0530822 /* Setup IOdelay configuration */
823 ret = do_set_iodelay((*ctrl)->iodelay_config_base, iod, iod_sz);
Lokesh Vutla3cb4c622017-06-05 14:48:16 +0530824 if (delta_iod_sz)
825 ret = do_set_iodelay((*ctrl)->iodelay_config_base, delta_iod,
826 delta_iod_sz);
827
Nishanth Menon8e3212e2016-11-25 11:14:22 +0530828err:
829 /* Closeup.. remove isolation */
830 __recalibrate_iodelay_end(ret);
Lokesh Vutlac3d39f92015-06-04 16:42:41 +0530831}
832#endif
833
Masahiro Yamada0a780172017-05-09 20:31:39 +0900834#if defined(CONFIG_MMC)
Felipe Balbi4750eb62014-11-10 14:02:44 -0600835int board_mmc_init(bd_t *bis)
836{
837 omap_mmc_init(0, 0, 0, -1, -1);
838 omap_mmc_init(1, 0, 0, -1, -1);
839 return 0;
840}
Kishon Vijay Abraham I110ed012018-01-30 16:01:52 +0100841
842static const struct mmc_platform_fixups am57x_es1_1_mmc1_fixups = {
843 .hw_rev = "rev11",
844 .unsupported_caps = MMC_CAP(MMC_HS_200) |
845 MMC_CAP(UHS_SDR104),
846 .max_freq = 96000000,
847};
848
849static const struct mmc_platform_fixups am57x_es1_1_mmc23_fixups = {
850 .hw_rev = "rev11",
851 .unsupported_caps = MMC_CAP(MMC_HS_200) |
852 MMC_CAP(UHS_SDR104) |
853 MMC_CAP(UHS_SDR50),
854 .max_freq = 48000000,
855};
856
857const struct mmc_platform_fixups *platform_fixups_mmc(uint32_t addr)
858{
859 switch (omap_revision()) {
860 case DRA752_ES1_0:
861 case DRA752_ES1_1:
862 if (addr == OMAP_HSMMC1_BASE)
863 return &am57x_es1_1_mmc1_fixups;
864 else
865 return &am57x_es1_1_mmc23_fixups;
866 default:
867 return NULL;
868 }
869}
Felipe Balbi4750eb62014-11-10 14:02:44 -0600870#endif
871
872#if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_OS_BOOT)
873int spl_start_uboot(void)
874{
875 /* break into full u-boot on 'c' */
876 if (serial_tstc() && serial_getc() == 'c')
877 return 1;
878
879#ifdef CONFIG_SPL_ENV_SUPPORT
880 env_init();
Simon Glass17539572017-08-03 12:22:07 -0600881 env_load();
Simon Glass22c34c22017-08-03 12:22:13 -0600882 if (env_get_yesno("boot_os") != 1)
Felipe Balbi4750eb62014-11-10 14:02:44 -0600883 return 1;
884#endif
885
886 return 0;
887}
888#endif
889
890#ifdef CONFIG_DRIVER_TI_CPSW
891
892/* Delay value to add to calibrated value */
893#define RGMII0_TXCTL_DLY_VAL ((0x3 << 5) + 0x8)
894#define RGMII0_TXD0_DLY_VAL ((0x3 << 5) + 0x8)
895#define RGMII0_TXD1_DLY_VAL ((0x3 << 5) + 0x2)
896#define RGMII0_TXD2_DLY_VAL ((0x4 << 5) + 0x0)
897#define RGMII0_TXD3_DLY_VAL ((0x4 << 5) + 0x0)
898#define VIN2A_D13_DLY_VAL ((0x3 << 5) + 0x8)
899#define VIN2A_D17_DLY_VAL ((0x3 << 5) + 0x8)
900#define VIN2A_D16_DLY_VAL ((0x3 << 5) + 0x2)
901#define VIN2A_D15_DLY_VAL ((0x4 << 5) + 0x0)
902#define VIN2A_D14_DLY_VAL ((0x4 << 5) + 0x0)
903
904static void cpsw_control(int enabled)
905{
906 /* VTP can be added here */
907}
908
909static struct cpsw_slave_data cpsw_slaves[] = {
910 {
911 .slave_reg_ofs = 0x208,
912 .sliver_reg_ofs = 0xd80,
913 .phy_addr = 1,
914 },
915 {
916 .slave_reg_ofs = 0x308,
917 .sliver_reg_ofs = 0xdc0,
918 .phy_addr = 2,
919 },
920};
921
922static struct cpsw_platform_data cpsw_data = {
923 .mdio_base = CPSW_MDIO_BASE,
924 .cpsw_base = CPSW_BASE,
925 .mdio_div = 0xff,
926 .channels = 8,
927 .cpdma_reg_ofs = 0x800,
928 .slaves = 1,
929 .slave_data = cpsw_slaves,
930 .ale_reg_ofs = 0xd00,
931 .ale_entries = 1024,
932 .host_port_reg_ofs = 0x108,
933 .hw_stats_reg_ofs = 0x900,
934 .bd_ram_ofs = 0x2000,
935 .mac_control = (1 << 5),
936 .control = cpsw_control,
937 .host_port_num = 0,
938 .version = CPSW_CTRL_VERSION_2,
939};
940
Roger Quadros64217a22016-03-18 13:18:12 +0200941static u64 mac_to_u64(u8 mac[6])
942{
943 int i;
944 u64 addr = 0;
945
946 for (i = 0; i < 6; i++) {
947 addr <<= 8;
948 addr |= mac[i];
949 }
950
951 return addr;
952}
953
954static void u64_to_mac(u64 addr, u8 mac[6])
955{
956 mac[5] = addr;
957 mac[4] = addr >> 8;
958 mac[3] = addr >> 16;
959 mac[2] = addr >> 24;
960 mac[1] = addr >> 32;
961 mac[0] = addr >> 40;
962}
963
Felipe Balbi4750eb62014-11-10 14:02:44 -0600964int board_eth_init(bd_t *bis)
965{
966 int ret;
967 uint8_t mac_addr[6];
968 uint32_t mac_hi, mac_lo;
969 uint32_t ctrl_val;
Roger Quadros64217a22016-03-18 13:18:12 +0200970 int i;
971 u64 mac1, mac2;
972 u8 mac_addr1[6], mac_addr2[6];
973 int num_macs;
Felipe Balbi4750eb62014-11-10 14:02:44 -0600974
975 /* try reading mac address from efuse */
976 mac_lo = readl((*ctrl)->control_core_mac_id_0_lo);
977 mac_hi = readl((*ctrl)->control_core_mac_id_0_hi);
978 mac_addr[0] = (mac_hi & 0xFF0000) >> 16;
979 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
980 mac_addr[2] = mac_hi & 0xFF;
981 mac_addr[3] = (mac_lo & 0xFF0000) >> 16;
982 mac_addr[4] = (mac_lo & 0xFF00) >> 8;
983 mac_addr[5] = mac_lo & 0xFF;
984
Simon Glass64b723f2017-08-03 12:22:12 -0600985 if (!env_get("ethaddr")) {
Felipe Balbi4750eb62014-11-10 14:02:44 -0600986 printf("<ethaddr> not set. Validating first E-fuse MAC\n");
987
Joe Hershberger8ecdbed2015-04-08 01:41:04 -0500988 if (is_valid_ethaddr(mac_addr))
Simon Glass8551d552017-08-03 12:22:11 -0600989 eth_env_set_enetaddr("ethaddr", mac_addr);
Felipe Balbi4750eb62014-11-10 14:02:44 -0600990 }
991
992 mac_lo = readl((*ctrl)->control_core_mac_id_1_lo);
993 mac_hi = readl((*ctrl)->control_core_mac_id_1_hi);
994 mac_addr[0] = (mac_hi & 0xFF0000) >> 16;
995 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
996 mac_addr[2] = mac_hi & 0xFF;
997 mac_addr[3] = (mac_lo & 0xFF0000) >> 16;
998 mac_addr[4] = (mac_lo & 0xFF00) >> 8;
999 mac_addr[5] = mac_lo & 0xFF;
1000
Simon Glass64b723f2017-08-03 12:22:12 -06001001 if (!env_get("eth1addr")) {
Joe Hershberger8ecdbed2015-04-08 01:41:04 -05001002 if (is_valid_ethaddr(mac_addr))
Simon Glass8551d552017-08-03 12:22:11 -06001003 eth_env_set_enetaddr("eth1addr", mac_addr);
Felipe Balbi4750eb62014-11-10 14:02:44 -06001004 }
1005
1006 ctrl_val = readl((*ctrl)->control_core_control_io1) & (~0x33);
1007 ctrl_val |= 0x22;
1008 writel(ctrl_val, (*ctrl)->control_core_control_io1);
1009
Steve Kipiszc95cddd2016-11-25 11:14:24 +05301010 /* The phy address for the AM57xx IDK are different than x15 */
Lokesh Vutla6e9635c2017-12-29 11:47:53 +05301011 if (board_is_am572x_idk() || board_is_am571x_idk() ||
1012 board_is_am574x_idk()) {
Steve Kipisz0ac8cea2016-04-08 17:01:29 -05001013 cpsw_data.slave_data[0].phy_addr = 0;
1014 cpsw_data.slave_data[1].phy_addr = 1;
1015 }
1016
Felipe Balbi4750eb62014-11-10 14:02:44 -06001017 ret = cpsw_register(&cpsw_data);
1018 if (ret < 0)
1019 printf("Error %d registering CPSW switch\n", ret);
1020
Roger Quadros64217a22016-03-18 13:18:12 +02001021 /*
1022 * Export any Ethernet MAC addresses from EEPROM.
1023 * On AM57xx the 2 MAC addresses define the address range
1024 */
1025 board_ti_get_eth_mac_addr(0, mac_addr1);
1026 board_ti_get_eth_mac_addr(1, mac_addr2);
1027
1028 if (is_valid_ethaddr(mac_addr1) && is_valid_ethaddr(mac_addr2)) {
1029 mac1 = mac_to_u64(mac_addr1);
1030 mac2 = mac_to_u64(mac_addr2);
1031
1032 /* must contain an address range */
1033 num_macs = mac2 - mac1 + 1;
1034 /* <= 50 to protect against user programming error */
1035 if (num_macs > 0 && num_macs <= 50) {
1036 for (i = 0; i < num_macs; i++) {
1037 u64_to_mac(mac1 + i, mac_addr);
1038 if (is_valid_ethaddr(mac_addr)) {
Simon Glass8551d552017-08-03 12:22:11 -06001039 eth_env_set_enetaddr_by_index("eth",
1040 i + 2,
1041 mac_addr);
Roger Quadros64217a22016-03-18 13:18:12 +02001042 }
1043 }
1044 }
1045 }
1046
Felipe Balbi4750eb62014-11-10 14:02:44 -06001047 return ret;
1048}
1049#endif
Lokesh Vutla9f150672015-06-16 20:36:05 +05301050
1051#ifdef CONFIG_BOARD_EARLY_INIT_F
1052/* VTT regulator enable */
1053static inline void vtt_regulator_enable(void)
1054{
1055 if (omap_hw_init_context() == OMAP_INIT_CONTEXT_UBOOT_AFTER_SPL)
1056 return;
1057
1058 gpio_request(GPIO_DDR_VTT_EN, "ddr_vtt_en");
1059 gpio_direction_output(GPIO_DDR_VTT_EN, 1);
1060}
1061
1062int board_early_init_f(void)
1063{
1064 vtt_regulator_enable();
1065 return 0;
1066}
1067#endif
Daniel Allred7ceffb22016-05-19 19:10:54 -05001068
1069#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
1070int ft_board_setup(void *blob, bd_t *bd)
1071{
1072 ft_cpu_setup(blob, bd);
1073
1074 return 0;
1075}
1076#endif
Lokesh Vutla00bf8b22016-06-10 09:35:43 +05301077
1078#ifdef CONFIG_SPL_LOAD_FIT
1079int board_fit_config_name_match(const char *name)
1080{
Lokesh Vutla638e1c02016-11-25 11:14:20 +05301081 if (board_is_x15()) {
1082 if (board_is_x15_revb1()) {
1083 if (!strcmp(name, "am57xx-beagle-x15-revb1"))
1084 return 0;
Lokesh Vutlaf35589c2017-08-23 11:39:06 +05301085 } else if (board_is_x15_revc()) {
1086 if (!strcmp(name, "am57xx-beagle-x15-revc"))
1087 return 0;
Lokesh Vutla638e1c02016-11-25 11:14:20 +05301088 } else if (!strcmp(name, "am57xx-beagle-x15")) {
1089 return 0;
1090 }
1091 } else if (board_is_am572x_evm() &&
1092 !strcmp(name, "am57xx-beagle-x15")) {
Lokesh Vutla00bf8b22016-06-10 09:35:43 +05301093 return 0;
Lokesh Vutla638e1c02016-11-25 11:14:20 +05301094 } else if (board_is_am572x_idk() && !strcmp(name, "am572x-idk")) {
Schuyler Patton99519852016-06-10 09:35:45 +05301095 return 0;
Lokesh Vutla58a3c1b2017-12-29 11:47:57 +05301096 } else if (board_is_am574x_idk() && !strcmp(name, "am574x-idk")) {
1097 return 0;
Schuyler Pattonc665e272016-11-25 11:14:25 +05301098 } else if (board_is_am571x_idk() && !strcmp(name, "am571x-idk")) {
1099 return 0;
Lokesh Vutla638e1c02016-11-25 11:14:20 +05301100 }
1101
1102 return -1;
Lokesh Vutla00bf8b22016-06-10 09:35:43 +05301103}
1104#endif
Andreas Dannenberg5cf344b2016-06-27 09:19:22 -05001105
Andrew F. Davisd3555832019-02-11 08:00:08 -06001106#if CONFIG_IS_ENABLED(FASTBOOT) && !CONFIG_IS_ENABLED(ENV_IS_NOWHERE)
1107int fastboot_set_reboot_flag(void)
1108{
1109 printf("Setting reboot to fastboot flag ...\n");
1110 env_set("dofastboot", "1");
1111 env_save();
1112 return 0;
1113}
1114#endif
1115
Andreas Dannenberg5cf344b2016-06-27 09:19:22 -05001116#ifdef CONFIG_TI_SECURE_DEVICE
1117void board_fit_image_post_process(void **p_image, size_t *p_size)
1118{
1119 secure_boot_verify_image(p_image, p_size);
1120}
Andrew F. Davis7d250622016-11-29 16:33:26 -06001121
1122void board_tee_image_process(ulong tee_image, size_t tee_size)
1123{
1124 secure_tee_install((u32)tee_image);
1125}
1126
1127U_BOOT_FIT_LOADABLE_HANDLER(IH_TYPE_TEE, board_tee_image_process);
Andreas Dannenberg5cf344b2016-06-27 09:19:22 -05001128#endif