blob: 8d1f38971c9201148385426f4855b4f7ef3b34ff [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Felipe Balbi1e4ad742014-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 Balbi1e4ad742014-11-10 14:02:44 -06008 */
9
10#include <common.h>
Simon Glass4bfd1f52019-08-01 09:46:43 -060011#include <env.h>
Felipe Balbi1e4ad742014-11-10 14:02:44 -060012#include <palmas.h>
13#include <sata.h>
Simon Glassb03e0512019-11-14 12:57:24 -070014#include <serial.h>
Felipe Balbi1e4ad742014-11-10 14:02:44 -060015#include <usb.h>
16#include <asm/omap_common.h>
Andreas Dannenberg17c29872016-06-27 09:19:22 -050017#include <asm/omap_sec_common.h>
Felipe Balbi1e4ad742014-11-10 14:02:44 -060018#include <asm/emif.h>
Lokesh Vutla334bbb32015-06-16 20:36:05 +053019#include <asm/gpio.h>
20#include <asm/arch/gpio.h>
Felipe Balbi1e4ad742014-11-10 14:02:44 -060021#include <asm/arch/clock.h>
Lokesh Vutlaf91e0c42015-06-04 16:42:41 +053022#include <asm/arch/dra7xx_iodelay.h>
Felipe Balbi1e4ad742014-11-10 14:02:44 -060023#include <asm/arch/sys_proto.h>
24#include <asm/arch/mmc_host_def.h>
25#include <asm/arch/sata.h>
26#include <asm/arch/gpio.h>
Kishon Vijay Abraham I7c379aa2015-08-19 14:13:19 +053027#include <asm/arch/omap.h>
Kishon Vijay Abraham I7c379aa2015-08-19 14:13:19 +053028#include <usb.h>
29#include <linux/usb/gadget.h>
30#include <dwc3-uboot.h>
31#include <dwc3-omap-uboot.h>
32#include <ti-usb-phy-uboot.h>
Kishon Vijay Abraham Ic413baa2018-01-30 16:01:52 +010033#include <mmc.h>
Tero Kristoe8e683d2019-09-27 19:14:27 +030034#include <dm/uclass.h>
Felipe Balbi1e4ad742014-11-10 14:02:44 -060035
Kipisz, Steven212f96f2016-02-24 12:30:58 -060036#include "../common/board_detect.h"
Felipe Balbi1e4ad742014-11-10 14:02:44 -060037#include "mux_data.h"
38
Kipisz, Steven212f96f2016-02-24 12:30:58 -060039#define board_is_x15() board_ti_is("BBRDX15_")
Lokesh Vutlaf7f9f6b2016-11-25 11:14:20 +053040#define board_is_x15_revb1() (board_ti_is("BBRDX15_") && \
Lokesh Vutla70879222017-07-16 19:59:18 +053041 !strncmp("B.10", board_ti_get_rev(), 3))
Lokesh Vutlaf70a4272017-07-16 19:59:19 +053042#define board_is_x15_revc() (board_ti_is("BBRDX15_") && \
43 !strncmp("C.00", board_ti_get_rev(), 3))
Kipisz, Steven212f96f2016-02-24 12:30:58 -060044#define board_is_am572x_evm() board_ti_is("AM572PM_")
Nishanth Menonbf43ce62016-11-25 11:14:19 +053045#define board_is_am572x_evm_reva3() \
46 (board_ti_is("AM572PM_") && \
Lokesh Vutla70879222017-07-16 19:59:18 +053047 !strncmp("A.30", board_ti_get_rev(), 3))
Lokesh Vutla9646b952017-12-29 11:47:52 +053048#define board_is_am574x_idk() board_ti_is("AM574IDK")
Steve Kipiszc020d352016-04-08 17:01:29 -050049#define board_is_am572x_idk() board_ti_is("AM572IDK")
Steve Kipisz4d8397c2016-11-25 11:14:24 +053050#define board_is_am571x_idk() board_ti_is("AM571IDK")
Kipisz, Steven212f96f2016-02-24 12:30:58 -060051
Felipe Balbi1e4ad742014-11-10 14:02:44 -060052#ifdef CONFIG_DRIVER_TI_CPSW
53#include <cpsw.h>
54#endif
55
56DECLARE_GLOBAL_DATA_PTR;
57
Roger Quadros37611052017-03-13 15:04:28 +020058#define GPIO_ETH_LCD GPIO_TO_PIN(2, 22)
Lokesh Vutla334bbb32015-06-16 20:36:05 +053059/* GPIO 7_11 */
60#define GPIO_DDR_VTT_EN 203
61
Nishanth Menonfcb18522017-03-13 15:04:30 +020062/* Touch screen controller to identify the LCD */
63#define OSD_TS_FT_BUS_ADDRESS 0
64#define OSD_TS_FT_CHIP_ADDRESS 0x38
65#define OSD_TS_FT_REG_ID 0xA3
66/*
67 * Touchscreen IDs for various OSD panels
68 * Ref: http://www.osddisplays.com/TI/OSD101T2587-53TS_A.1.pdf
69 */
70/* Used on newer osd101t2587 Panels */
71#define OSD_TS_FT_ID_5x46 0x54
72/* Used on older osd101t2045 Panels */
73#define OSD_TS_FT_ID_5606 0x08
74
Kipisz, Steven212f96f2016-02-24 12:30:58 -060075#define SYSINFO_BOARD_NAME_MAX_LEN 45
76
Keerthy385d3632016-11-30 15:02:53 +053077#define TPS65903X_PRIMARY_SECONDARY_PAD2 0xFB
78#define TPS65903X_PAD2_POWERHOLD_MASK 0x20
79
Felipe Balbi1e4ad742014-11-10 14:02:44 -060080const struct omap_sysinfo sysinfo = {
Kipisz, Steven212f96f2016-02-24 12:30:58 -060081 "Board: UNKNOWN(BeagleBoard X15?) REV UNKNOWN\n"
Felipe Balbi1e4ad742014-11-10 14:02:44 -060082};
83
84static const struct dmm_lisa_map_regs beagle_x15_lisa_regs = {
85 .dmm_lisa_map_3 = 0x80740300,
86 .is_ma_present = 0x1
87};
88
Steve Kipisz4d8397c2016-11-25 11:14:24 +053089static const struct dmm_lisa_map_regs am571x_idk_lisa_regs = {
90 .dmm_lisa_map_3 = 0x80640100,
91 .is_ma_present = 0x1
92};
93
Lokesh Vutla7b16de82017-12-29 11:47:54 +053094static const struct dmm_lisa_map_regs am574x_idk_lisa_regs = {
95 .dmm_lisa_map_2 = 0xc0600200,
96 .dmm_lisa_map_3 = 0x80600100,
97 .is_ma_present = 0x1
98};
99
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600100void emif_get_dmm_regs(const struct dmm_lisa_map_regs **dmm_lisa_regs)
101{
Steve Kipisz4d8397c2016-11-25 11:14:24 +0530102 if (board_is_am571x_idk())
103 *dmm_lisa_regs = &am571x_idk_lisa_regs;
Lokesh Vutla7b16de82017-12-29 11:47:54 +0530104 else if (board_is_am574x_idk())
105 *dmm_lisa_regs = &am574x_idk_lisa_regs;
Steve Kipisz4d8397c2016-11-25 11:14:24 +0530106 else
107 *dmm_lisa_regs = &beagle_x15_lisa_regs;
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600108}
109
110static const struct emif_regs beagle_x15_emif1_ddr3_532mhz_emif_regs = {
Keerthyeafd4642016-05-24 11:45:07 +0530111 .sdram_config_init = 0x61851b32,
112 .sdram_config = 0x61851b32,
113 .sdram_config2 = 0x08000000,
114 .ref_ctrl = 0x000040F1,
115 .ref_ctrl_final = 0x00001035,
116 .sdram_tim1 = 0xcccf36ab,
117 .sdram_tim2 = 0x308f7fda,
118 .sdram_tim3 = 0x409f88a8,
119 .read_idle_ctrl = 0x00050000,
120 .zq_config = 0x5007190b,
121 .temp_alert_config = 0x00000000,
122 .emif_ddr_phy_ctlr_1_init = 0x0024400b,
123 .emif_ddr_phy_ctlr_1 = 0x0e24400b,
124 .emif_ddr_ext_phy_ctrl_1 = 0x10040100,
125 .emif_ddr_ext_phy_ctrl_2 = 0x00910091,
126 .emif_ddr_ext_phy_ctrl_3 = 0x00950095,
127 .emif_ddr_ext_phy_ctrl_4 = 0x009b009b,
128 .emif_ddr_ext_phy_ctrl_5 = 0x009e009e,
129 .emif_rd_wr_lvl_rmp_win = 0x00000000,
130 .emif_rd_wr_lvl_rmp_ctl = 0x80000000,
131 .emif_rd_wr_lvl_ctl = 0x00000000,
132 .emif_rd_wr_exec_thresh = 0x00000305
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600133};
134
Lokesh Vutla6213db72015-06-03 14:43:21 +0530135/* Ext phy ctrl regs 1-35 */
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600136static const u32 beagle_x15_emif1_ddr3_ext_phy_ctrl_const_regs[] = {
Lokesh Vutla6213db72015-06-03 14:43:21 +0530137 0x10040100,
Lokesh Vutla11e2b042016-03-08 09:11:35 +0530138 0x00910091,
139 0x00950095,
140 0x009B009B,
141 0x009E009E,
142 0x00980098,
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600143 0x00340034,
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600144 0x00350035,
Lokesh Vutla11e2b042016-03-08 09:11:35 +0530145 0x00340034,
146 0x00310031,
147 0x00340034,
148 0x007F007F,
149 0x007F007F,
150 0x007F007F,
151 0x007F007F,
152 0x007F007F,
153 0x00480048,
154 0x004A004A,
155 0x00520052,
156 0x00550055,
157 0x00500050,
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600158 0x00000000,
159 0x00600020,
Lokesh Vutla6213db72015-06-03 14:43:21 +0530160 0x40011080,
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600161 0x08102040,
Lokesh Vutla11e2b042016-03-08 09:11:35 +0530162 0x0,
163 0x0,
164 0x0,
165 0x0,
166 0x0,
Lokesh Vutla496edff2015-06-03 14:43:22 +0530167 0x0,
168 0x0,
169 0x0,
170 0x0,
171 0x0
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600172};
173
174static const struct emif_regs beagle_x15_emif2_ddr3_532mhz_emif_regs = {
Keerthyeafd4642016-05-24 11:45:07 +0530175 .sdram_config_init = 0x61851b32,
176 .sdram_config = 0x61851b32,
177 .sdram_config2 = 0x08000000,
178 .ref_ctrl = 0x000040F1,
179 .ref_ctrl_final = 0x00001035,
180 .sdram_tim1 = 0xcccf36b3,
181 .sdram_tim2 = 0x308f7fda,
182 .sdram_tim3 = 0x407f88a8,
183 .read_idle_ctrl = 0x00050000,
184 .zq_config = 0x5007190b,
185 .temp_alert_config = 0x00000000,
186 .emif_ddr_phy_ctlr_1_init = 0x0024400b,
187 .emif_ddr_phy_ctlr_1 = 0x0e24400b,
188 .emif_ddr_ext_phy_ctrl_1 = 0x10040100,
189 .emif_ddr_ext_phy_ctrl_2 = 0x00910091,
190 .emif_ddr_ext_phy_ctrl_3 = 0x00950095,
191 .emif_ddr_ext_phy_ctrl_4 = 0x009b009b,
192 .emif_ddr_ext_phy_ctrl_5 = 0x009e009e,
193 .emif_rd_wr_lvl_rmp_win = 0x00000000,
194 .emif_rd_wr_lvl_rmp_ctl = 0x80000000,
195 .emif_rd_wr_lvl_ctl = 0x00000000,
196 .emif_rd_wr_exec_thresh = 0x00000305
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600197};
198
199static const u32 beagle_x15_emif2_ddr3_ext_phy_ctrl_const_regs[] = {
Lokesh Vutla6213db72015-06-03 14:43:21 +0530200 0x10040100,
Lokesh Vutla11e2b042016-03-08 09:11:35 +0530201 0x00910091,
202 0x00950095,
203 0x009B009B,
204 0x009E009E,
205 0x00980098,
206 0x00340034,
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600207 0x00350035,
Lokesh Vutla11e2b042016-03-08 09:11:35 +0530208 0x00340034,
209 0x00310031,
210 0x00340034,
211 0x007F007F,
212 0x007F007F,
213 0x007F007F,
214 0x007F007F,
215 0x007F007F,
216 0x00480048,
217 0x004A004A,
218 0x00520052,
219 0x00550055,
220 0x00500050,
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600221 0x00000000,
222 0x00600020,
Lokesh Vutla6213db72015-06-03 14:43:21 +0530223 0x40011080,
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600224 0x08102040,
Lokesh Vutla11e2b042016-03-08 09:11:35 +0530225 0x0,
226 0x0,
227 0x0,
228 0x0,
229 0x0,
Lokesh Vutla496edff2015-06-03 14:43:22 +0530230 0x0,
231 0x0,
232 0x0,
233 0x0,
234 0x0
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600235};
236
Steve Kipisz209742f2017-08-22 13:52:58 +0530237static const struct emif_regs am571x_emif1_ddr3_666mhz_emif_regs = {
238 .sdram_config_init = 0x61863332,
239 .sdram_config = 0x61863332,
240 .sdram_config2 = 0x08000000,
241 .ref_ctrl = 0x0000514d,
242 .ref_ctrl_final = 0x0000144a,
243 .sdram_tim1 = 0xd333887c,
Lokesh Vutla7b16de82017-12-29 11:47:54 +0530244 .sdram_tim2 = 0x30b37fe3,
245 .sdram_tim3 = 0x409f8ad8,
Steve Kipisz209742f2017-08-22 13:52:58 +0530246 .read_idle_ctrl = 0x00050000,
247 .zq_config = 0x5007190b,
248 .temp_alert_config = 0x00000000,
249 .emif_ddr_phy_ctlr_1_init = 0x0024400f,
250 .emif_ddr_phy_ctlr_1 = 0x0e24400f,
251 .emif_ddr_ext_phy_ctrl_1 = 0x10040100,
252 .emif_ddr_ext_phy_ctrl_2 = 0x00910091,
253 .emif_ddr_ext_phy_ctrl_3 = 0x00950095,
254 .emif_ddr_ext_phy_ctrl_4 = 0x009b009b,
255 .emif_ddr_ext_phy_ctrl_5 = 0x009e009e,
256 .emif_rd_wr_lvl_rmp_win = 0x00000000,
257 .emif_rd_wr_lvl_rmp_ctl = 0x80000000,
258 .emif_rd_wr_lvl_ctl = 0x00000000,
259 .emif_rd_wr_exec_thresh = 0x00000305
260};
261
Lokesh Vutla7b16de82017-12-29 11:47:54 +0530262static const struct emif_regs am574x_emif1_ddr3_666mhz_emif_ecc_regs = {
263 .sdram_config_init = 0x61863332,
264 .sdram_config = 0x61863332,
265 .sdram_config2 = 0x08000000,
266 .ref_ctrl = 0x0000514d,
267 .ref_ctrl_final = 0x0000144a,
268 .sdram_tim1 = 0xd333887c,
269 .sdram_tim2 = 0x30b37fe3,
270 .sdram_tim3 = 0x409f8ad8,
271 .read_idle_ctrl = 0x00050000,
272 .zq_config = 0x5007190b,
273 .temp_alert_config = 0x00000000,
274 .emif_ddr_phy_ctlr_1_init = 0x0024400f,
275 .emif_ddr_phy_ctlr_1 = 0x0e24400f,
276 .emif_ddr_ext_phy_ctrl_1 = 0x10040100,
277 .emif_ddr_ext_phy_ctrl_2 = 0x00910091,
278 .emif_ddr_ext_phy_ctrl_3 = 0x00950095,
279 .emif_ddr_ext_phy_ctrl_4 = 0x009b009b,
280 .emif_ddr_ext_phy_ctrl_5 = 0x009e009e,
281 .emif_rd_wr_lvl_rmp_win = 0x00000000,
282 .emif_rd_wr_lvl_rmp_ctl = 0x80000000,
283 .emif_rd_wr_lvl_ctl = 0x00000000,
284 .emif_rd_wr_exec_thresh = 0x00000305,
285 .emif_ecc_ctrl_reg = 0xD0000001,
286 .emif_ecc_address_range_1 = 0x3FFF0000,
287 .emif_ecc_address_range_2 = 0x00000000
288};
289
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600290void emif_get_reg_dump(u32 emif_nr, const struct emif_regs **regs)
291{
292 switch (emif_nr) {
293 case 1:
Steve Kipisz209742f2017-08-22 13:52:58 +0530294 if (board_is_am571x_idk())
295 *regs = &am571x_emif1_ddr3_666mhz_emif_regs;
Lokesh Vutla7b16de82017-12-29 11:47:54 +0530296 else if (board_is_am574x_idk())
297 *regs = &am574x_emif1_ddr3_666mhz_emif_ecc_regs;
Steve Kipisz209742f2017-08-22 13:52:58 +0530298 else
299 *regs = &beagle_x15_emif1_ddr3_532mhz_emif_regs;
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600300 break;
301 case 2:
Lokesh Vutla7b16de82017-12-29 11:47:54 +0530302 if (board_is_am574x_idk())
303 *regs = &am571x_emif1_ddr3_666mhz_emif_regs;
304 else
305 *regs = &beagle_x15_emif2_ddr3_532mhz_emif_regs;
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600306 break;
307 }
308}
309
310void emif_get_ext_phy_ctrl_const_regs(u32 emif_nr, const u32 **regs, u32 *size)
311{
312 switch (emif_nr) {
313 case 1:
314 *regs = beagle_x15_emif1_ddr3_ext_phy_ctrl_const_regs;
315 *size = ARRAY_SIZE(beagle_x15_emif1_ddr3_ext_phy_ctrl_const_regs);
316 break;
317 case 2:
318 *regs = beagle_x15_emif2_ddr3_ext_phy_ctrl_const_regs;
319 *size = ARRAY_SIZE(beagle_x15_emif2_ddr3_ext_phy_ctrl_const_regs);
320 break;
321 }
322}
323
324struct vcores_data beagle_x15_volts = {
Lokesh Vutlabeb71272016-11-23 12:54:39 +0530325 .mpu.value[OPP_NOM] = VDD_MPU_DRA7_NOM,
326 .mpu.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_MPU_NOM,
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600327 .mpu.efuse.reg_bits = DRA752_EFUSE_REGBITS,
328 .mpu.addr = TPS659038_REG_ADDR_SMPS12,
329 .mpu.pmic = &tps659038,
Keerthyeafd4642016-05-24 11:45:07 +0530330 .mpu.abb_tx_done_mask = OMAP_ABB_MPU_TXDONE_MASK,
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600331
Lokesh Vutlabeb71272016-11-23 12:54:39 +0530332 .eve.value[OPP_NOM] = VDD_EVE_DRA7_NOM,
333 .eve.value[OPP_OD] = VDD_EVE_DRA7_OD,
334 .eve.value[OPP_HIGH] = VDD_EVE_DRA7_HIGH,
335 .eve.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_DSPEVE_NOM,
336 .eve.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_DSPEVE_OD,
337 .eve.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_DSPEVE_HIGH,
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600338 .eve.efuse.reg_bits = DRA752_EFUSE_REGBITS,
339 .eve.addr = TPS659038_REG_ADDR_SMPS45,
340 .eve.pmic = &tps659038,
Nishanth Menone52e3342016-04-21 14:34:25 -0500341 .eve.abb_tx_done_mask = OMAP_ABB_EVE_TXDONE_MASK,
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600342
Lokesh Vutlabeb71272016-11-23 12:54:39 +0530343 .gpu.value[OPP_NOM] = VDD_GPU_DRA7_NOM,
344 .gpu.value[OPP_OD] = VDD_GPU_DRA7_OD,
345 .gpu.value[OPP_HIGH] = VDD_GPU_DRA7_HIGH,
346 .gpu.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_GPU_NOM,
347 .gpu.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_GPU_OD,
348 .gpu.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_GPU_HIGH,
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600349 .gpu.efuse.reg_bits = DRA752_EFUSE_REGBITS,
350 .gpu.addr = TPS659038_REG_ADDR_SMPS45,
351 .gpu.pmic = &tps659038,
Nishanth Menone52e3342016-04-21 14:34:25 -0500352 .gpu.abb_tx_done_mask = OMAP_ABB_GPU_TXDONE_MASK,
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600353
Lokesh Vutlabeb71272016-11-23 12:54:39 +0530354 .core.value[OPP_NOM] = VDD_CORE_DRA7_NOM,
355 .core.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_CORE_NOM,
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600356 .core.efuse.reg_bits = DRA752_EFUSE_REGBITS,
357 .core.addr = TPS659038_REG_ADDR_SMPS6,
358 .core.pmic = &tps659038,
359
Lokesh Vutlabeb71272016-11-23 12:54:39 +0530360 .iva.value[OPP_NOM] = VDD_IVA_DRA7_NOM,
361 .iva.value[OPP_OD] = VDD_IVA_DRA7_OD,
362 .iva.value[OPP_HIGH] = VDD_IVA_DRA7_HIGH,
363 .iva.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_IVA_NOM,
364 .iva.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_IVA_OD,
365 .iva.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_IVA_HIGH,
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600366 .iva.efuse.reg_bits = DRA752_EFUSE_REGBITS,
367 .iva.addr = TPS659038_REG_ADDR_SMPS45,
368 .iva.pmic = &tps659038,
Nishanth Menone52e3342016-04-21 14:34:25 -0500369 .iva.abb_tx_done_mask = OMAP_ABB_IVA_TXDONE_MASK,
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600370};
371
Keerthyd60198d2016-05-24 11:45:06 +0530372struct vcores_data am572x_idk_volts = {
Lokesh Vutlabeb71272016-11-23 12:54:39 +0530373 .mpu.value[OPP_NOM] = VDD_MPU_DRA7_NOM,
374 .mpu.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_MPU_NOM,
Keerthyd60198d2016-05-24 11:45:06 +0530375 .mpu.efuse.reg_bits = DRA752_EFUSE_REGBITS,
376 .mpu.addr = TPS659038_REG_ADDR_SMPS12,
377 .mpu.pmic = &tps659038,
378 .mpu.abb_tx_done_mask = OMAP_ABB_MPU_TXDONE_MASK,
379
Lokesh Vutlabeb71272016-11-23 12:54:39 +0530380 .eve.value[OPP_NOM] = VDD_EVE_DRA7_NOM,
381 .eve.value[OPP_OD] = VDD_EVE_DRA7_OD,
382 .eve.value[OPP_HIGH] = VDD_EVE_DRA7_HIGH,
383 .eve.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_DSPEVE_NOM,
384 .eve.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_DSPEVE_OD,
385 .eve.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_DSPEVE_HIGH,
Keerthyd60198d2016-05-24 11:45:06 +0530386 .eve.efuse.reg_bits = DRA752_EFUSE_REGBITS,
387 .eve.addr = TPS659038_REG_ADDR_SMPS45,
388 .eve.pmic = &tps659038,
389 .eve.abb_tx_done_mask = OMAP_ABB_EVE_TXDONE_MASK,
390
Lokesh Vutlabeb71272016-11-23 12:54:39 +0530391 .gpu.value[OPP_NOM] = VDD_GPU_DRA7_NOM,
392 .gpu.value[OPP_OD] = VDD_GPU_DRA7_OD,
393 .gpu.value[OPP_HIGH] = VDD_GPU_DRA7_HIGH,
394 .gpu.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_GPU_NOM,
395 .gpu.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_GPU_OD,
396 .gpu.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_GPU_HIGH,
Keerthyd60198d2016-05-24 11:45:06 +0530397 .gpu.efuse.reg_bits = DRA752_EFUSE_REGBITS,
398 .gpu.addr = TPS659038_REG_ADDR_SMPS6,
399 .gpu.pmic = &tps659038,
400 .gpu.abb_tx_done_mask = OMAP_ABB_GPU_TXDONE_MASK,
401
Lokesh Vutlabeb71272016-11-23 12:54:39 +0530402 .core.value[OPP_NOM] = VDD_CORE_DRA7_NOM,
403 .core.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_CORE_NOM,
Keerthyd60198d2016-05-24 11:45:06 +0530404 .core.efuse.reg_bits = DRA752_EFUSE_REGBITS,
405 .core.addr = TPS659038_REG_ADDR_SMPS7,
406 .core.pmic = &tps659038,
407
Lokesh Vutlabeb71272016-11-23 12:54:39 +0530408 .iva.value[OPP_NOM] = VDD_IVA_DRA7_NOM,
409 .iva.value[OPP_OD] = VDD_IVA_DRA7_OD,
410 .iva.value[OPP_HIGH] = VDD_IVA_DRA7_HIGH,
411 .iva.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_IVA_NOM,
412 .iva.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_IVA_OD,
413 .iva.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_IVA_HIGH,
Keerthyd60198d2016-05-24 11:45:06 +0530414 .iva.efuse.reg_bits = DRA752_EFUSE_REGBITS,
415 .iva.addr = TPS659038_REG_ADDR_SMPS8,
416 .iva.pmic = &tps659038,
417 .iva.abb_tx_done_mask = OMAP_ABB_IVA_TXDONE_MASK,
418};
419
Keerthyb12550e2017-05-25 15:37:34 +0530420struct vcores_data am571x_idk_volts = {
421 .mpu.value[OPP_NOM] = VDD_MPU_DRA7_NOM,
422 .mpu.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_MPU_NOM,
423 .mpu.efuse.reg_bits = DRA752_EFUSE_REGBITS,
424 .mpu.addr = TPS659038_REG_ADDR_SMPS12,
425 .mpu.pmic = &tps659038,
426 .mpu.abb_tx_done_mask = OMAP_ABB_MPU_TXDONE_MASK,
427
428 .eve.value[OPP_NOM] = VDD_EVE_DRA7_NOM,
429 .eve.value[OPP_OD] = VDD_EVE_DRA7_OD,
430 .eve.value[OPP_HIGH] = VDD_EVE_DRA7_HIGH,
431 .eve.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_DSPEVE_NOM,
432 .eve.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_DSPEVE_OD,
433 .eve.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_DSPEVE_HIGH,
434 .eve.efuse.reg_bits = DRA752_EFUSE_REGBITS,
435 .eve.addr = TPS659038_REG_ADDR_SMPS45,
436 .eve.pmic = &tps659038,
437 .eve.abb_tx_done_mask = OMAP_ABB_EVE_TXDONE_MASK,
438
439 .gpu.value[OPP_NOM] = VDD_GPU_DRA7_NOM,
440 .gpu.value[OPP_OD] = VDD_GPU_DRA7_OD,
441 .gpu.value[OPP_HIGH] = VDD_GPU_DRA7_HIGH,
442 .gpu.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_GPU_NOM,
443 .gpu.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_GPU_OD,
444 .gpu.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_GPU_HIGH,
445 .gpu.efuse.reg_bits = DRA752_EFUSE_REGBITS,
446 .gpu.addr = TPS659038_REG_ADDR_SMPS6,
447 .gpu.pmic = &tps659038,
448 .gpu.abb_tx_done_mask = OMAP_ABB_GPU_TXDONE_MASK,
449
450 .core.value[OPP_NOM] = VDD_CORE_DRA7_NOM,
451 .core.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_CORE_NOM,
452 .core.efuse.reg_bits = DRA752_EFUSE_REGBITS,
453 .core.addr = TPS659038_REG_ADDR_SMPS7,
454 .core.pmic = &tps659038,
455
456 .iva.value[OPP_NOM] = VDD_IVA_DRA7_NOM,
457 .iva.value[OPP_OD] = VDD_IVA_DRA7_OD,
458 .iva.value[OPP_HIGH] = VDD_IVA_DRA7_HIGH,
459 .iva.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_IVA_NOM,
460 .iva.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_IVA_OD,
461 .iva.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_IVA_HIGH,
462 .iva.efuse.reg_bits = DRA752_EFUSE_REGBITS,
463 .iva.addr = TPS659038_REG_ADDR_SMPS45,
464 .iva.pmic = &tps659038,
465 .iva.abb_tx_done_mask = OMAP_ABB_IVA_TXDONE_MASK,
466};
467
Lokesh Vutlabeb71272016-11-23 12:54:39 +0530468int get_voltrail_opp(int rail_offset)
469{
470 int opp;
471
472 switch (rail_offset) {
473 case VOLT_MPU:
474 opp = DRA7_MPU_OPP;
475 break;
476 case VOLT_CORE:
477 opp = DRA7_CORE_OPP;
478 break;
479 case VOLT_GPU:
480 opp = DRA7_GPU_OPP;
481 break;
482 case VOLT_EVE:
483 opp = DRA7_DSPEVE_OPP;
484 break;
485 case VOLT_IVA:
486 opp = DRA7_IVA_OPP;
487 break;
488 default:
489 opp = OPP_NOM;
490 }
491
492 return opp;
493}
494
495
Kipisz, Steven212f96f2016-02-24 12:30:58 -0600496#ifdef CONFIG_SPL_BUILD
497/* No env to setup for SPL */
498static inline void setup_board_eeprom_env(void) { }
499
500/* Override function to read eeprom information */
501void do_board_detect(void)
502{
503 int rc;
504
505 rc = ti_i2c_eeprom_am_get(CONFIG_EEPROM_BUS_ADDRESS,
506 CONFIG_EEPROM_CHIP_ADDRESS);
507 if (rc)
508 printf("ti_i2c_eeprom_init failed %d\n", rc);
509}
510
511#else /* CONFIG_SPL_BUILD */
512
513/* Override function to read eeprom information: actual i2c read done by SPL*/
514void do_board_detect(void)
515{
516 char *bname = NULL;
517 int rc;
518
519 rc = ti_i2c_eeprom_am_get(CONFIG_EEPROM_BUS_ADDRESS,
520 CONFIG_EEPROM_CHIP_ADDRESS);
521 if (rc)
522 printf("ti_i2c_eeprom_init failed %d\n", rc);
523
524 if (board_is_x15())
525 bname = "BeagleBoard X15";
526 else if (board_is_am572x_evm())
527 bname = "AM572x EVM";
Lokesh Vutla9646b952017-12-29 11:47:52 +0530528 else if (board_is_am574x_idk())
529 bname = "AM574x IDK";
Steve Kipiszc020d352016-04-08 17:01:29 -0500530 else if (board_is_am572x_idk())
531 bname = "AM572x IDK";
Steve Kipisz4d8397c2016-11-25 11:14:24 +0530532 else if (board_is_am571x_idk())
533 bname = "AM571x IDK";
Kipisz, Steven212f96f2016-02-24 12:30:58 -0600534
535 if (bname)
536 snprintf(sysinfo.board_string, SYSINFO_BOARD_NAME_MAX_LEN,
537 "Board: %s REV %s\n", bname, board_ti_get_rev());
538}
539
540static void setup_board_eeprom_env(void)
541{
542 char *name = "beagle_x15";
543 int rc;
544
545 rc = ti_i2c_eeprom_am_get(CONFIG_EEPROM_BUS_ADDRESS,
546 CONFIG_EEPROM_CHIP_ADDRESS);
547 if (rc)
548 goto invalid_eeprom;
549
Nishanth Menonbf43ce62016-11-25 11:14:19 +0530550 if (board_is_x15()) {
Lokesh Vutlaf7f9f6b2016-11-25 11:14:20 +0530551 if (board_is_x15_revb1())
552 name = "beagle_x15_revb1";
Lokesh Vutlaf70a4272017-07-16 19:59:19 +0530553 else if (board_is_x15_revc())
554 name = "beagle_x15_revc";
Lokesh Vutlaf7f9f6b2016-11-25 11:14:20 +0530555 else
556 name = "beagle_x15";
Nishanth Menonbf43ce62016-11-25 11:14:19 +0530557 } else if (board_is_am572x_evm()) {
558 if (board_is_am572x_evm_reva3())
559 name = "am57xx_evm_reva3";
560 else
561 name = "am57xx_evm";
Lokesh Vutla9646b952017-12-29 11:47:52 +0530562 } else if (board_is_am574x_idk()) {
563 name = "am574x_idk";
Nishanth Menonbf43ce62016-11-25 11:14:19 +0530564 } else if (board_is_am572x_idk()) {
Steve Kipiszc020d352016-04-08 17:01:29 -0500565 name = "am572x_idk";
Steve Kipisz4d8397c2016-11-25 11:14:24 +0530566 } else if (board_is_am571x_idk()) {
567 name = "am571x_idk";
Nishanth Menonbf43ce62016-11-25 11:14:19 +0530568 } else {
Kipisz, Steven212f96f2016-02-24 12:30:58 -0600569 printf("Unidentified board claims %s in eeprom header\n",
570 board_ti_get_name());
Nishanth Menonbf43ce62016-11-25 11:14:19 +0530571 }
Kipisz, Steven212f96f2016-02-24 12:30:58 -0600572
573invalid_eeprom:
574 set_board_info_env(name);
575}
576
577#endif /* CONFIG_SPL_BUILD */
578
Keerthyd60198d2016-05-24 11:45:06 +0530579void vcores_init(void)
580{
Lokesh Vutla10f430f2017-12-29 11:47:53 +0530581 if (board_is_am572x_idk() || board_is_am574x_idk())
Keerthyd60198d2016-05-24 11:45:06 +0530582 *omap_vcores = &am572x_idk_volts;
Keerthyb12550e2017-05-25 15:37:34 +0530583 else if (board_is_am571x_idk())
584 *omap_vcores = &am571x_idk_volts;
Keerthyd60198d2016-05-24 11:45:06 +0530585 else
586 *omap_vcores = &beagle_x15_volts;
587}
588
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600589void hw_data_init(void)
590{
591 *prcm = &dra7xx_prcm;
Steve Kipisz209742f2017-08-22 13:52:58 +0530592 if (is_dra72x())
593 *dplls_data = &dra72x_dplls;
Lokesh Vutla10f430f2017-12-29 11:47:53 +0530594 else if (is_dra76x())
595 *dplls_data = &dra76x_dplls;
Steve Kipisz209742f2017-08-22 13:52:58 +0530596 else
597 *dplls_data = &dra7xx_dplls;
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600598 *ctrl = &dra7xx_ctrl;
599}
600
Roger Quadros37611052017-03-13 15:04:28 +0200601bool am571x_idk_needs_lcd(void)
602{
603 bool needs_lcd;
604
605 gpio_request(GPIO_ETH_LCD, "nLCD_Detect");
606 if (gpio_get_value(GPIO_ETH_LCD))
607 needs_lcd = false;
608 else
609 needs_lcd = true;
610
611 gpio_free(GPIO_ETH_LCD);
612
613 return needs_lcd;
614}
615
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600616int board_init(void)
617{
618 gpmc_init();
619 gd->bd->bi_boot_params = (CONFIG_SYS_SDRAM_BASE + 0x100);
620
621 return 0;
622}
623
Nishanth Menonfcb18522017-03-13 15:04:30 +0200624void am57x_idk_lcd_detect(void)
625{
626 int r = -ENODEV;
627 char *idk_lcd = "no";
Jean-Jacques Hiblot7eb1f602018-12-07 14:50:50 +0100628 struct udevice *dev;
Nishanth Menonfcb18522017-03-13 15:04:30 +0200629
630 /* Only valid for IDKs */
631 if (board_is_x15() || board_is_am572x_evm())
632 return;
633
634 /* Only AM571x IDK has gpio control detect.. so check that */
635 if (board_is_am571x_idk() && !am571x_idk_needs_lcd())
636 goto out;
637
Jean-Jacques Hiblot15142442018-12-07 14:50:49 +0100638 r = i2c_get_chip_for_busnum(OSD_TS_FT_BUS_ADDRESS,
639 OSD_TS_FT_CHIP_ADDRESS, 1, &dev);
Nishanth Menonfcb18522017-03-13 15:04:30 +0200640 if (r) {
Jean-Jacques Hiblot15142442018-12-07 14:50:49 +0100641 printf("%s: Failed to get I2C device %d/%d (ret %d)\n",
642 __func__, OSD_TS_FT_BUS_ADDRESS, OSD_TS_FT_CHIP_ADDRESS,
643 r);
Nishanth Menonfcb18522017-03-13 15:04:30 +0200644 /* AM572x IDK has no explicit settings for optional LCD kit */
Jean-Jacques Hiblot15142442018-12-07 14:50:49 +0100645 if (board_is_am571x_idk())
Nishanth Menonfcb18522017-03-13 15:04:30 +0200646 printf("%s: Touch screen detect failed: %d!\n",
647 __func__, r);
Nishanth Menonfcb18522017-03-13 15:04:30 +0200648 goto out;
649 }
650
651 /* Read FT ID */
Jean-Jacques Hiblot15142442018-12-07 14:50:49 +0100652 r = dm_i2c_reg_read(dev, OSD_TS_FT_REG_ID);
653 if (r < 0) {
Nishanth Menonfcb18522017-03-13 15:04:30 +0200654 printf("%s: Touch screen ID read %d:0x%02x[0x%02x] failed:%d\n",
655 __func__, OSD_TS_FT_BUS_ADDRESS, OSD_TS_FT_CHIP_ADDRESS,
656 OSD_TS_FT_REG_ID, r);
657 goto out;
658 }
659
Jean-Jacques Hiblot7eb1f602018-12-07 14:50:50 +0100660 switch (r) {
Nishanth Menonfcb18522017-03-13 15:04:30 +0200661 case OSD_TS_FT_ID_5606:
662 idk_lcd = "osd101t2045";
663 break;
664 case OSD_TS_FT_ID_5x46:
665 idk_lcd = "osd101t2587";
666 break;
667 default:
668 printf("%s: Unidentifed Touch screen ID 0x%02x\n",
Jean-Jacques Hiblot7eb1f602018-12-07 14:50:50 +0100669 __func__, r);
Nishanth Menonfcb18522017-03-13 15:04:30 +0200670 /* we will let default be "no lcd" */
671 }
672out:
Simon Glass382bee52017-08-03 12:22:09 -0600673 env_set("idk_lcd", idk_lcd);
Nishanth Menonfcb18522017-03-13 15:04:30 +0200674 return;
675}
676
Vignesh Rc3cd5fc2018-11-29 10:57:42 +0100677#if CONFIG_IS_ENABLED(DM_USB) && CONFIG_IS_ENABLED(OF_CONTROL)
678static int device_okay(const char *path)
679{
680 int node;
681
682 node = fdt_path_offset(gd->fdt_blob, path);
683 if (node < 0)
684 return 0;
685
686 return fdtdec_get_is_enabled(gd->fdt_blob, node);
687}
688#endif
689
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600690int board_late_init(void)
691{
Kipisz, Steven212f96f2016-02-24 12:30:58 -0600692 setup_board_eeprom_env();
Keerthy385d3632016-11-30 15:02:53 +0530693 u8 val;
Tero Kristoe8e683d2019-09-27 19:14:27 +0300694 struct udevice *dev;
Kipisz, Steven212f96f2016-02-24 12:30:58 -0600695
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600696 /*
697 * DEV_CTRL.DEV_ON = 1 please - else palmas switches off in 8 seconds
698 * This is the POWERHOLD-in-Low behavior.
699 */
700 palmas_i2c_write_u8(TPS65903X_CHIP_P1, 0xA0, 0x1);
Lokesh Vutla82cca5a2016-11-29 11:58:02 +0530701
702 /*
703 * Default FIT boot on HS devices. Non FIT images are not allowed
704 * on HS devices.
705 */
706 if (get_device_type() == HS_DEVICE)
Simon Glass382bee52017-08-03 12:22:09 -0600707 env_set("boot_fit", "1");
Lokesh Vutla82cca5a2016-11-29 11:58:02 +0530708
Keerthy385d3632016-11-30 15:02:53 +0530709 /*
710 * Set the GPIO7 Pad to POWERHOLD. This has higher priority
711 * over DEV_CTRL.DEV_ON bit. This can be reset in case of
712 * PMIC Power off. So to be on the safer side set it back
713 * to POWERHOLD mode irrespective of the current state.
714 */
715 palmas_i2c_read_u8(TPS65903X_CHIP_P1, TPS65903X_PRIMARY_SECONDARY_PAD2,
716 &val);
717 val = val | TPS65903X_PAD2_POWERHOLD_MASK;
718 palmas_i2c_write_u8(TPS65903X_CHIP_P1, TPS65903X_PRIMARY_SECONDARY_PAD2,
719 val);
720
Semen Protsenko7a2af752017-02-13 19:09:37 +0200721 omap_die_id_serial();
Semen Protsenko8bd29622017-05-22 19:16:41 +0300722 omap_set_fastboot_vars();
Semen Protsenko7a2af752017-02-13 19:09:37 +0200723
Nishanth Menonfcb18522017-03-13 15:04:30 +0200724 am57x_idk_lcd_detect();
Roger Quadros37611052017-03-13 15:04:28 +0200725
Tero Kristoe8e683d2019-09-27 19:14:27 +0300726 /* Just probe the potentially supported cdce913 device */
727 uclass_get_device(UCLASS_CLK, 0, &dev);
728
Roger Quadros37611052017-03-13 15:04:28 +0200729#if !defined(CONFIG_SPL_BUILD)
730 board_ti_set_ethaddr(2);
731#endif
732
Vignesh Rc3cd5fc2018-11-29 10:57:42 +0100733#if CONFIG_IS_ENABLED(DM_USB) && CONFIG_IS_ENABLED(OF_CONTROL)
734 if (device_okay("/ocp/omap_dwc3_1@48880000"))
735 enable_usb_clocks(0);
736 if (device_okay("/ocp/omap_dwc3_2@488c0000"))
737 enable_usb_clocks(1);
738#endif
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600739 return 0;
740}
741
Paul Kocialkowski3ef56e62016-02-27 19:18:56 +0100742void set_muxconf_regs(void)
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600743{
744 do_set_mux32((*ctrl)->control_padconf_core_base,
Lokesh Vutlaf91e0c42015-06-04 16:42:41 +0530745 early_padconf, ARRAY_SIZE(early_padconf));
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600746}
747
Lokesh Vutlaf91e0c42015-06-04 16:42:41 +0530748#ifdef CONFIG_IODELAY_RECALIBRATION
749void recalibrate_iodelay(void)
750{
Steve Kipiszc020d352016-04-08 17:01:29 -0500751 const struct pad_conf_entry *pconf;
Lokesh Vutla2d7e9e92017-06-05 14:48:16 +0530752 const struct iodelay_cfg_entry *iod, *delta_iod;
753 int pconf_sz, iod_sz, delta_iod_sz = 0;
Nishanth Menon89a38952016-11-25 11:14:22 +0530754 int ret;
Steve Kipiszc020d352016-04-08 17:01:29 -0500755
Lokesh Vutla443b0df2017-12-29 11:47:55 +0530756 if (board_is_am572x_idk()) {
Steve Kipiszc020d352016-04-08 17:01:29 -0500757 pconf = core_padconf_array_essential_am572x_idk;
758 pconf_sz = ARRAY_SIZE(core_padconf_array_essential_am572x_idk);
759 iod = iodelay_cfg_array_am572x_idk;
760 iod_sz = ARRAY_SIZE(iodelay_cfg_array_am572x_idk);
Lokesh Vutla443b0df2017-12-29 11:47:55 +0530761 } else if (board_is_am574x_idk()) {
762 pconf = core_padconf_array_essential_am574x_idk;
763 pconf_sz = ARRAY_SIZE(core_padconf_array_essential_am574x_idk);
764 iod = iodelay_cfg_array_am574x_idk;
765 iod_sz = ARRAY_SIZE(iodelay_cfg_array_am574x_idk);
Steve Kipisz4d8397c2016-11-25 11:14:24 +0530766 } else if (board_is_am571x_idk()) {
767 pconf = core_padconf_array_essential_am571x_idk;
768 pconf_sz = ARRAY_SIZE(core_padconf_array_essential_am571x_idk);
769 iod = iodelay_cfg_array_am571x_idk;
770 iod_sz = ARRAY_SIZE(iodelay_cfg_array_am571x_idk);
Steve Kipiszc020d352016-04-08 17:01:29 -0500771 } else {
772 /* Common for X15/GPEVM */
773 pconf = core_padconf_array_essential_x15;
774 pconf_sz = ARRAY_SIZE(core_padconf_array_essential_x15);
Nishanth Menon89a38952016-11-25 11:14:22 +0530775 /* There never was an SR1.0 X15.. So.. */
776 if (omap_revision() == DRA752_ES1_1) {
777 iod = iodelay_cfg_array_x15_sr1_1;
778 iod_sz = ARRAY_SIZE(iodelay_cfg_array_x15_sr1_1);
779 } else {
780 /* Since full production should switch to SR2.0 */
781 iod = iodelay_cfg_array_x15_sr2_0;
782 iod_sz = ARRAY_SIZE(iodelay_cfg_array_x15_sr2_0);
783 }
Steve Kipiszc020d352016-04-08 17:01:29 -0500784 }
785
Nishanth Menon89a38952016-11-25 11:14:22 +0530786 /* Setup I/O isolation */
787 ret = __recalibrate_iodelay_start();
788 if (ret)
789 goto err;
790
791 /* Do the muxing here */
792 do_set_mux32((*ctrl)->control_padconf_core_base, pconf, pconf_sz);
793
794 /* Now do the weird minor deltas that should be safe */
795 if (board_is_x15() || board_is_am572x_evm()) {
Lokesh Vutlaf70a4272017-07-16 19:59:19 +0530796 if (board_is_x15_revb1() || board_is_am572x_evm_reva3() ||
797 board_is_x15_revc()) {
Nishanth Menon89a38952016-11-25 11:14:22 +0530798 pconf = core_padconf_array_delta_x15_sr2_0;
799 pconf_sz = ARRAY_SIZE(core_padconf_array_delta_x15_sr2_0);
800 } else {
801 pconf = core_padconf_array_delta_x15_sr1_1;
802 pconf_sz = ARRAY_SIZE(core_padconf_array_delta_x15_sr1_1);
803 }
804 do_set_mux32((*ctrl)->control_padconf_core_base, pconf, pconf_sz);
805 }
806
Roger Quadros37611052017-03-13 15:04:28 +0200807 if (board_is_am571x_idk()) {
808 if (am571x_idk_needs_lcd()) {
809 pconf = core_padconf_array_vout_am571x_idk;
810 pconf_sz = ARRAY_SIZE(core_padconf_array_vout_am571x_idk);
Lokesh Vutla2d7e9e92017-06-05 14:48:16 +0530811 delta_iod = iodelay_cfg_array_am571x_idk_4port;
812 delta_iod_sz = ARRAY_SIZE(iodelay_cfg_array_am571x_idk_4port);
813
Roger Quadros37611052017-03-13 15:04:28 +0200814 } else {
815 pconf = core_padconf_array_icss1eth_am571x_idk;
816 pconf_sz = ARRAY_SIZE(core_padconf_array_icss1eth_am571x_idk);
817 }
818 do_set_mux32((*ctrl)->control_padconf_core_base, pconf, pconf_sz);
819 }
820
Nishanth Menon89a38952016-11-25 11:14:22 +0530821 /* Setup IOdelay configuration */
822 ret = do_set_iodelay((*ctrl)->iodelay_config_base, iod, iod_sz);
Lokesh Vutla2d7e9e92017-06-05 14:48:16 +0530823 if (delta_iod_sz)
824 ret = do_set_iodelay((*ctrl)->iodelay_config_base, delta_iod,
825 delta_iod_sz);
826
Nishanth Menon89a38952016-11-25 11:14:22 +0530827err:
828 /* Closeup.. remove isolation */
829 __recalibrate_iodelay_end(ret);
Lokesh Vutlaf91e0c42015-06-04 16:42:41 +0530830}
831#endif
832
Masahiro Yamada4aa2ba32017-05-09 20:31:39 +0900833#if defined(CONFIG_MMC)
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600834int board_mmc_init(bd_t *bis)
835{
836 omap_mmc_init(0, 0, 0, -1, -1);
837 omap_mmc_init(1, 0, 0, -1, -1);
838 return 0;
839}
Kishon Vijay Abraham Ic413baa2018-01-30 16:01:52 +0100840
841static const struct mmc_platform_fixups am57x_es1_1_mmc1_fixups = {
842 .hw_rev = "rev11",
843 .unsupported_caps = MMC_CAP(MMC_HS_200) |
844 MMC_CAP(UHS_SDR104),
845 .max_freq = 96000000,
846};
847
848static const struct mmc_platform_fixups am57x_es1_1_mmc23_fixups = {
849 .hw_rev = "rev11",
850 .unsupported_caps = MMC_CAP(MMC_HS_200) |
851 MMC_CAP(UHS_SDR104) |
852 MMC_CAP(UHS_SDR50),
853 .max_freq = 48000000,
854};
855
856const struct mmc_platform_fixups *platform_fixups_mmc(uint32_t addr)
857{
858 switch (omap_revision()) {
859 case DRA752_ES1_0:
860 case DRA752_ES1_1:
861 if (addr == OMAP_HSMMC1_BASE)
862 return &am57x_es1_1_mmc1_fixups;
863 else
864 return &am57x_es1_1_mmc23_fixups;
865 default:
866 return NULL;
867 }
868}
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600869#endif
870
871#if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_OS_BOOT)
872int spl_start_uboot(void)
873{
874 /* break into full u-boot on 'c' */
875 if (serial_tstc() && serial_getc() == 'c')
876 return 1;
877
878#ifdef CONFIG_SPL_ENV_SUPPORT
879 env_init();
Simon Glass310fb142017-08-03 12:22:07 -0600880 env_load();
Simon Glassbfebc8c2017-08-03 12:22:13 -0600881 if (env_get_yesno("boot_os") != 1)
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600882 return 1;
883#endif
884
885 return 0;
886}
887#endif
888
889#ifdef CONFIG_DRIVER_TI_CPSW
890
891/* Delay value to add to calibrated value */
892#define RGMII0_TXCTL_DLY_VAL ((0x3 << 5) + 0x8)
893#define RGMII0_TXD0_DLY_VAL ((0x3 << 5) + 0x8)
894#define RGMII0_TXD1_DLY_VAL ((0x3 << 5) + 0x2)
895#define RGMII0_TXD2_DLY_VAL ((0x4 << 5) + 0x0)
896#define RGMII0_TXD3_DLY_VAL ((0x4 << 5) + 0x0)
897#define VIN2A_D13_DLY_VAL ((0x3 << 5) + 0x8)
898#define VIN2A_D17_DLY_VAL ((0x3 << 5) + 0x8)
899#define VIN2A_D16_DLY_VAL ((0x3 << 5) + 0x2)
900#define VIN2A_D15_DLY_VAL ((0x4 << 5) + 0x0)
901#define VIN2A_D14_DLY_VAL ((0x4 << 5) + 0x0)
902
903static void cpsw_control(int enabled)
904{
905 /* VTP can be added here */
906}
907
908static struct cpsw_slave_data cpsw_slaves[] = {
909 {
910 .slave_reg_ofs = 0x208,
911 .sliver_reg_ofs = 0xd80,
912 .phy_addr = 1,
913 },
914 {
915 .slave_reg_ofs = 0x308,
916 .sliver_reg_ofs = 0xdc0,
917 .phy_addr = 2,
918 },
919};
920
921static struct cpsw_platform_data cpsw_data = {
922 .mdio_base = CPSW_MDIO_BASE,
923 .cpsw_base = CPSW_BASE,
924 .mdio_div = 0xff,
925 .channels = 8,
926 .cpdma_reg_ofs = 0x800,
927 .slaves = 1,
928 .slave_data = cpsw_slaves,
929 .ale_reg_ofs = 0xd00,
930 .ale_entries = 1024,
931 .host_port_reg_ofs = 0x108,
932 .hw_stats_reg_ofs = 0x900,
933 .bd_ram_ofs = 0x2000,
934 .mac_control = (1 << 5),
935 .control = cpsw_control,
936 .host_port_num = 0,
937 .version = CPSW_CTRL_VERSION_2,
938};
939
Roger Quadros92667e82016-03-18 13:18:12 +0200940static u64 mac_to_u64(u8 mac[6])
941{
942 int i;
943 u64 addr = 0;
944
945 for (i = 0; i < 6; i++) {
946 addr <<= 8;
947 addr |= mac[i];
948 }
949
950 return addr;
951}
952
953static void u64_to_mac(u64 addr, u8 mac[6])
954{
955 mac[5] = addr;
956 mac[4] = addr >> 8;
957 mac[3] = addr >> 16;
958 mac[2] = addr >> 24;
959 mac[1] = addr >> 32;
960 mac[0] = addr >> 40;
961}
962
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600963int board_eth_init(bd_t *bis)
964{
965 int ret;
966 uint8_t mac_addr[6];
967 uint32_t mac_hi, mac_lo;
968 uint32_t ctrl_val;
Roger Quadros92667e82016-03-18 13:18:12 +0200969 int i;
970 u64 mac1, mac2;
971 u8 mac_addr1[6], mac_addr2[6];
972 int num_macs;
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600973
974 /* try reading mac address from efuse */
975 mac_lo = readl((*ctrl)->control_core_mac_id_0_lo);
976 mac_hi = readl((*ctrl)->control_core_mac_id_0_hi);
977 mac_addr[0] = (mac_hi & 0xFF0000) >> 16;
978 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
979 mac_addr[2] = mac_hi & 0xFF;
980 mac_addr[3] = (mac_lo & 0xFF0000) >> 16;
981 mac_addr[4] = (mac_lo & 0xFF00) >> 8;
982 mac_addr[5] = mac_lo & 0xFF;
983
Simon Glass00caae62017-08-03 12:22:12 -0600984 if (!env_get("ethaddr")) {
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600985 printf("<ethaddr> not set. Validating first E-fuse MAC\n");
986
Joe Hershberger0adb5b72015-04-08 01:41:04 -0500987 if (is_valid_ethaddr(mac_addr))
Simon Glassfd1e9592017-08-03 12:22:11 -0600988 eth_env_set_enetaddr("ethaddr", mac_addr);
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600989 }
990
991 mac_lo = readl((*ctrl)->control_core_mac_id_1_lo);
992 mac_hi = readl((*ctrl)->control_core_mac_id_1_hi);
993 mac_addr[0] = (mac_hi & 0xFF0000) >> 16;
994 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
995 mac_addr[2] = mac_hi & 0xFF;
996 mac_addr[3] = (mac_lo & 0xFF0000) >> 16;
997 mac_addr[4] = (mac_lo & 0xFF00) >> 8;
998 mac_addr[5] = mac_lo & 0xFF;
999
Simon Glass00caae62017-08-03 12:22:12 -06001000 if (!env_get("eth1addr")) {
Joe Hershberger0adb5b72015-04-08 01:41:04 -05001001 if (is_valid_ethaddr(mac_addr))
Simon Glassfd1e9592017-08-03 12:22:11 -06001002 eth_env_set_enetaddr("eth1addr", mac_addr);
Felipe Balbi1e4ad742014-11-10 14:02:44 -06001003 }
1004
1005 ctrl_val = readl((*ctrl)->control_core_control_io1) & (~0x33);
1006 ctrl_val |= 0x22;
1007 writel(ctrl_val, (*ctrl)->control_core_control_io1);
1008
Steve Kipisz4d8397c2016-11-25 11:14:24 +05301009 /* The phy address for the AM57xx IDK are different than x15 */
Lokesh Vutla10f430f2017-12-29 11:47:53 +05301010 if (board_is_am572x_idk() || board_is_am571x_idk() ||
1011 board_is_am574x_idk()) {
Steve Kipiszc020d352016-04-08 17:01:29 -05001012 cpsw_data.slave_data[0].phy_addr = 0;
1013 cpsw_data.slave_data[1].phy_addr = 1;
1014 }
1015
Felipe Balbi1e4ad742014-11-10 14:02:44 -06001016 ret = cpsw_register(&cpsw_data);
1017 if (ret < 0)
1018 printf("Error %d registering CPSW switch\n", ret);
1019
Roger Quadros92667e82016-03-18 13:18:12 +02001020 /*
1021 * Export any Ethernet MAC addresses from EEPROM.
1022 * On AM57xx the 2 MAC addresses define the address range
1023 */
1024 board_ti_get_eth_mac_addr(0, mac_addr1);
1025 board_ti_get_eth_mac_addr(1, mac_addr2);
1026
1027 if (is_valid_ethaddr(mac_addr1) && is_valid_ethaddr(mac_addr2)) {
1028 mac1 = mac_to_u64(mac_addr1);
1029 mac2 = mac_to_u64(mac_addr2);
1030
1031 /* must contain an address range */
1032 num_macs = mac2 - mac1 + 1;
1033 /* <= 50 to protect against user programming error */
1034 if (num_macs > 0 && num_macs <= 50) {
1035 for (i = 0; i < num_macs; i++) {
1036 u64_to_mac(mac1 + i, mac_addr);
1037 if (is_valid_ethaddr(mac_addr)) {
Simon Glassfd1e9592017-08-03 12:22:11 -06001038 eth_env_set_enetaddr_by_index("eth",
1039 i + 2,
1040 mac_addr);
Roger Quadros92667e82016-03-18 13:18:12 +02001041 }
1042 }
1043 }
1044 }
1045
Felipe Balbi1e4ad742014-11-10 14:02:44 -06001046 return ret;
1047}
1048#endif
Lokesh Vutla334bbb32015-06-16 20:36:05 +05301049
1050#ifdef CONFIG_BOARD_EARLY_INIT_F
1051/* VTT regulator enable */
1052static inline void vtt_regulator_enable(void)
1053{
1054 if (omap_hw_init_context() == OMAP_INIT_CONTEXT_UBOOT_AFTER_SPL)
1055 return;
1056
1057 gpio_request(GPIO_DDR_VTT_EN, "ddr_vtt_en");
1058 gpio_direction_output(GPIO_DDR_VTT_EN, 1);
1059}
1060
1061int board_early_init_f(void)
1062{
1063 vtt_regulator_enable();
1064 return 0;
1065}
1066#endif
Daniel Allred62a09f02016-05-19 19:10:54 -05001067
1068#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
1069int ft_board_setup(void *blob, bd_t *bd)
1070{
1071 ft_cpu_setup(blob, bd);
1072
1073 return 0;
1074}
1075#endif
Lokesh Vutla7a0ea582016-06-10 09:35:43 +05301076
1077#ifdef CONFIG_SPL_LOAD_FIT
1078int board_fit_config_name_match(const char *name)
1079{
Lokesh Vutlaf7f9f6b2016-11-25 11:14:20 +05301080 if (board_is_x15()) {
1081 if (board_is_x15_revb1()) {
1082 if (!strcmp(name, "am57xx-beagle-x15-revb1"))
1083 return 0;
Lokesh Vutla8b2551a2017-08-23 11:39:06 +05301084 } else if (board_is_x15_revc()) {
1085 if (!strcmp(name, "am57xx-beagle-x15-revc"))
1086 return 0;
Lokesh Vutlaf7f9f6b2016-11-25 11:14:20 +05301087 } else if (!strcmp(name, "am57xx-beagle-x15")) {
1088 return 0;
1089 }
1090 } else if (board_is_am572x_evm() &&
1091 !strcmp(name, "am57xx-beagle-x15")) {
Lokesh Vutla7a0ea582016-06-10 09:35:43 +05301092 return 0;
Lokesh Vutlaf7f9f6b2016-11-25 11:14:20 +05301093 } else if (board_is_am572x_idk() && !strcmp(name, "am572x-idk")) {
Lokesh Vutla7a0ea582016-06-10 09:35:43 +05301094 return 0;
Lokesh Vutlab4185e42017-12-29 11:47:57 +05301095 } else if (board_is_am574x_idk() && !strcmp(name, "am574x-idk")) {
1096 return 0;
Schuyler Patton45e7f7e2016-11-25 11:14:25 +05301097 } else if (board_is_am571x_idk() && !strcmp(name, "am571x-idk")) {
1098 return 0;
Lokesh Vutlaf7f9f6b2016-11-25 11:14:20 +05301099 }
1100
1101 return -1;
Lokesh Vutla7a0ea582016-06-10 09:35:43 +05301102}
1103#endif
Andreas Dannenberg17c29872016-06-27 09:19:22 -05001104
Andrew F. Davis50580a02019-02-11 08:00:08 -06001105#if CONFIG_IS_ENABLED(FASTBOOT) && !CONFIG_IS_ENABLED(ENV_IS_NOWHERE)
1106int fastboot_set_reboot_flag(void)
1107{
1108 printf("Setting reboot to fastboot flag ...\n");
1109 env_set("dofastboot", "1");
1110 env_save();
1111 return 0;
1112}
1113#endif
1114
Andreas Dannenberg17c29872016-06-27 09:19:22 -05001115#ifdef CONFIG_TI_SECURE_DEVICE
1116void board_fit_image_post_process(void **p_image, size_t *p_size)
1117{
1118 secure_boot_verify_image(p_image, p_size);
1119}
Andrew F. Davis1b597ad2016-11-29 16:33:26 -06001120
1121void board_tee_image_process(ulong tee_image, size_t tee_size)
1122{
1123 secure_tee_install((u32)tee_image);
1124}
1125
1126U_BOOT_FIT_LOADABLE_HANDLER(IH_TYPE_TEE, board_tee_image_process);
Andreas Dannenberg17c29872016-06-27 09:19:22 -05001127#endif