blob: 52f5e954e698061d7286d3eb0836f34127073c07 [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>
Caleb Robey0dfcc932020-01-02 08:17:25 -060017#include <errno.h>
Felipe Balbi4750eb62014-11-10 14:02:44 -060018#include <asm/omap_common.h>
Andreas Dannenberg5cf344b2016-06-27 09:19:22 -050019#include <asm/omap_sec_common.h>
Felipe Balbi4750eb62014-11-10 14:02:44 -060020#include <asm/emif.h>
Lokesh Vutla9f150672015-06-16 20:36:05 +053021#include <asm/gpio.h>
22#include <asm/arch/gpio.h>
Felipe Balbi4750eb62014-11-10 14:02:44 -060023#include <asm/arch/clock.h>
Lokesh Vutlac3d39f92015-06-04 16:42:41 +053024#include <asm/arch/dra7xx_iodelay.h>
Felipe Balbi4750eb62014-11-10 14:02:44 -060025#include <asm/arch/sys_proto.h>
26#include <asm/arch/mmc_host_def.h>
27#include <asm/arch/sata.h>
28#include <asm/arch/gpio.h>
Kishon Vijay Abraham I5f19b2d2015-08-19 14:13:19 +053029#include <asm/arch/omap.h>
Kishon Vijay Abraham I5f19b2d2015-08-19 14:13:19 +053030#include <usb.h>
31#include <linux/usb/gadget.h>
32#include <dwc3-uboot.h>
33#include <dwc3-omap-uboot.h>
34#include <ti-usb-phy-uboot.h>
Kishon Vijay Abraham I110ed012018-01-30 16:01:52 +010035#include <mmc.h>
Tero Kristodfbc6b82019-09-27 19:14:27 +030036#include <dm/uclass.h>
Felipe Balbi4750eb62014-11-10 14:02:44 -060037
Kipisz, Steven161f1382016-02-24 12:30:58 -060038#include "../common/board_detect.h"
Felipe Balbi4750eb62014-11-10 14:02:44 -060039#include "mux_data.h"
40
Caleb Robey0dfcc932020-01-02 08:17:25 -060041#ifdef CONFIG_SUPPORT_EMMC_BOOT
42static int board_bootmode_has_emmc(void);
43#endif
44
Kipisz, Steven161f1382016-02-24 12:30:58 -060045#define board_is_x15() board_ti_is("BBRDX15_")
Lokesh Vutla638e1c02016-11-25 11:14:20 +053046#define board_is_x15_revb1() (board_ti_is("BBRDX15_") && \
Lokesh Vutlaab4f71e2017-07-16 19:59:18 +053047 !strncmp("B.10", board_ti_get_rev(), 3))
Lokesh Vutla816178b2017-07-16 19:59:19 +053048#define board_is_x15_revc() (board_ti_is("BBRDX15_") && \
49 !strncmp("C.00", board_ti_get_rev(), 3))
Kipisz, Steven161f1382016-02-24 12:30:58 -060050#define board_is_am572x_evm() board_ti_is("AM572PM_")
Nishanth Menona2aea1c2016-11-25 11:14:19 +053051#define board_is_am572x_evm_reva3() \
52 (board_ti_is("AM572PM_") && \
Lokesh Vutlaab4f71e2017-07-16 19:59:18 +053053 !strncmp("A.30", board_ti_get_rev(), 3))
Lokesh Vutla374aea02017-12-29 11:47:52 +053054#define board_is_am574x_idk() board_ti_is("AM574IDK")
Steve Kipisz0ac8cea2016-04-08 17:01:29 -050055#define board_is_am572x_idk() board_ti_is("AM572IDK")
Steve Kipiszc95cddd2016-11-25 11:14:24 +053056#define board_is_am571x_idk() board_ti_is("AM571IDK")
Kipisz, Steven161f1382016-02-24 12:30:58 -060057
Felipe Balbi4750eb62014-11-10 14:02:44 -060058#ifdef CONFIG_DRIVER_TI_CPSW
59#include <cpsw.h>
60#endif
61
62DECLARE_GLOBAL_DATA_PTR;
63
Roger Quadros26130592017-03-13 15:04:28 +020064#define GPIO_ETH_LCD GPIO_TO_PIN(2, 22)
Lokesh Vutla9f150672015-06-16 20:36:05 +053065/* GPIO 7_11 */
66#define GPIO_DDR_VTT_EN 203
67
Nishanth Menond0f399c2017-03-13 15:04:30 +020068/* Touch screen controller to identify the LCD */
69#define OSD_TS_FT_BUS_ADDRESS 0
70#define OSD_TS_FT_CHIP_ADDRESS 0x38
71#define OSD_TS_FT_REG_ID 0xA3
72/*
73 * Touchscreen IDs for various OSD panels
74 * Ref: http://www.osddisplays.com/TI/OSD101T2587-53TS_A.1.pdf
75 */
76/* Used on newer osd101t2587 Panels */
77#define OSD_TS_FT_ID_5x46 0x54
78/* Used on older osd101t2045 Panels */
79#define OSD_TS_FT_ID_5606 0x08
80
Kipisz, Steven161f1382016-02-24 12:30:58 -060081#define SYSINFO_BOARD_NAME_MAX_LEN 45
82
Keerthyee85ebe2016-11-30 15:02:53 +053083#define TPS65903X_PRIMARY_SECONDARY_PAD2 0xFB
84#define TPS65903X_PAD2_POWERHOLD_MASK 0x20
85
Felipe Balbi4750eb62014-11-10 14:02:44 -060086const struct omap_sysinfo sysinfo = {
Kipisz, Steven161f1382016-02-24 12:30:58 -060087 "Board: UNKNOWN(BeagleBoard X15?) REV UNKNOWN\n"
Felipe Balbi4750eb62014-11-10 14:02:44 -060088};
89
90static const struct dmm_lisa_map_regs beagle_x15_lisa_regs = {
91 .dmm_lisa_map_3 = 0x80740300,
92 .is_ma_present = 0x1
93};
94
Steve Kipiszc95cddd2016-11-25 11:14:24 +053095static const struct dmm_lisa_map_regs am571x_idk_lisa_regs = {
96 .dmm_lisa_map_3 = 0x80640100,
97 .is_ma_present = 0x1
98};
99
Lokesh Vutlacbd70db2017-12-29 11:47:54 +0530100static const struct dmm_lisa_map_regs am574x_idk_lisa_regs = {
101 .dmm_lisa_map_2 = 0xc0600200,
102 .dmm_lisa_map_3 = 0x80600100,
103 .is_ma_present = 0x1
104};
105
Felipe Balbi4750eb62014-11-10 14:02:44 -0600106void emif_get_dmm_regs(const struct dmm_lisa_map_regs **dmm_lisa_regs)
107{
Steve Kipiszc95cddd2016-11-25 11:14:24 +0530108 if (board_is_am571x_idk())
109 *dmm_lisa_regs = &am571x_idk_lisa_regs;
Lokesh Vutlacbd70db2017-12-29 11:47:54 +0530110 else if (board_is_am574x_idk())
111 *dmm_lisa_regs = &am574x_idk_lisa_regs;
Steve Kipiszc95cddd2016-11-25 11:14:24 +0530112 else
113 *dmm_lisa_regs = &beagle_x15_lisa_regs;
Felipe Balbi4750eb62014-11-10 14:02:44 -0600114}
115
116static const struct emif_regs beagle_x15_emif1_ddr3_532mhz_emif_regs = {
Keerthy66dd8062016-05-24 11:45:07 +0530117 .sdram_config_init = 0x61851b32,
118 .sdram_config = 0x61851b32,
119 .sdram_config2 = 0x08000000,
120 .ref_ctrl = 0x000040F1,
121 .ref_ctrl_final = 0x00001035,
122 .sdram_tim1 = 0xcccf36ab,
123 .sdram_tim2 = 0x308f7fda,
124 .sdram_tim3 = 0x409f88a8,
125 .read_idle_ctrl = 0x00050000,
126 .zq_config = 0x5007190b,
127 .temp_alert_config = 0x00000000,
128 .emif_ddr_phy_ctlr_1_init = 0x0024400b,
129 .emif_ddr_phy_ctlr_1 = 0x0e24400b,
130 .emif_ddr_ext_phy_ctrl_1 = 0x10040100,
131 .emif_ddr_ext_phy_ctrl_2 = 0x00910091,
132 .emif_ddr_ext_phy_ctrl_3 = 0x00950095,
133 .emif_ddr_ext_phy_ctrl_4 = 0x009b009b,
134 .emif_ddr_ext_phy_ctrl_5 = 0x009e009e,
135 .emif_rd_wr_lvl_rmp_win = 0x00000000,
136 .emif_rd_wr_lvl_rmp_ctl = 0x80000000,
137 .emif_rd_wr_lvl_ctl = 0x00000000,
138 .emif_rd_wr_exec_thresh = 0x00000305
Felipe Balbi4750eb62014-11-10 14:02:44 -0600139};
140
Lokesh Vutla979d2c32015-06-03 14:43:21 +0530141/* Ext phy ctrl regs 1-35 */
Felipe Balbi4750eb62014-11-10 14:02:44 -0600142static const u32 beagle_x15_emif1_ddr3_ext_phy_ctrl_const_regs[] = {
Lokesh Vutla979d2c32015-06-03 14:43:21 +0530143 0x10040100,
Lokesh Vutla306b5972016-03-08 09:11:35 +0530144 0x00910091,
145 0x00950095,
146 0x009B009B,
147 0x009E009E,
148 0x00980098,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600149 0x00340034,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600150 0x00350035,
Lokesh Vutla306b5972016-03-08 09:11:35 +0530151 0x00340034,
152 0x00310031,
153 0x00340034,
154 0x007F007F,
155 0x007F007F,
156 0x007F007F,
157 0x007F007F,
158 0x007F007F,
159 0x00480048,
160 0x004A004A,
161 0x00520052,
162 0x00550055,
163 0x00500050,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600164 0x00000000,
165 0x00600020,
Lokesh Vutla979d2c32015-06-03 14:43:21 +0530166 0x40011080,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600167 0x08102040,
Lokesh Vutla306b5972016-03-08 09:11:35 +0530168 0x0,
169 0x0,
170 0x0,
171 0x0,
Lokesh Vutla51a0f1f2015-06-03 14:43:22 +0530172 0x0,
173 0x0,
174 0x0,
175 0x0,
Lokesh Vutla306b5972016-03-08 09:11:35 +0530176 0x0,
Lokesh Vutla51a0f1f2015-06-03 14:43:22 +0530177 0x0
Felipe Balbi4750eb62014-11-10 14:02:44 -0600178};
179
180static const struct emif_regs beagle_x15_emif2_ddr3_532mhz_emif_regs = {
Keerthy66dd8062016-05-24 11:45:07 +0530181 .sdram_config_init = 0x61851b32,
182 .sdram_config = 0x61851b32,
183 .sdram_config2 = 0x08000000,
184 .ref_ctrl = 0x000040F1,
185 .ref_ctrl_final = 0x00001035,
186 .sdram_tim1 = 0xcccf36b3,
187 .sdram_tim2 = 0x308f7fda,
188 .sdram_tim3 = 0x407f88a8,
189 .read_idle_ctrl = 0x00050000,
190 .zq_config = 0x5007190b,
191 .temp_alert_config = 0x00000000,
192 .emif_ddr_phy_ctlr_1_init = 0x0024400b,
193 .emif_ddr_phy_ctlr_1 = 0x0e24400b,
194 .emif_ddr_ext_phy_ctrl_1 = 0x10040100,
195 .emif_ddr_ext_phy_ctrl_2 = 0x00910091,
196 .emif_ddr_ext_phy_ctrl_3 = 0x00950095,
197 .emif_ddr_ext_phy_ctrl_4 = 0x009b009b,
198 .emif_ddr_ext_phy_ctrl_5 = 0x009e009e,
199 .emif_rd_wr_lvl_rmp_win = 0x00000000,
200 .emif_rd_wr_lvl_rmp_ctl = 0x80000000,
201 .emif_rd_wr_lvl_ctl = 0x00000000,
202 .emif_rd_wr_exec_thresh = 0x00000305
Felipe Balbi4750eb62014-11-10 14:02:44 -0600203};
204
205static const u32 beagle_x15_emif2_ddr3_ext_phy_ctrl_const_regs[] = {
Lokesh Vutla979d2c32015-06-03 14:43:21 +0530206 0x10040100,
Lokesh Vutla306b5972016-03-08 09:11:35 +0530207 0x00910091,
208 0x00950095,
209 0x009B009B,
210 0x009E009E,
211 0x00980098,
212 0x00340034,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600213 0x00350035,
Lokesh Vutla306b5972016-03-08 09:11:35 +0530214 0x00340034,
215 0x00310031,
216 0x00340034,
217 0x007F007F,
218 0x007F007F,
219 0x007F007F,
220 0x007F007F,
221 0x007F007F,
222 0x00480048,
223 0x004A004A,
224 0x00520052,
225 0x00550055,
226 0x00500050,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600227 0x00000000,
228 0x00600020,
Lokesh Vutla979d2c32015-06-03 14:43:21 +0530229 0x40011080,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600230 0x08102040,
Lokesh Vutla306b5972016-03-08 09:11:35 +0530231 0x0,
232 0x0,
233 0x0,
234 0x0,
235 0x0,
Lokesh Vutla51a0f1f2015-06-03 14:43:22 +0530236 0x0,
237 0x0,
238 0x0,
239 0x0,
240 0x0
Felipe Balbi4750eb62014-11-10 14:02:44 -0600241};
242
Steve Kipisz81c46742017-08-22 13:52:58 +0530243static const struct emif_regs am571x_emif1_ddr3_666mhz_emif_regs = {
244 .sdram_config_init = 0x61863332,
245 .sdram_config = 0x61863332,
246 .sdram_config2 = 0x08000000,
247 .ref_ctrl = 0x0000514d,
248 .ref_ctrl_final = 0x0000144a,
249 .sdram_tim1 = 0xd333887c,
Lokesh Vutlacbd70db2017-12-29 11:47:54 +0530250 .sdram_tim2 = 0x30b37fe3,
251 .sdram_tim3 = 0x409f8ad8,
Steve Kipisz81c46742017-08-22 13:52:58 +0530252 .read_idle_ctrl = 0x00050000,
253 .zq_config = 0x5007190b,
254 .temp_alert_config = 0x00000000,
255 .emif_ddr_phy_ctlr_1_init = 0x0024400f,
256 .emif_ddr_phy_ctlr_1 = 0x0e24400f,
257 .emif_ddr_ext_phy_ctrl_1 = 0x10040100,
258 .emif_ddr_ext_phy_ctrl_2 = 0x00910091,
259 .emif_ddr_ext_phy_ctrl_3 = 0x00950095,
260 .emif_ddr_ext_phy_ctrl_4 = 0x009b009b,
261 .emif_ddr_ext_phy_ctrl_5 = 0x009e009e,
262 .emif_rd_wr_lvl_rmp_win = 0x00000000,
263 .emif_rd_wr_lvl_rmp_ctl = 0x80000000,
264 .emif_rd_wr_lvl_ctl = 0x00000000,
265 .emif_rd_wr_exec_thresh = 0x00000305
266};
267
Lokesh Vutlacbd70db2017-12-29 11:47:54 +0530268static const struct emif_regs am574x_emif1_ddr3_666mhz_emif_ecc_regs = {
269 .sdram_config_init = 0x61863332,
270 .sdram_config = 0x61863332,
271 .sdram_config2 = 0x08000000,
272 .ref_ctrl = 0x0000514d,
273 .ref_ctrl_final = 0x0000144a,
274 .sdram_tim1 = 0xd333887c,
275 .sdram_tim2 = 0x30b37fe3,
276 .sdram_tim3 = 0x409f8ad8,
277 .read_idle_ctrl = 0x00050000,
278 .zq_config = 0x5007190b,
279 .temp_alert_config = 0x00000000,
280 .emif_ddr_phy_ctlr_1_init = 0x0024400f,
281 .emif_ddr_phy_ctlr_1 = 0x0e24400f,
282 .emif_ddr_ext_phy_ctrl_1 = 0x10040100,
283 .emif_ddr_ext_phy_ctrl_2 = 0x00910091,
284 .emif_ddr_ext_phy_ctrl_3 = 0x00950095,
285 .emif_ddr_ext_phy_ctrl_4 = 0x009b009b,
286 .emif_ddr_ext_phy_ctrl_5 = 0x009e009e,
287 .emif_rd_wr_lvl_rmp_win = 0x00000000,
288 .emif_rd_wr_lvl_rmp_ctl = 0x80000000,
289 .emif_rd_wr_lvl_ctl = 0x00000000,
290 .emif_rd_wr_exec_thresh = 0x00000305,
291 .emif_ecc_ctrl_reg = 0xD0000001,
292 .emif_ecc_address_range_1 = 0x3FFF0000,
293 .emif_ecc_address_range_2 = 0x00000000
294};
295
Felipe Balbi4750eb62014-11-10 14:02:44 -0600296void emif_get_reg_dump(u32 emif_nr, const struct emif_regs **regs)
297{
298 switch (emif_nr) {
299 case 1:
Steve Kipisz81c46742017-08-22 13:52:58 +0530300 if (board_is_am571x_idk())
301 *regs = &am571x_emif1_ddr3_666mhz_emif_regs;
Lokesh Vutlacbd70db2017-12-29 11:47:54 +0530302 else if (board_is_am574x_idk())
303 *regs = &am574x_emif1_ddr3_666mhz_emif_ecc_regs;
Steve Kipisz81c46742017-08-22 13:52:58 +0530304 else
305 *regs = &beagle_x15_emif1_ddr3_532mhz_emif_regs;
Felipe Balbi4750eb62014-11-10 14:02:44 -0600306 break;
307 case 2:
Lokesh Vutlacbd70db2017-12-29 11:47:54 +0530308 if (board_is_am574x_idk())
309 *regs = &am571x_emif1_ddr3_666mhz_emif_regs;
310 else
311 *regs = &beagle_x15_emif2_ddr3_532mhz_emif_regs;
Felipe Balbi4750eb62014-11-10 14:02:44 -0600312 break;
313 }
314}
315
316void emif_get_ext_phy_ctrl_const_regs(u32 emif_nr, const u32 **regs, u32 *size)
317{
318 switch (emif_nr) {
319 case 1:
320 *regs = beagle_x15_emif1_ddr3_ext_phy_ctrl_const_regs;
321 *size = ARRAY_SIZE(beagle_x15_emif1_ddr3_ext_phy_ctrl_const_regs);
322 break;
323 case 2:
324 *regs = beagle_x15_emif2_ddr3_ext_phy_ctrl_const_regs;
325 *size = ARRAY_SIZE(beagle_x15_emif2_ddr3_ext_phy_ctrl_const_regs);
326 break;
327 }
328}
329
330struct vcores_data beagle_x15_volts = {
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530331 .mpu.value[OPP_NOM] = VDD_MPU_DRA7_NOM,
332 .mpu.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_MPU_NOM,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600333 .mpu.efuse.reg_bits = DRA752_EFUSE_REGBITS,
334 .mpu.addr = TPS659038_REG_ADDR_SMPS12,
335 .mpu.pmic = &tps659038,
Keerthy66dd8062016-05-24 11:45:07 +0530336 .mpu.abb_tx_done_mask = OMAP_ABB_MPU_TXDONE_MASK,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600337
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530338 .eve.value[OPP_NOM] = VDD_EVE_DRA7_NOM,
339 .eve.value[OPP_OD] = VDD_EVE_DRA7_OD,
340 .eve.value[OPP_HIGH] = VDD_EVE_DRA7_HIGH,
341 .eve.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_DSPEVE_NOM,
342 .eve.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_DSPEVE_OD,
343 .eve.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_DSPEVE_HIGH,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600344 .eve.efuse.reg_bits = DRA752_EFUSE_REGBITS,
345 .eve.addr = TPS659038_REG_ADDR_SMPS45,
346 .eve.pmic = &tps659038,
Nishanth Menon59b92af2016-04-21 14:34:25 -0500347 .eve.abb_tx_done_mask = OMAP_ABB_EVE_TXDONE_MASK,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600348
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530349 .gpu.value[OPP_NOM] = VDD_GPU_DRA7_NOM,
350 .gpu.value[OPP_OD] = VDD_GPU_DRA7_OD,
351 .gpu.value[OPP_HIGH] = VDD_GPU_DRA7_HIGH,
352 .gpu.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_GPU_NOM,
353 .gpu.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_GPU_OD,
354 .gpu.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_GPU_HIGH,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600355 .gpu.efuse.reg_bits = DRA752_EFUSE_REGBITS,
356 .gpu.addr = TPS659038_REG_ADDR_SMPS45,
357 .gpu.pmic = &tps659038,
Nishanth Menon59b92af2016-04-21 14:34:25 -0500358 .gpu.abb_tx_done_mask = OMAP_ABB_GPU_TXDONE_MASK,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600359
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530360 .core.value[OPP_NOM] = VDD_CORE_DRA7_NOM,
361 .core.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_CORE_NOM,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600362 .core.efuse.reg_bits = DRA752_EFUSE_REGBITS,
363 .core.addr = TPS659038_REG_ADDR_SMPS6,
364 .core.pmic = &tps659038,
365
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530366 .iva.value[OPP_NOM] = VDD_IVA_DRA7_NOM,
367 .iva.value[OPP_OD] = VDD_IVA_DRA7_OD,
368 .iva.value[OPP_HIGH] = VDD_IVA_DRA7_HIGH,
369 .iva.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_IVA_NOM,
370 .iva.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_IVA_OD,
371 .iva.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_IVA_HIGH,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600372 .iva.efuse.reg_bits = DRA752_EFUSE_REGBITS,
373 .iva.addr = TPS659038_REG_ADDR_SMPS45,
374 .iva.pmic = &tps659038,
Nishanth Menon59b92af2016-04-21 14:34:25 -0500375 .iva.abb_tx_done_mask = OMAP_ABB_IVA_TXDONE_MASK,
Felipe Balbi4750eb62014-11-10 14:02:44 -0600376};
377
Keerthy152e9932016-05-24 11:45:06 +0530378struct vcores_data am572x_idk_volts = {
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530379 .mpu.value[OPP_NOM] = VDD_MPU_DRA7_NOM,
380 .mpu.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_MPU_NOM,
Keerthy152e9932016-05-24 11:45:06 +0530381 .mpu.efuse.reg_bits = DRA752_EFUSE_REGBITS,
382 .mpu.addr = TPS659038_REG_ADDR_SMPS12,
383 .mpu.pmic = &tps659038,
384 .mpu.abb_tx_done_mask = OMAP_ABB_MPU_TXDONE_MASK,
385
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530386 .eve.value[OPP_NOM] = VDD_EVE_DRA7_NOM,
387 .eve.value[OPP_OD] = VDD_EVE_DRA7_OD,
388 .eve.value[OPP_HIGH] = VDD_EVE_DRA7_HIGH,
389 .eve.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_DSPEVE_NOM,
390 .eve.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_DSPEVE_OD,
391 .eve.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_DSPEVE_HIGH,
Keerthy152e9932016-05-24 11:45:06 +0530392 .eve.efuse.reg_bits = DRA752_EFUSE_REGBITS,
393 .eve.addr = TPS659038_REG_ADDR_SMPS45,
394 .eve.pmic = &tps659038,
395 .eve.abb_tx_done_mask = OMAP_ABB_EVE_TXDONE_MASK,
396
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530397 .gpu.value[OPP_NOM] = VDD_GPU_DRA7_NOM,
398 .gpu.value[OPP_OD] = VDD_GPU_DRA7_OD,
399 .gpu.value[OPP_HIGH] = VDD_GPU_DRA7_HIGH,
400 .gpu.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_GPU_NOM,
401 .gpu.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_GPU_OD,
402 .gpu.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_GPU_HIGH,
Keerthy152e9932016-05-24 11:45:06 +0530403 .gpu.efuse.reg_bits = DRA752_EFUSE_REGBITS,
404 .gpu.addr = TPS659038_REG_ADDR_SMPS6,
405 .gpu.pmic = &tps659038,
406 .gpu.abb_tx_done_mask = OMAP_ABB_GPU_TXDONE_MASK,
407
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530408 .core.value[OPP_NOM] = VDD_CORE_DRA7_NOM,
409 .core.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_CORE_NOM,
Keerthy152e9932016-05-24 11:45:06 +0530410 .core.efuse.reg_bits = DRA752_EFUSE_REGBITS,
411 .core.addr = TPS659038_REG_ADDR_SMPS7,
412 .core.pmic = &tps659038,
413
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530414 .iva.value[OPP_NOM] = VDD_IVA_DRA7_NOM,
415 .iva.value[OPP_OD] = VDD_IVA_DRA7_OD,
416 .iva.value[OPP_HIGH] = VDD_IVA_DRA7_HIGH,
417 .iva.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_IVA_NOM,
418 .iva.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_IVA_OD,
419 .iva.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_IVA_HIGH,
Keerthy152e9932016-05-24 11:45:06 +0530420 .iva.efuse.reg_bits = DRA752_EFUSE_REGBITS,
421 .iva.addr = TPS659038_REG_ADDR_SMPS8,
422 .iva.pmic = &tps659038,
423 .iva.abb_tx_done_mask = OMAP_ABB_IVA_TXDONE_MASK,
424};
425
Keerthy9cc2aee2017-05-25 15:37:34 +0530426struct vcores_data am571x_idk_volts = {
427 .mpu.value[OPP_NOM] = VDD_MPU_DRA7_NOM,
428 .mpu.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_MPU_NOM,
429 .mpu.efuse.reg_bits = DRA752_EFUSE_REGBITS,
430 .mpu.addr = TPS659038_REG_ADDR_SMPS12,
431 .mpu.pmic = &tps659038,
432 .mpu.abb_tx_done_mask = OMAP_ABB_MPU_TXDONE_MASK,
433
434 .eve.value[OPP_NOM] = VDD_EVE_DRA7_NOM,
435 .eve.value[OPP_OD] = VDD_EVE_DRA7_OD,
436 .eve.value[OPP_HIGH] = VDD_EVE_DRA7_HIGH,
437 .eve.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_DSPEVE_NOM,
438 .eve.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_DSPEVE_OD,
439 .eve.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_DSPEVE_HIGH,
440 .eve.efuse.reg_bits = DRA752_EFUSE_REGBITS,
441 .eve.addr = TPS659038_REG_ADDR_SMPS45,
442 .eve.pmic = &tps659038,
443 .eve.abb_tx_done_mask = OMAP_ABB_EVE_TXDONE_MASK,
444
445 .gpu.value[OPP_NOM] = VDD_GPU_DRA7_NOM,
446 .gpu.value[OPP_OD] = VDD_GPU_DRA7_OD,
447 .gpu.value[OPP_HIGH] = VDD_GPU_DRA7_HIGH,
448 .gpu.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_GPU_NOM,
449 .gpu.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_GPU_OD,
450 .gpu.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_GPU_HIGH,
451 .gpu.efuse.reg_bits = DRA752_EFUSE_REGBITS,
452 .gpu.addr = TPS659038_REG_ADDR_SMPS6,
453 .gpu.pmic = &tps659038,
454 .gpu.abb_tx_done_mask = OMAP_ABB_GPU_TXDONE_MASK,
455
456 .core.value[OPP_NOM] = VDD_CORE_DRA7_NOM,
457 .core.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_CORE_NOM,
458 .core.efuse.reg_bits = DRA752_EFUSE_REGBITS,
459 .core.addr = TPS659038_REG_ADDR_SMPS7,
460 .core.pmic = &tps659038,
461
462 .iva.value[OPP_NOM] = VDD_IVA_DRA7_NOM,
463 .iva.value[OPP_OD] = VDD_IVA_DRA7_OD,
464 .iva.value[OPP_HIGH] = VDD_IVA_DRA7_HIGH,
465 .iva.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_IVA_NOM,
466 .iva.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_IVA_OD,
467 .iva.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_IVA_HIGH,
468 .iva.efuse.reg_bits = DRA752_EFUSE_REGBITS,
469 .iva.addr = TPS659038_REG_ADDR_SMPS45,
470 .iva.pmic = &tps659038,
471 .iva.abb_tx_done_mask = OMAP_ABB_IVA_TXDONE_MASK,
472};
473
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530474int get_voltrail_opp(int rail_offset)
475{
476 int opp;
477
478 switch (rail_offset) {
479 case VOLT_MPU:
480 opp = DRA7_MPU_OPP;
481 break;
482 case VOLT_CORE:
483 opp = DRA7_CORE_OPP;
484 break;
485 case VOLT_GPU:
486 opp = DRA7_GPU_OPP;
487 break;
488 case VOLT_EVE:
489 opp = DRA7_DSPEVE_OPP;
490 break;
491 case VOLT_IVA:
492 opp = DRA7_IVA_OPP;
493 break;
494 default:
495 opp = OPP_NOM;
496 }
497
498 return opp;
499}
500
501
Kipisz, Steven161f1382016-02-24 12:30:58 -0600502#ifdef CONFIG_SPL_BUILD
503/* No env to setup for SPL */
504static inline void setup_board_eeprom_env(void) { }
505
506/* Override function to read eeprom information */
507void do_board_detect(void)
508{
509 int rc;
510
511 rc = ti_i2c_eeprom_am_get(CONFIG_EEPROM_BUS_ADDRESS,
512 CONFIG_EEPROM_CHIP_ADDRESS);
513 if (rc)
514 printf("ti_i2c_eeprom_init failed %d\n", rc);
Caleb Robey0dfcc932020-01-02 08:17:25 -0600515
516#ifdef CONFIG_SUPPORT_EMMC_BOOT
517 rc = board_bootmode_has_emmc();
518 if (!rc)
519 rc = ti_emmc_boardid_get();
520 if (rc)
521 printf("ti_emmc_boardid_get failed %d\n", rc);
522#endif
Kipisz, Steven161f1382016-02-24 12:30:58 -0600523}
524
525#else /* CONFIG_SPL_BUILD */
526
527/* Override function to read eeprom information: actual i2c read done by SPL*/
528void do_board_detect(void)
529{
530 char *bname = NULL;
531 int rc;
532
533 rc = ti_i2c_eeprom_am_get(CONFIG_EEPROM_BUS_ADDRESS,
534 CONFIG_EEPROM_CHIP_ADDRESS);
535 if (rc)
536 printf("ti_i2c_eeprom_init failed %d\n", rc);
537
Caleb Robey0dfcc932020-01-02 08:17:25 -0600538#ifdef CONFIG_SUPPORT_EMMC_BOOT
539 rc = board_bootmode_has_emmc();
540 if (!rc)
541 rc = ti_emmc_boardid_get();
542 if (rc)
543 printf("ti_emmc_boardid_get failed %d\n", rc);
544#endif
545
Kipisz, Steven161f1382016-02-24 12:30:58 -0600546 if (board_is_x15())
547 bname = "BeagleBoard X15";
548 else if (board_is_am572x_evm())
549 bname = "AM572x EVM";
Lokesh Vutla374aea02017-12-29 11:47:52 +0530550 else if (board_is_am574x_idk())
551 bname = "AM574x IDK";
Steve Kipisz0ac8cea2016-04-08 17:01:29 -0500552 else if (board_is_am572x_idk())
553 bname = "AM572x IDK";
Steve Kipiszc95cddd2016-11-25 11:14:24 +0530554 else if (board_is_am571x_idk())
555 bname = "AM571x IDK";
Kipisz, Steven161f1382016-02-24 12:30:58 -0600556
557 if (bname)
558 snprintf(sysinfo.board_string, SYSINFO_BOARD_NAME_MAX_LEN,
559 "Board: %s REV %s\n", bname, board_ti_get_rev());
560}
561
562static void setup_board_eeprom_env(void)
563{
564 char *name = "beagle_x15";
565 int rc;
566
567 rc = ti_i2c_eeprom_am_get(CONFIG_EEPROM_BUS_ADDRESS,
568 CONFIG_EEPROM_CHIP_ADDRESS);
569 if (rc)
570 goto invalid_eeprom;
571
Nishanth Menona2aea1c2016-11-25 11:14:19 +0530572 if (board_is_x15()) {
Lokesh Vutla638e1c02016-11-25 11:14:20 +0530573 if (board_is_x15_revb1())
574 name = "beagle_x15_revb1";
Lokesh Vutla816178b2017-07-16 19:59:19 +0530575 else if (board_is_x15_revc())
576 name = "beagle_x15_revc";
Lokesh Vutla638e1c02016-11-25 11:14:20 +0530577 else
578 name = "beagle_x15";
Nishanth Menona2aea1c2016-11-25 11:14:19 +0530579 } else if (board_is_am572x_evm()) {
580 if (board_is_am572x_evm_reva3())
581 name = "am57xx_evm_reva3";
582 else
583 name = "am57xx_evm";
Lokesh Vutla374aea02017-12-29 11:47:52 +0530584 } else if (board_is_am574x_idk()) {
585 name = "am574x_idk";
Nishanth Menona2aea1c2016-11-25 11:14:19 +0530586 } else if (board_is_am572x_idk()) {
Steve Kipisz0ac8cea2016-04-08 17:01:29 -0500587 name = "am572x_idk";
Steve Kipiszc95cddd2016-11-25 11:14:24 +0530588 } else if (board_is_am571x_idk()) {
589 name = "am571x_idk";
Nishanth Menona2aea1c2016-11-25 11:14:19 +0530590 } else {
Kipisz, Steven161f1382016-02-24 12:30:58 -0600591 printf("Unidentified board claims %s in eeprom header\n",
592 board_ti_get_name());
Nishanth Menona2aea1c2016-11-25 11:14:19 +0530593 }
Kipisz, Steven161f1382016-02-24 12:30:58 -0600594
595invalid_eeprom:
596 set_board_info_env(name);
597}
598
599#endif /* CONFIG_SPL_BUILD */
600
Keerthy152e9932016-05-24 11:45:06 +0530601void vcores_init(void)
602{
Lokesh Vutla6e9635c2017-12-29 11:47:53 +0530603 if (board_is_am572x_idk() || board_is_am574x_idk())
Keerthy152e9932016-05-24 11:45:06 +0530604 *omap_vcores = &am572x_idk_volts;
Keerthy9cc2aee2017-05-25 15:37:34 +0530605 else if (board_is_am571x_idk())
606 *omap_vcores = &am571x_idk_volts;
Keerthy152e9932016-05-24 11:45:06 +0530607 else
608 *omap_vcores = &beagle_x15_volts;
609}
610
Felipe Balbi4750eb62014-11-10 14:02:44 -0600611void hw_data_init(void)
612{
613 *prcm = &dra7xx_prcm;
Steve Kipisz81c46742017-08-22 13:52:58 +0530614 if (is_dra72x())
615 *dplls_data = &dra72x_dplls;
Lokesh Vutla6e9635c2017-12-29 11:47:53 +0530616 else if (is_dra76x())
617 *dplls_data = &dra76x_dplls;
Steve Kipisz81c46742017-08-22 13:52:58 +0530618 else
619 *dplls_data = &dra7xx_dplls;
Felipe Balbi4750eb62014-11-10 14:02:44 -0600620 *ctrl = &dra7xx_ctrl;
621}
622
Roger Quadros26130592017-03-13 15:04:28 +0200623bool am571x_idk_needs_lcd(void)
624{
625 bool needs_lcd;
626
627 gpio_request(GPIO_ETH_LCD, "nLCD_Detect");
628 if (gpio_get_value(GPIO_ETH_LCD))
629 needs_lcd = false;
630 else
631 needs_lcd = true;
632
633 gpio_free(GPIO_ETH_LCD);
634
635 return needs_lcd;
636}
637
Felipe Balbi4750eb62014-11-10 14:02:44 -0600638int board_init(void)
639{
640 gpmc_init();
641 gd->bd->bi_boot_params = (CONFIG_SYS_SDRAM_BASE + 0x100);
642
643 return 0;
644}
645
Nishanth Menond0f399c2017-03-13 15:04:30 +0200646void am57x_idk_lcd_detect(void)
Felipe Balbi4750eb62014-11-10 14:02:44 -0600647{
Nishanth Menond0f399c2017-03-13 15:04:30 +0200648 int r = -ENODEV;
649 char *idk_lcd = "no";
Jean-Jacques Hiblot184ec9a2018-12-07 14:50:50 +0100650 struct udevice *dev;
Nishanth Menond0f399c2017-03-13 15:04:30 +0200651
652 /* Only valid for IDKs */
653 if (board_is_x15() || board_is_am572x_evm())
654 return;
655
656 /* Only AM571x IDK has gpio control detect.. so check that */
657 if (board_is_am571x_idk() && !am571x_idk_needs_lcd())
658 goto out;
659
Jean-Jacques Hiblot52a51512018-12-07 14:50:49 +0100660 r = i2c_get_chip_for_busnum(OSD_TS_FT_BUS_ADDRESS,
661 OSD_TS_FT_CHIP_ADDRESS, 1, &dev);
Nishanth Menond0f399c2017-03-13 15:04:30 +0200662 if (r) {
Jean-Jacques Hiblot52a51512018-12-07 14:50:49 +0100663 printf("%s: Failed to get I2C device %d/%d (ret %d)\n",
664 __func__, OSD_TS_FT_BUS_ADDRESS, OSD_TS_FT_CHIP_ADDRESS,
665 r);
Nishanth Menond0f399c2017-03-13 15:04:30 +0200666 /* AM572x IDK has no explicit settings for optional LCD kit */
Jean-Jacques Hiblot52a51512018-12-07 14:50:49 +0100667 if (board_is_am571x_idk())
Nishanth Menond0f399c2017-03-13 15:04:30 +0200668 printf("%s: Touch screen detect failed: %d!\n",
669 __func__, r);
Nishanth Menond0f399c2017-03-13 15:04:30 +0200670 goto out;
671 }
672
673 /* Read FT ID */
Jean-Jacques Hiblot52a51512018-12-07 14:50:49 +0100674 r = dm_i2c_reg_read(dev, OSD_TS_FT_REG_ID);
675 if (r < 0) {
Nishanth Menond0f399c2017-03-13 15:04:30 +0200676 printf("%s: Touch screen ID read %d:0x%02x[0x%02x] failed:%d\n",
677 __func__, OSD_TS_FT_BUS_ADDRESS, OSD_TS_FT_CHIP_ADDRESS,
678 OSD_TS_FT_REG_ID, r);
679 goto out;
680 }
681
Jean-Jacques Hiblot184ec9a2018-12-07 14:50:50 +0100682 switch (r) {
Nishanth Menond0f399c2017-03-13 15:04:30 +0200683 case OSD_TS_FT_ID_5606:
684 idk_lcd = "osd101t2045";
685 break;
686 case OSD_TS_FT_ID_5x46:
687 idk_lcd = "osd101t2587";
688 break;
689 default:
690 printf("%s: Unidentifed Touch screen ID 0x%02x\n",
Jean-Jacques Hiblot184ec9a2018-12-07 14:50:50 +0100691 __func__, r);
Nishanth Menond0f399c2017-03-13 15:04:30 +0200692 /* we will let default be "no lcd" */
693 }
694out:
Simon Glass6a38e412017-08-03 12:22:09 -0600695 env_set("idk_lcd", idk_lcd);
Nishanth Menond0f399c2017-03-13 15:04:30 +0200696 return;
697}
Roger Quadros26130592017-03-13 15:04:28 +0200698
Vignesh R98c5f632018-11-29 10:57:42 +0100699#if CONFIG_IS_ENABLED(DM_USB) && CONFIG_IS_ENABLED(OF_CONTROL)
700static int device_okay(const char *path)
701{
702 int node;
703
704 node = fdt_path_offset(gd->fdt_blob, path);
705 if (node < 0)
706 return 0;
707
708 return fdtdec_get_is_enabled(gd->fdt_blob, node);
709}
710#endif
711
Nishanth Menond0f399c2017-03-13 15:04:30 +0200712int board_late_init(void)
713{
Kipisz, Steven161f1382016-02-24 12:30:58 -0600714 setup_board_eeprom_env();
Keerthyee85ebe2016-11-30 15:02:53 +0530715 u8 val;
Tero Kristodfbc6b82019-09-27 19:14:27 +0300716 struct udevice *dev;
Kipisz, Steven161f1382016-02-24 12:30:58 -0600717
Felipe Balbi4750eb62014-11-10 14:02:44 -0600718 /*
719 * DEV_CTRL.DEV_ON = 1 please - else palmas switches off in 8 seconds
720 * This is the POWERHOLD-in-Low behavior.
721 */
722 palmas_i2c_write_u8(TPS65903X_CHIP_P1, 0xA0, 0x1);
Lokesh Vutla2c47e8c2016-11-29 11:58:02 +0530723
724 /*
725 * Default FIT boot on HS devices. Non FIT images are not allowed
726 * on HS devices.
727 */
728 if (get_device_type() == HS_DEVICE)
Simon Glass6a38e412017-08-03 12:22:09 -0600729 env_set("boot_fit", "1");
Lokesh Vutla2c47e8c2016-11-29 11:58:02 +0530730
Keerthyee85ebe2016-11-30 15:02:53 +0530731 /*
732 * Set the GPIO7 Pad to POWERHOLD. This has higher priority
733 * over DEV_CTRL.DEV_ON bit. This can be reset in case of
734 * PMIC Power off. So to be on the safer side set it back
735 * to POWERHOLD mode irrespective of the current state.
736 */
737 palmas_i2c_read_u8(TPS65903X_CHIP_P1, TPS65903X_PRIMARY_SECONDARY_PAD2,
738 &val);
739 val = val | TPS65903X_PAD2_POWERHOLD_MASK;
740 palmas_i2c_write_u8(TPS65903X_CHIP_P1, TPS65903X_PRIMARY_SECONDARY_PAD2,
741 val);
742
Semen Protsenko4b0721f2017-02-13 19:09:37 +0200743 omap_die_id_serial();
Semen Protsenkob72dccd2017-05-22 19:16:41 +0300744 omap_set_fastboot_vars();
Semen Protsenko4b0721f2017-02-13 19:09:37 +0200745
Nishanth Menond0f399c2017-03-13 15:04:30 +0200746 am57x_idk_lcd_detect();
Roger Quadros26130592017-03-13 15:04:28 +0200747
Tero Kristodfbc6b82019-09-27 19:14:27 +0300748 /* Just probe the potentially supported cdce913 device */
749 uclass_get_device(UCLASS_CLK, 0, &dev);
750
Roger Quadros26130592017-03-13 15:04:28 +0200751#if !defined(CONFIG_SPL_BUILD)
752 board_ti_set_ethaddr(2);
753#endif
754
Vignesh R98c5f632018-11-29 10:57:42 +0100755#if CONFIG_IS_ENABLED(DM_USB) && CONFIG_IS_ENABLED(OF_CONTROL)
756 if (device_okay("/ocp/omap_dwc3_1@48880000"))
757 enable_usb_clocks(0);
758 if (device_okay("/ocp/omap_dwc3_2@488c0000"))
759 enable_usb_clocks(1);
760#endif
Felipe Balbi4750eb62014-11-10 14:02:44 -0600761 return 0;
762}
763
Paul Kocialkowskia00b1e52016-02-27 19:18:56 +0100764void set_muxconf_regs(void)
Felipe Balbi4750eb62014-11-10 14:02:44 -0600765{
766 do_set_mux32((*ctrl)->control_padconf_core_base,
Lokesh Vutlac3d39f92015-06-04 16:42:41 +0530767 early_padconf, ARRAY_SIZE(early_padconf));
Caleb Robey0dfcc932020-01-02 08:17:25 -0600768
769#ifdef CONFIG_SUPPORT_EMMC_BOOT
770 do_set_mux32((*ctrl)->control_padconf_core_base,
771 emmc_padconf, ARRAY_SIZE(emmc_padconf));
772#endif
Felipe Balbi4750eb62014-11-10 14:02:44 -0600773}
774
Lokesh Vutlac3d39f92015-06-04 16:42:41 +0530775#ifdef CONFIG_IODELAY_RECALIBRATION
776void recalibrate_iodelay(void)
777{
Steve Kipisz0ac8cea2016-04-08 17:01:29 -0500778 const struct pad_conf_entry *pconf;
Lokesh Vutla3cb4c622017-06-05 14:48:16 +0530779 const struct iodelay_cfg_entry *iod, *delta_iod;
780 int pconf_sz, iod_sz, delta_iod_sz = 0;
Nishanth Menon8e3212e2016-11-25 11:14:22 +0530781 int ret;
Steve Kipisz0ac8cea2016-04-08 17:01:29 -0500782
Lokesh Vutla1e3425c2017-12-29 11:47:55 +0530783 if (board_is_am572x_idk()) {
Steve Kipisz0ac8cea2016-04-08 17:01:29 -0500784 pconf = core_padconf_array_essential_am572x_idk;
785 pconf_sz = ARRAY_SIZE(core_padconf_array_essential_am572x_idk);
786 iod = iodelay_cfg_array_am572x_idk;
787 iod_sz = ARRAY_SIZE(iodelay_cfg_array_am572x_idk);
Lokesh Vutla1e3425c2017-12-29 11:47:55 +0530788 } else if (board_is_am574x_idk()) {
789 pconf = core_padconf_array_essential_am574x_idk;
790 pconf_sz = ARRAY_SIZE(core_padconf_array_essential_am574x_idk);
791 iod = iodelay_cfg_array_am574x_idk;
792 iod_sz = ARRAY_SIZE(iodelay_cfg_array_am574x_idk);
Steve Kipiszc95cddd2016-11-25 11:14:24 +0530793 } else if (board_is_am571x_idk()) {
794 pconf = core_padconf_array_essential_am571x_idk;
795 pconf_sz = ARRAY_SIZE(core_padconf_array_essential_am571x_idk);
796 iod = iodelay_cfg_array_am571x_idk;
797 iod_sz = ARRAY_SIZE(iodelay_cfg_array_am571x_idk);
Steve Kipisz0ac8cea2016-04-08 17:01:29 -0500798 } else {
799 /* Common for X15/GPEVM */
800 pconf = core_padconf_array_essential_x15;
801 pconf_sz = ARRAY_SIZE(core_padconf_array_essential_x15);
Nishanth Menon8e3212e2016-11-25 11:14:22 +0530802 /* There never was an SR1.0 X15.. So.. */
803 if (omap_revision() == DRA752_ES1_1) {
804 iod = iodelay_cfg_array_x15_sr1_1;
805 iod_sz = ARRAY_SIZE(iodelay_cfg_array_x15_sr1_1);
806 } else {
807 /* Since full production should switch to SR2.0 */
808 iod = iodelay_cfg_array_x15_sr2_0;
809 iod_sz = ARRAY_SIZE(iodelay_cfg_array_x15_sr2_0);
810 }
Steve Kipisz0ac8cea2016-04-08 17:01:29 -0500811 }
812
Nishanth Menon8e3212e2016-11-25 11:14:22 +0530813 /* Setup I/O isolation */
814 ret = __recalibrate_iodelay_start();
815 if (ret)
816 goto err;
817
818 /* Do the muxing here */
819 do_set_mux32((*ctrl)->control_padconf_core_base, pconf, pconf_sz);
820
821 /* Now do the weird minor deltas that should be safe */
822 if (board_is_x15() || board_is_am572x_evm()) {
Lokesh Vutla816178b2017-07-16 19:59:19 +0530823 if (board_is_x15_revb1() || board_is_am572x_evm_reva3() ||
824 board_is_x15_revc()) {
Nishanth Menon8e3212e2016-11-25 11:14:22 +0530825 pconf = core_padconf_array_delta_x15_sr2_0;
826 pconf_sz = ARRAY_SIZE(core_padconf_array_delta_x15_sr2_0);
827 } else {
828 pconf = core_padconf_array_delta_x15_sr1_1;
829 pconf_sz = ARRAY_SIZE(core_padconf_array_delta_x15_sr1_1);
830 }
831 do_set_mux32((*ctrl)->control_padconf_core_base, pconf, pconf_sz);
832 }
833
Roger Quadros26130592017-03-13 15:04:28 +0200834 if (board_is_am571x_idk()) {
835 if (am571x_idk_needs_lcd()) {
836 pconf = core_padconf_array_vout_am571x_idk;
837 pconf_sz = ARRAY_SIZE(core_padconf_array_vout_am571x_idk);
Lokesh Vutla3cb4c622017-06-05 14:48:16 +0530838 delta_iod = iodelay_cfg_array_am571x_idk_4port;
839 delta_iod_sz = ARRAY_SIZE(iodelay_cfg_array_am571x_idk_4port);
840
Roger Quadros26130592017-03-13 15:04:28 +0200841 } else {
842 pconf = core_padconf_array_icss1eth_am571x_idk;
843 pconf_sz = ARRAY_SIZE(core_padconf_array_icss1eth_am571x_idk);
844 }
845 do_set_mux32((*ctrl)->control_padconf_core_base, pconf, pconf_sz);
846 }
847
Nishanth Menon8e3212e2016-11-25 11:14:22 +0530848 /* Setup IOdelay configuration */
849 ret = do_set_iodelay((*ctrl)->iodelay_config_base, iod, iod_sz);
Lokesh Vutla3cb4c622017-06-05 14:48:16 +0530850 if (delta_iod_sz)
851 ret = do_set_iodelay((*ctrl)->iodelay_config_base, delta_iod,
852 delta_iod_sz);
853
Nishanth Menon8e3212e2016-11-25 11:14:22 +0530854err:
855 /* Closeup.. remove isolation */
856 __recalibrate_iodelay_end(ret);
Lokesh Vutlac3d39f92015-06-04 16:42:41 +0530857}
858#endif
859
Masahiro Yamada0a780172017-05-09 20:31:39 +0900860#if defined(CONFIG_MMC)
Felipe Balbi4750eb62014-11-10 14:02:44 -0600861int board_mmc_init(bd_t *bis)
862{
863 omap_mmc_init(0, 0, 0, -1, -1);
864 omap_mmc_init(1, 0, 0, -1, -1);
865 return 0;
866}
Kishon Vijay Abraham I110ed012018-01-30 16:01:52 +0100867
868static const struct mmc_platform_fixups am57x_es1_1_mmc1_fixups = {
869 .hw_rev = "rev11",
870 .unsupported_caps = MMC_CAP(MMC_HS_200) |
871 MMC_CAP(UHS_SDR104),
872 .max_freq = 96000000,
873};
874
875static const struct mmc_platform_fixups am57x_es1_1_mmc23_fixups = {
876 .hw_rev = "rev11",
877 .unsupported_caps = MMC_CAP(MMC_HS_200) |
878 MMC_CAP(UHS_SDR104) |
879 MMC_CAP(UHS_SDR50),
880 .max_freq = 48000000,
881};
882
883const struct mmc_platform_fixups *platform_fixups_mmc(uint32_t addr)
884{
885 switch (omap_revision()) {
886 case DRA752_ES1_0:
887 case DRA752_ES1_1:
888 if (addr == OMAP_HSMMC1_BASE)
889 return &am57x_es1_1_mmc1_fixups;
890 else
891 return &am57x_es1_1_mmc23_fixups;
892 default:
893 return NULL;
894 }
895}
Felipe Balbi4750eb62014-11-10 14:02:44 -0600896#endif
897
898#if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_OS_BOOT)
899int spl_start_uboot(void)
900{
901 /* break into full u-boot on 'c' */
902 if (serial_tstc() && serial_getc() == 'c')
903 return 1;
904
905#ifdef CONFIG_SPL_ENV_SUPPORT
906 env_init();
Simon Glass17539572017-08-03 12:22:07 -0600907 env_load();
Simon Glass22c34c22017-08-03 12:22:13 -0600908 if (env_get_yesno("boot_os") != 1)
Felipe Balbi4750eb62014-11-10 14:02:44 -0600909 return 1;
910#endif
911
912 return 0;
913}
914#endif
915
916#ifdef CONFIG_DRIVER_TI_CPSW
917
918/* Delay value to add to calibrated value */
919#define RGMII0_TXCTL_DLY_VAL ((0x3 << 5) + 0x8)
920#define RGMII0_TXD0_DLY_VAL ((0x3 << 5) + 0x8)
921#define RGMII0_TXD1_DLY_VAL ((0x3 << 5) + 0x2)
922#define RGMII0_TXD2_DLY_VAL ((0x4 << 5) + 0x0)
923#define RGMII0_TXD3_DLY_VAL ((0x4 << 5) + 0x0)
924#define VIN2A_D13_DLY_VAL ((0x3 << 5) + 0x8)
925#define VIN2A_D17_DLY_VAL ((0x3 << 5) + 0x8)
926#define VIN2A_D16_DLY_VAL ((0x3 << 5) + 0x2)
927#define VIN2A_D15_DLY_VAL ((0x4 << 5) + 0x0)
928#define VIN2A_D14_DLY_VAL ((0x4 << 5) + 0x0)
929
930static void cpsw_control(int enabled)
931{
932 /* VTP can be added here */
933}
934
935static struct cpsw_slave_data cpsw_slaves[] = {
936 {
937 .slave_reg_ofs = 0x208,
938 .sliver_reg_ofs = 0xd80,
939 .phy_addr = 1,
940 },
941 {
942 .slave_reg_ofs = 0x308,
943 .sliver_reg_ofs = 0xdc0,
944 .phy_addr = 2,
945 },
946};
947
948static struct cpsw_platform_data cpsw_data = {
949 .mdio_base = CPSW_MDIO_BASE,
950 .cpsw_base = CPSW_BASE,
951 .mdio_div = 0xff,
952 .channels = 8,
953 .cpdma_reg_ofs = 0x800,
954 .slaves = 1,
955 .slave_data = cpsw_slaves,
956 .ale_reg_ofs = 0xd00,
957 .ale_entries = 1024,
958 .host_port_reg_ofs = 0x108,
959 .hw_stats_reg_ofs = 0x900,
960 .bd_ram_ofs = 0x2000,
961 .mac_control = (1 << 5),
962 .control = cpsw_control,
963 .host_port_num = 0,
964 .version = CPSW_CTRL_VERSION_2,
965};
966
Roger Quadros64217a22016-03-18 13:18:12 +0200967static u64 mac_to_u64(u8 mac[6])
968{
969 int i;
970 u64 addr = 0;
971
972 for (i = 0; i < 6; i++) {
973 addr <<= 8;
974 addr |= mac[i];
975 }
976
977 return addr;
978}
979
980static void u64_to_mac(u64 addr, u8 mac[6])
981{
982 mac[5] = addr;
983 mac[4] = addr >> 8;
984 mac[3] = addr >> 16;
985 mac[2] = addr >> 24;
986 mac[1] = addr >> 32;
987 mac[0] = addr >> 40;
988}
989
Felipe Balbi4750eb62014-11-10 14:02:44 -0600990int board_eth_init(bd_t *bis)
991{
992 int ret;
993 uint8_t mac_addr[6];
994 uint32_t mac_hi, mac_lo;
995 uint32_t ctrl_val;
Roger Quadros64217a22016-03-18 13:18:12 +0200996 int i;
997 u64 mac1, mac2;
998 u8 mac_addr1[6], mac_addr2[6];
999 int num_macs;
Felipe Balbi4750eb62014-11-10 14:02:44 -06001000
1001 /* try reading mac address from efuse */
1002 mac_lo = readl((*ctrl)->control_core_mac_id_0_lo);
1003 mac_hi = readl((*ctrl)->control_core_mac_id_0_hi);
1004 mac_addr[0] = (mac_hi & 0xFF0000) >> 16;
1005 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
1006 mac_addr[2] = mac_hi & 0xFF;
1007 mac_addr[3] = (mac_lo & 0xFF0000) >> 16;
1008 mac_addr[4] = (mac_lo & 0xFF00) >> 8;
1009 mac_addr[5] = mac_lo & 0xFF;
1010
Simon Glass64b723f2017-08-03 12:22:12 -06001011 if (!env_get("ethaddr")) {
Felipe Balbi4750eb62014-11-10 14:02:44 -06001012 printf("<ethaddr> not set. Validating first E-fuse MAC\n");
1013
Joe Hershberger8ecdbed2015-04-08 01:41:04 -05001014 if (is_valid_ethaddr(mac_addr))
Simon Glass8551d552017-08-03 12:22:11 -06001015 eth_env_set_enetaddr("ethaddr", mac_addr);
Felipe Balbi4750eb62014-11-10 14:02:44 -06001016 }
1017
1018 mac_lo = readl((*ctrl)->control_core_mac_id_1_lo);
1019 mac_hi = readl((*ctrl)->control_core_mac_id_1_hi);
1020 mac_addr[0] = (mac_hi & 0xFF0000) >> 16;
1021 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
1022 mac_addr[2] = mac_hi & 0xFF;
1023 mac_addr[3] = (mac_lo & 0xFF0000) >> 16;
1024 mac_addr[4] = (mac_lo & 0xFF00) >> 8;
1025 mac_addr[5] = mac_lo & 0xFF;
1026
Simon Glass64b723f2017-08-03 12:22:12 -06001027 if (!env_get("eth1addr")) {
Joe Hershberger8ecdbed2015-04-08 01:41:04 -05001028 if (is_valid_ethaddr(mac_addr))
Simon Glass8551d552017-08-03 12:22:11 -06001029 eth_env_set_enetaddr("eth1addr", mac_addr);
Felipe Balbi4750eb62014-11-10 14:02:44 -06001030 }
1031
1032 ctrl_val = readl((*ctrl)->control_core_control_io1) & (~0x33);
1033 ctrl_val |= 0x22;
1034 writel(ctrl_val, (*ctrl)->control_core_control_io1);
1035
Steve Kipiszc95cddd2016-11-25 11:14:24 +05301036 /* The phy address for the AM57xx IDK are different than x15 */
Lokesh Vutla6e9635c2017-12-29 11:47:53 +05301037 if (board_is_am572x_idk() || board_is_am571x_idk() ||
1038 board_is_am574x_idk()) {
Steve Kipisz0ac8cea2016-04-08 17:01:29 -05001039 cpsw_data.slave_data[0].phy_addr = 0;
1040 cpsw_data.slave_data[1].phy_addr = 1;
1041 }
1042
Felipe Balbi4750eb62014-11-10 14:02:44 -06001043 ret = cpsw_register(&cpsw_data);
1044 if (ret < 0)
1045 printf("Error %d registering CPSW switch\n", ret);
1046
Roger Quadros64217a22016-03-18 13:18:12 +02001047 /*
1048 * Export any Ethernet MAC addresses from EEPROM.
1049 * On AM57xx the 2 MAC addresses define the address range
1050 */
1051 board_ti_get_eth_mac_addr(0, mac_addr1);
1052 board_ti_get_eth_mac_addr(1, mac_addr2);
1053
1054 if (is_valid_ethaddr(mac_addr1) && is_valid_ethaddr(mac_addr2)) {
1055 mac1 = mac_to_u64(mac_addr1);
1056 mac2 = mac_to_u64(mac_addr2);
1057
1058 /* must contain an address range */
1059 num_macs = mac2 - mac1 + 1;
1060 /* <= 50 to protect against user programming error */
1061 if (num_macs > 0 && num_macs <= 50) {
1062 for (i = 0; i < num_macs; i++) {
1063 u64_to_mac(mac1 + i, mac_addr);
1064 if (is_valid_ethaddr(mac_addr)) {
Simon Glass8551d552017-08-03 12:22:11 -06001065 eth_env_set_enetaddr_by_index("eth",
1066 i + 2,
1067 mac_addr);
Roger Quadros64217a22016-03-18 13:18:12 +02001068 }
1069 }
1070 }
1071 }
1072
Felipe Balbi4750eb62014-11-10 14:02:44 -06001073 return ret;
1074}
1075#endif
Lokesh Vutla9f150672015-06-16 20:36:05 +05301076
1077#ifdef CONFIG_BOARD_EARLY_INIT_F
1078/* VTT regulator enable */
1079static inline void vtt_regulator_enable(void)
1080{
1081 if (omap_hw_init_context() == OMAP_INIT_CONTEXT_UBOOT_AFTER_SPL)
1082 return;
1083
1084 gpio_request(GPIO_DDR_VTT_EN, "ddr_vtt_en");
1085 gpio_direction_output(GPIO_DDR_VTT_EN, 1);
1086}
1087
1088int board_early_init_f(void)
1089{
1090 vtt_regulator_enable();
1091 return 0;
1092}
1093#endif
Daniel Allred7ceffb22016-05-19 19:10:54 -05001094
1095#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
1096int ft_board_setup(void *blob, bd_t *bd)
1097{
1098 ft_cpu_setup(blob, bd);
1099
1100 return 0;
1101}
1102#endif
Lokesh Vutla00bf8b22016-06-10 09:35:43 +05301103
1104#ifdef CONFIG_SPL_LOAD_FIT
1105int board_fit_config_name_match(const char *name)
1106{
Lokesh Vutla638e1c02016-11-25 11:14:20 +05301107 if (board_is_x15()) {
1108 if (board_is_x15_revb1()) {
1109 if (!strcmp(name, "am57xx-beagle-x15-revb1"))
1110 return 0;
Lokesh Vutlaf35589c2017-08-23 11:39:06 +05301111 } else if (board_is_x15_revc()) {
1112 if (!strcmp(name, "am57xx-beagle-x15-revc"))
1113 return 0;
Lokesh Vutla638e1c02016-11-25 11:14:20 +05301114 } else if (!strcmp(name, "am57xx-beagle-x15")) {
1115 return 0;
1116 }
1117 } else if (board_is_am572x_evm() &&
1118 !strcmp(name, "am57xx-beagle-x15")) {
Lokesh Vutla00bf8b22016-06-10 09:35:43 +05301119 return 0;
Lokesh Vutla638e1c02016-11-25 11:14:20 +05301120 } else if (board_is_am572x_idk() && !strcmp(name, "am572x-idk")) {
Schuyler Patton99519852016-06-10 09:35:45 +05301121 return 0;
Lokesh Vutla58a3c1b2017-12-29 11:47:57 +05301122 } else if (board_is_am574x_idk() && !strcmp(name, "am574x-idk")) {
1123 return 0;
Schuyler Pattonc665e272016-11-25 11:14:25 +05301124 } else if (board_is_am571x_idk() && !strcmp(name, "am571x-idk")) {
1125 return 0;
Lokesh Vutla638e1c02016-11-25 11:14:20 +05301126 }
1127
1128 return -1;
Lokesh Vutla00bf8b22016-06-10 09:35:43 +05301129}
1130#endif
Andreas Dannenberg5cf344b2016-06-27 09:19:22 -05001131
Andrew F. Davisd3555832019-02-11 08:00:08 -06001132#if CONFIG_IS_ENABLED(FASTBOOT) && !CONFIG_IS_ENABLED(ENV_IS_NOWHERE)
1133int fastboot_set_reboot_flag(void)
1134{
1135 printf("Setting reboot to fastboot flag ...\n");
1136 env_set("dofastboot", "1");
1137 env_save();
1138 return 0;
1139}
1140#endif
1141
Caleb Robey0dfcc932020-01-02 08:17:25 -06001142#ifdef CONFIG_SUPPORT_EMMC_BOOT
1143static int board_bootmode_has_emmc(void)
1144{
1145 /* Check that boot mode is same as BBAI */
1146 if (gd->arch.omap_boot_mode != 2)
1147 return -EIO;
1148
1149 return 0;
1150}
1151#endif
1152
Andreas Dannenberg5cf344b2016-06-27 09:19:22 -05001153#ifdef CONFIG_TI_SECURE_DEVICE
1154void board_fit_image_post_process(void **p_image, size_t *p_size)
1155{
1156 secure_boot_verify_image(p_image, p_size);
1157}
Andrew F. Davis7d250622016-11-29 16:33:26 -06001158
1159void board_tee_image_process(ulong tee_image, size_t tee_size)
1160{
1161 secure_tee_install((u32)tee_image);
1162}
1163
1164U_BOOT_FIT_LOADABLE_HANDLER(IH_TYPE_TEE, board_tee_image_process);
Andreas Dannenberg5cf344b2016-06-27 09:19:22 -05001165#endif