blob: 5f2d4dfab8c5aa103743f10a5d4d03f1fad9cc5d [file] [log] [blame]
Felipe Balbi1e4ad742014-11-10 14:02:44 -06001/*
2 * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com
3 *
4 * Author: Felipe Balbi <balbi@ti.com>
5 *
6 * Based on board/ti/dra7xx/evm.c
7 *
8 * SPDX-License-Identifier: GPL-2.0+
9 */
10
11#include <common.h>
12#include <palmas.h>
13#include <sata.h>
14#include <usb.h>
15#include <asm/omap_common.h>
Andreas Dannenberg17c29872016-06-27 09:19:22 -050016#include <asm/omap_sec_common.h>
Felipe Balbi1e4ad742014-11-10 14:02:44 -060017#include <asm/emif.h>
Lokesh Vutla334bbb32015-06-16 20:36:05 +053018#include <asm/gpio.h>
19#include <asm/arch/gpio.h>
Felipe Balbi1e4ad742014-11-10 14:02:44 -060020#include <asm/arch/clock.h>
Lokesh Vutlaf91e0c42015-06-04 16:42:41 +053021#include <asm/arch/dra7xx_iodelay.h>
Felipe Balbi1e4ad742014-11-10 14:02:44 -060022#include <asm/arch/sys_proto.h>
23#include <asm/arch/mmc_host_def.h>
24#include <asm/arch/sata.h>
25#include <asm/arch/gpio.h>
Kishon Vijay Abraham I7c379aa2015-08-19 14:13:19 +053026#include <asm/arch/omap.h>
Felipe Balbi1e4ad742014-11-10 14:02:44 -060027#include <environment.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>
Felipe Balbi1e4ad742014-11-10 14:02:44 -060033
Kipisz, Steven212f96f2016-02-24 12:30:58 -060034#include "../common/board_detect.h"
Felipe Balbi1e4ad742014-11-10 14:02:44 -060035#include "mux_data.h"
36
Kipisz, Steven212f96f2016-02-24 12:30:58 -060037#define board_is_x15() board_ti_is("BBRDX15_")
Lokesh Vutlaf7f9f6b2016-11-25 11:14:20 +053038#define board_is_x15_revb1() (board_ti_is("BBRDX15_") && \
39 (strncmp("B.10", board_ti_get_rev(), 3) <= 0))
Kipisz, Steven212f96f2016-02-24 12:30:58 -060040#define board_is_am572x_evm() board_ti_is("AM572PM_")
Nishanth Menonbf43ce62016-11-25 11:14:19 +053041#define board_is_am572x_evm_reva3() \
42 (board_ti_is("AM572PM_") && \
43 (strncmp("A.30", board_ti_get_rev(), 3) <= 0))
Steve Kipiszc020d352016-04-08 17:01:29 -050044#define board_is_am572x_idk() board_ti_is("AM572IDK")
Steve Kipisz4d8397c2016-11-25 11:14:24 +053045#define board_is_am571x_idk() board_ti_is("AM571IDK")
Kipisz, Steven212f96f2016-02-24 12:30:58 -060046
Felipe Balbi1e4ad742014-11-10 14:02:44 -060047#ifdef CONFIG_DRIVER_TI_CPSW
48#include <cpsw.h>
49#endif
50
51DECLARE_GLOBAL_DATA_PTR;
52
Lokesh Vutla334bbb32015-06-16 20:36:05 +053053/* GPIO 7_11 */
54#define GPIO_DDR_VTT_EN 203
55
Kipisz, Steven212f96f2016-02-24 12:30:58 -060056#define SYSINFO_BOARD_NAME_MAX_LEN 45
57
Keerthy385d3632016-11-30 15:02:53 +053058#define TPS65903X_PRIMARY_SECONDARY_PAD2 0xFB
59#define TPS65903X_PAD2_POWERHOLD_MASK 0x20
60
Felipe Balbi1e4ad742014-11-10 14:02:44 -060061const struct omap_sysinfo sysinfo = {
Kipisz, Steven212f96f2016-02-24 12:30:58 -060062 "Board: UNKNOWN(BeagleBoard X15?) REV UNKNOWN\n"
Felipe Balbi1e4ad742014-11-10 14:02:44 -060063};
64
65static const struct dmm_lisa_map_regs beagle_x15_lisa_regs = {
66 .dmm_lisa_map_3 = 0x80740300,
67 .is_ma_present = 0x1
68};
69
Steve Kipisz4d8397c2016-11-25 11:14:24 +053070static const struct dmm_lisa_map_regs am571x_idk_lisa_regs = {
71 .dmm_lisa_map_3 = 0x80640100,
72 .is_ma_present = 0x1
73};
74
Felipe Balbi1e4ad742014-11-10 14:02:44 -060075void emif_get_dmm_regs(const struct dmm_lisa_map_regs **dmm_lisa_regs)
76{
Steve Kipisz4d8397c2016-11-25 11:14:24 +053077 if (board_is_am571x_idk())
78 *dmm_lisa_regs = &am571x_idk_lisa_regs;
79 else
80 *dmm_lisa_regs = &beagle_x15_lisa_regs;
Felipe Balbi1e4ad742014-11-10 14:02:44 -060081}
82
83static const struct emif_regs beagle_x15_emif1_ddr3_532mhz_emif_regs = {
Keerthyeafd4642016-05-24 11:45:07 +053084 .sdram_config_init = 0x61851b32,
85 .sdram_config = 0x61851b32,
86 .sdram_config2 = 0x08000000,
87 .ref_ctrl = 0x000040F1,
88 .ref_ctrl_final = 0x00001035,
89 .sdram_tim1 = 0xcccf36ab,
90 .sdram_tim2 = 0x308f7fda,
91 .sdram_tim3 = 0x409f88a8,
92 .read_idle_ctrl = 0x00050000,
93 .zq_config = 0x5007190b,
94 .temp_alert_config = 0x00000000,
95 .emif_ddr_phy_ctlr_1_init = 0x0024400b,
96 .emif_ddr_phy_ctlr_1 = 0x0e24400b,
97 .emif_ddr_ext_phy_ctrl_1 = 0x10040100,
98 .emif_ddr_ext_phy_ctrl_2 = 0x00910091,
99 .emif_ddr_ext_phy_ctrl_3 = 0x00950095,
100 .emif_ddr_ext_phy_ctrl_4 = 0x009b009b,
101 .emif_ddr_ext_phy_ctrl_5 = 0x009e009e,
102 .emif_rd_wr_lvl_rmp_win = 0x00000000,
103 .emif_rd_wr_lvl_rmp_ctl = 0x80000000,
104 .emif_rd_wr_lvl_ctl = 0x00000000,
105 .emif_rd_wr_exec_thresh = 0x00000305
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600106};
107
Lokesh Vutla6213db72015-06-03 14:43:21 +0530108/* Ext phy ctrl regs 1-35 */
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600109static const u32 beagle_x15_emif1_ddr3_ext_phy_ctrl_const_regs[] = {
Lokesh Vutla6213db72015-06-03 14:43:21 +0530110 0x10040100,
Lokesh Vutla11e2b042016-03-08 09:11:35 +0530111 0x00910091,
112 0x00950095,
113 0x009B009B,
114 0x009E009E,
115 0x00980098,
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600116 0x00340034,
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600117 0x00350035,
Lokesh Vutla11e2b042016-03-08 09:11:35 +0530118 0x00340034,
119 0x00310031,
120 0x00340034,
121 0x007F007F,
122 0x007F007F,
123 0x007F007F,
124 0x007F007F,
125 0x007F007F,
126 0x00480048,
127 0x004A004A,
128 0x00520052,
129 0x00550055,
130 0x00500050,
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600131 0x00000000,
132 0x00600020,
Lokesh Vutla6213db72015-06-03 14:43:21 +0530133 0x40011080,
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600134 0x08102040,
Lokesh Vutla11e2b042016-03-08 09:11:35 +0530135 0x0,
136 0x0,
137 0x0,
138 0x0,
139 0x0,
Lokesh Vutla496edff2015-06-03 14:43:22 +0530140 0x0,
141 0x0,
142 0x0,
143 0x0,
144 0x0
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600145};
146
147static const struct emif_regs beagle_x15_emif2_ddr3_532mhz_emif_regs = {
Keerthyeafd4642016-05-24 11:45:07 +0530148 .sdram_config_init = 0x61851b32,
149 .sdram_config = 0x61851b32,
150 .sdram_config2 = 0x08000000,
151 .ref_ctrl = 0x000040F1,
152 .ref_ctrl_final = 0x00001035,
153 .sdram_tim1 = 0xcccf36b3,
154 .sdram_tim2 = 0x308f7fda,
155 .sdram_tim3 = 0x407f88a8,
156 .read_idle_ctrl = 0x00050000,
157 .zq_config = 0x5007190b,
158 .temp_alert_config = 0x00000000,
159 .emif_ddr_phy_ctlr_1_init = 0x0024400b,
160 .emif_ddr_phy_ctlr_1 = 0x0e24400b,
161 .emif_ddr_ext_phy_ctrl_1 = 0x10040100,
162 .emif_ddr_ext_phy_ctrl_2 = 0x00910091,
163 .emif_ddr_ext_phy_ctrl_3 = 0x00950095,
164 .emif_ddr_ext_phy_ctrl_4 = 0x009b009b,
165 .emif_ddr_ext_phy_ctrl_5 = 0x009e009e,
166 .emif_rd_wr_lvl_rmp_win = 0x00000000,
167 .emif_rd_wr_lvl_rmp_ctl = 0x80000000,
168 .emif_rd_wr_lvl_ctl = 0x00000000,
169 .emif_rd_wr_exec_thresh = 0x00000305
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600170};
171
172static const u32 beagle_x15_emif2_ddr3_ext_phy_ctrl_const_regs[] = {
Lokesh Vutla6213db72015-06-03 14:43:21 +0530173 0x10040100,
Lokesh Vutla11e2b042016-03-08 09:11:35 +0530174 0x00910091,
175 0x00950095,
176 0x009B009B,
177 0x009E009E,
178 0x00980098,
179 0x00340034,
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600180 0x00350035,
Lokesh Vutla11e2b042016-03-08 09:11:35 +0530181 0x00340034,
182 0x00310031,
183 0x00340034,
184 0x007F007F,
185 0x007F007F,
186 0x007F007F,
187 0x007F007F,
188 0x007F007F,
189 0x00480048,
190 0x004A004A,
191 0x00520052,
192 0x00550055,
193 0x00500050,
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600194 0x00000000,
195 0x00600020,
Lokesh Vutla6213db72015-06-03 14:43:21 +0530196 0x40011080,
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600197 0x08102040,
Lokesh Vutla11e2b042016-03-08 09:11:35 +0530198 0x0,
199 0x0,
200 0x0,
201 0x0,
202 0x0,
Lokesh Vutla496edff2015-06-03 14:43:22 +0530203 0x0,
204 0x0,
205 0x0,
206 0x0,
207 0x0
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600208};
209
210void emif_get_reg_dump(u32 emif_nr, const struct emif_regs **regs)
211{
212 switch (emif_nr) {
213 case 1:
214 *regs = &beagle_x15_emif1_ddr3_532mhz_emif_regs;
215 break;
216 case 2:
217 *regs = &beagle_x15_emif2_ddr3_532mhz_emif_regs;
218 break;
219 }
220}
221
222void emif_get_ext_phy_ctrl_const_regs(u32 emif_nr, const u32 **regs, u32 *size)
223{
224 switch (emif_nr) {
225 case 1:
226 *regs = beagle_x15_emif1_ddr3_ext_phy_ctrl_const_regs;
227 *size = ARRAY_SIZE(beagle_x15_emif1_ddr3_ext_phy_ctrl_const_regs);
228 break;
229 case 2:
230 *regs = beagle_x15_emif2_ddr3_ext_phy_ctrl_const_regs;
231 *size = ARRAY_SIZE(beagle_x15_emif2_ddr3_ext_phy_ctrl_const_regs);
232 break;
233 }
234}
235
236struct vcores_data beagle_x15_volts = {
Lokesh Vutlabeb71272016-11-23 12:54:39 +0530237 .mpu.value[OPP_NOM] = VDD_MPU_DRA7_NOM,
238 .mpu.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_MPU_NOM,
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600239 .mpu.efuse.reg_bits = DRA752_EFUSE_REGBITS,
240 .mpu.addr = TPS659038_REG_ADDR_SMPS12,
241 .mpu.pmic = &tps659038,
Keerthyeafd4642016-05-24 11:45:07 +0530242 .mpu.abb_tx_done_mask = OMAP_ABB_MPU_TXDONE_MASK,
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600243
Lokesh Vutlabeb71272016-11-23 12:54:39 +0530244 .eve.value[OPP_NOM] = VDD_EVE_DRA7_NOM,
245 .eve.value[OPP_OD] = VDD_EVE_DRA7_OD,
246 .eve.value[OPP_HIGH] = VDD_EVE_DRA7_HIGH,
247 .eve.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_DSPEVE_NOM,
248 .eve.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_DSPEVE_OD,
249 .eve.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_DSPEVE_HIGH,
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600250 .eve.efuse.reg_bits = DRA752_EFUSE_REGBITS,
251 .eve.addr = TPS659038_REG_ADDR_SMPS45,
252 .eve.pmic = &tps659038,
Nishanth Menone52e3342016-04-21 14:34:25 -0500253 .eve.abb_tx_done_mask = OMAP_ABB_EVE_TXDONE_MASK,
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600254
Lokesh Vutlabeb71272016-11-23 12:54:39 +0530255 .gpu.value[OPP_NOM] = VDD_GPU_DRA7_NOM,
256 .gpu.value[OPP_OD] = VDD_GPU_DRA7_OD,
257 .gpu.value[OPP_HIGH] = VDD_GPU_DRA7_HIGH,
258 .gpu.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_GPU_NOM,
259 .gpu.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_GPU_OD,
260 .gpu.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_GPU_HIGH,
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600261 .gpu.efuse.reg_bits = DRA752_EFUSE_REGBITS,
262 .gpu.addr = TPS659038_REG_ADDR_SMPS45,
263 .gpu.pmic = &tps659038,
Nishanth Menone52e3342016-04-21 14:34:25 -0500264 .gpu.abb_tx_done_mask = OMAP_ABB_GPU_TXDONE_MASK,
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600265
Lokesh Vutlabeb71272016-11-23 12:54:39 +0530266 .core.value[OPP_NOM] = VDD_CORE_DRA7_NOM,
267 .core.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_CORE_NOM,
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600268 .core.efuse.reg_bits = DRA752_EFUSE_REGBITS,
269 .core.addr = TPS659038_REG_ADDR_SMPS6,
270 .core.pmic = &tps659038,
271
Lokesh Vutlabeb71272016-11-23 12:54:39 +0530272 .iva.value[OPP_NOM] = VDD_IVA_DRA7_NOM,
273 .iva.value[OPP_OD] = VDD_IVA_DRA7_OD,
274 .iva.value[OPP_HIGH] = VDD_IVA_DRA7_HIGH,
275 .iva.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_IVA_NOM,
276 .iva.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_IVA_OD,
277 .iva.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_IVA_HIGH,
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600278 .iva.efuse.reg_bits = DRA752_EFUSE_REGBITS,
279 .iva.addr = TPS659038_REG_ADDR_SMPS45,
280 .iva.pmic = &tps659038,
Nishanth Menone52e3342016-04-21 14:34:25 -0500281 .iva.abb_tx_done_mask = OMAP_ABB_IVA_TXDONE_MASK,
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600282};
283
Keerthyd60198d2016-05-24 11:45:06 +0530284struct vcores_data am572x_idk_volts = {
Lokesh Vutlabeb71272016-11-23 12:54:39 +0530285 .mpu.value[OPP_NOM] = VDD_MPU_DRA7_NOM,
286 .mpu.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_MPU_NOM,
Keerthyd60198d2016-05-24 11:45:06 +0530287 .mpu.efuse.reg_bits = DRA752_EFUSE_REGBITS,
288 .mpu.addr = TPS659038_REG_ADDR_SMPS12,
289 .mpu.pmic = &tps659038,
290 .mpu.abb_tx_done_mask = OMAP_ABB_MPU_TXDONE_MASK,
291
Lokesh Vutlabeb71272016-11-23 12:54:39 +0530292 .eve.value[OPP_NOM] = VDD_EVE_DRA7_NOM,
293 .eve.value[OPP_OD] = VDD_EVE_DRA7_OD,
294 .eve.value[OPP_HIGH] = VDD_EVE_DRA7_HIGH,
295 .eve.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_DSPEVE_NOM,
296 .eve.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_DSPEVE_OD,
297 .eve.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_DSPEVE_HIGH,
Keerthyd60198d2016-05-24 11:45:06 +0530298 .eve.efuse.reg_bits = DRA752_EFUSE_REGBITS,
299 .eve.addr = TPS659038_REG_ADDR_SMPS45,
300 .eve.pmic = &tps659038,
301 .eve.abb_tx_done_mask = OMAP_ABB_EVE_TXDONE_MASK,
302
Lokesh Vutlabeb71272016-11-23 12:54:39 +0530303 .gpu.value[OPP_NOM] = VDD_GPU_DRA7_NOM,
304 .gpu.value[OPP_OD] = VDD_GPU_DRA7_OD,
305 .gpu.value[OPP_HIGH] = VDD_GPU_DRA7_HIGH,
306 .gpu.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_GPU_NOM,
307 .gpu.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_GPU_OD,
308 .gpu.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_GPU_HIGH,
Keerthyd60198d2016-05-24 11:45:06 +0530309 .gpu.efuse.reg_bits = DRA752_EFUSE_REGBITS,
310 .gpu.addr = TPS659038_REG_ADDR_SMPS6,
311 .gpu.pmic = &tps659038,
312 .gpu.abb_tx_done_mask = OMAP_ABB_GPU_TXDONE_MASK,
313
Lokesh Vutlabeb71272016-11-23 12:54:39 +0530314 .core.value[OPP_NOM] = VDD_CORE_DRA7_NOM,
315 .core.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_CORE_NOM,
Keerthyd60198d2016-05-24 11:45:06 +0530316 .core.efuse.reg_bits = DRA752_EFUSE_REGBITS,
317 .core.addr = TPS659038_REG_ADDR_SMPS7,
318 .core.pmic = &tps659038,
319
Lokesh Vutlabeb71272016-11-23 12:54:39 +0530320 .iva.value[OPP_NOM] = VDD_IVA_DRA7_NOM,
321 .iva.value[OPP_OD] = VDD_IVA_DRA7_OD,
322 .iva.value[OPP_HIGH] = VDD_IVA_DRA7_HIGH,
323 .iva.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_IVA_NOM,
324 .iva.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_IVA_OD,
325 .iva.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_IVA_HIGH,
Keerthyd60198d2016-05-24 11:45:06 +0530326 .iva.efuse.reg_bits = DRA752_EFUSE_REGBITS,
327 .iva.addr = TPS659038_REG_ADDR_SMPS8,
328 .iva.pmic = &tps659038,
329 .iva.abb_tx_done_mask = OMAP_ABB_IVA_TXDONE_MASK,
330};
331
Lokesh Vutlabeb71272016-11-23 12:54:39 +0530332int get_voltrail_opp(int rail_offset)
333{
334 int opp;
335
336 switch (rail_offset) {
337 case VOLT_MPU:
338 opp = DRA7_MPU_OPP;
339 break;
340 case VOLT_CORE:
341 opp = DRA7_CORE_OPP;
342 break;
343 case VOLT_GPU:
344 opp = DRA7_GPU_OPP;
345 break;
346 case VOLT_EVE:
347 opp = DRA7_DSPEVE_OPP;
348 break;
349 case VOLT_IVA:
350 opp = DRA7_IVA_OPP;
351 break;
352 default:
353 opp = OPP_NOM;
354 }
355
356 return opp;
357}
358
359
Kipisz, Steven212f96f2016-02-24 12:30:58 -0600360#ifdef CONFIG_SPL_BUILD
361/* No env to setup for SPL */
362static inline void setup_board_eeprom_env(void) { }
363
364/* Override function to read eeprom information */
365void do_board_detect(void)
366{
367 int rc;
368
369 rc = ti_i2c_eeprom_am_get(CONFIG_EEPROM_BUS_ADDRESS,
370 CONFIG_EEPROM_CHIP_ADDRESS);
371 if (rc)
372 printf("ti_i2c_eeprom_init failed %d\n", rc);
373}
374
375#else /* CONFIG_SPL_BUILD */
376
377/* Override function to read eeprom information: actual i2c read done by SPL*/
378void do_board_detect(void)
379{
380 char *bname = NULL;
381 int rc;
382
383 rc = ti_i2c_eeprom_am_get(CONFIG_EEPROM_BUS_ADDRESS,
384 CONFIG_EEPROM_CHIP_ADDRESS);
385 if (rc)
386 printf("ti_i2c_eeprom_init failed %d\n", rc);
387
388 if (board_is_x15())
389 bname = "BeagleBoard X15";
390 else if (board_is_am572x_evm())
391 bname = "AM572x EVM";
Steve Kipiszc020d352016-04-08 17:01:29 -0500392 else if (board_is_am572x_idk())
393 bname = "AM572x IDK";
Steve Kipisz4d8397c2016-11-25 11:14:24 +0530394 else if (board_is_am571x_idk())
395 bname = "AM571x IDK";
Kipisz, Steven212f96f2016-02-24 12:30:58 -0600396
397 if (bname)
398 snprintf(sysinfo.board_string, SYSINFO_BOARD_NAME_MAX_LEN,
399 "Board: %s REV %s\n", bname, board_ti_get_rev());
400}
401
402static void setup_board_eeprom_env(void)
403{
404 char *name = "beagle_x15";
405 int rc;
406
407 rc = ti_i2c_eeprom_am_get(CONFIG_EEPROM_BUS_ADDRESS,
408 CONFIG_EEPROM_CHIP_ADDRESS);
409 if (rc)
410 goto invalid_eeprom;
411
Nishanth Menonbf43ce62016-11-25 11:14:19 +0530412 if (board_is_x15()) {
Lokesh Vutlaf7f9f6b2016-11-25 11:14:20 +0530413 if (board_is_x15_revb1())
414 name = "beagle_x15_revb1";
415 else
416 name = "beagle_x15";
Nishanth Menonbf43ce62016-11-25 11:14:19 +0530417 } else if (board_is_am572x_evm()) {
418 if (board_is_am572x_evm_reva3())
419 name = "am57xx_evm_reva3";
420 else
421 name = "am57xx_evm";
422 } else if (board_is_am572x_idk()) {
Steve Kipiszc020d352016-04-08 17:01:29 -0500423 name = "am572x_idk";
Steve Kipisz4d8397c2016-11-25 11:14:24 +0530424 } else if (board_is_am571x_idk()) {
425 name = "am571x_idk";
Nishanth Menonbf43ce62016-11-25 11:14:19 +0530426 } else {
Kipisz, Steven212f96f2016-02-24 12:30:58 -0600427 printf("Unidentified board claims %s in eeprom header\n",
428 board_ti_get_name());
Nishanth Menonbf43ce62016-11-25 11:14:19 +0530429 }
Kipisz, Steven212f96f2016-02-24 12:30:58 -0600430
431invalid_eeprom:
432 set_board_info_env(name);
433}
434
435#endif /* CONFIG_SPL_BUILD */
436
Keerthyd60198d2016-05-24 11:45:06 +0530437void vcores_init(void)
438{
439 if (board_is_am572x_idk())
440 *omap_vcores = &am572x_idk_volts;
441 else
442 *omap_vcores = &beagle_x15_volts;
443}
444
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600445void hw_data_init(void)
446{
447 *prcm = &dra7xx_prcm;
448 *dplls_data = &dra7xx_dplls;
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600449 *ctrl = &dra7xx_ctrl;
450}
451
452int board_init(void)
453{
454 gpmc_init();
455 gd->bd->bi_boot_params = (CONFIG_SYS_SDRAM_BASE + 0x100);
456
457 return 0;
458}
459
460int board_late_init(void)
461{
Kipisz, Steven212f96f2016-02-24 12:30:58 -0600462 setup_board_eeprom_env();
Keerthy385d3632016-11-30 15:02:53 +0530463 u8 val;
Kipisz, Steven212f96f2016-02-24 12:30:58 -0600464
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600465 /*
466 * DEV_CTRL.DEV_ON = 1 please - else palmas switches off in 8 seconds
467 * This is the POWERHOLD-in-Low behavior.
468 */
469 palmas_i2c_write_u8(TPS65903X_CHIP_P1, 0xA0, 0x1);
Lokesh Vutla82cca5a2016-11-29 11:58:02 +0530470
471 /*
472 * Default FIT boot on HS devices. Non FIT images are not allowed
473 * on HS devices.
474 */
475 if (get_device_type() == HS_DEVICE)
476 setenv("boot_fit", "1");
477
Keerthy385d3632016-11-30 15:02:53 +0530478 /*
479 * Set the GPIO7 Pad to POWERHOLD. This has higher priority
480 * over DEV_CTRL.DEV_ON bit. This can be reset in case of
481 * PMIC Power off. So to be on the safer side set it back
482 * to POWERHOLD mode irrespective of the current state.
483 */
484 palmas_i2c_read_u8(TPS65903X_CHIP_P1, TPS65903X_PRIMARY_SECONDARY_PAD2,
485 &val);
486 val = val | TPS65903X_PAD2_POWERHOLD_MASK;
487 palmas_i2c_write_u8(TPS65903X_CHIP_P1, TPS65903X_PRIMARY_SECONDARY_PAD2,
488 val);
489
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600490 return 0;
491}
492
Paul Kocialkowski3ef56e62016-02-27 19:18:56 +0100493void set_muxconf_regs(void)
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600494{
495 do_set_mux32((*ctrl)->control_padconf_core_base,
Lokesh Vutlaf91e0c42015-06-04 16:42:41 +0530496 early_padconf, ARRAY_SIZE(early_padconf));
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600497}
498
Lokesh Vutlaf91e0c42015-06-04 16:42:41 +0530499#ifdef CONFIG_IODELAY_RECALIBRATION
500void recalibrate_iodelay(void)
501{
Steve Kipiszc020d352016-04-08 17:01:29 -0500502 const struct pad_conf_entry *pconf;
503 const struct iodelay_cfg_entry *iod;
504 int pconf_sz, iod_sz;
Nishanth Menon89a38952016-11-25 11:14:22 +0530505 int ret;
Steve Kipiszc020d352016-04-08 17:01:29 -0500506
507 if (board_is_am572x_idk()) {
508 pconf = core_padconf_array_essential_am572x_idk;
509 pconf_sz = ARRAY_SIZE(core_padconf_array_essential_am572x_idk);
510 iod = iodelay_cfg_array_am572x_idk;
511 iod_sz = ARRAY_SIZE(iodelay_cfg_array_am572x_idk);
Steve Kipisz4d8397c2016-11-25 11:14:24 +0530512 } else if (board_is_am571x_idk()) {
513 pconf = core_padconf_array_essential_am571x_idk;
514 pconf_sz = ARRAY_SIZE(core_padconf_array_essential_am571x_idk);
515 iod = iodelay_cfg_array_am571x_idk;
516 iod_sz = ARRAY_SIZE(iodelay_cfg_array_am571x_idk);
Steve Kipiszc020d352016-04-08 17:01:29 -0500517 } else {
518 /* Common for X15/GPEVM */
519 pconf = core_padconf_array_essential_x15;
520 pconf_sz = ARRAY_SIZE(core_padconf_array_essential_x15);
Nishanth Menon89a38952016-11-25 11:14:22 +0530521 /* There never was an SR1.0 X15.. So.. */
522 if (omap_revision() == DRA752_ES1_1) {
523 iod = iodelay_cfg_array_x15_sr1_1;
524 iod_sz = ARRAY_SIZE(iodelay_cfg_array_x15_sr1_1);
525 } else {
526 /* Since full production should switch to SR2.0 */
527 iod = iodelay_cfg_array_x15_sr2_0;
528 iod_sz = ARRAY_SIZE(iodelay_cfg_array_x15_sr2_0);
529 }
Steve Kipiszc020d352016-04-08 17:01:29 -0500530 }
531
Nishanth Menon89a38952016-11-25 11:14:22 +0530532 /* Setup I/O isolation */
533 ret = __recalibrate_iodelay_start();
534 if (ret)
535 goto err;
536
537 /* Do the muxing here */
538 do_set_mux32((*ctrl)->control_padconf_core_base, pconf, pconf_sz);
539
540 /* Now do the weird minor deltas that should be safe */
541 if (board_is_x15() || board_is_am572x_evm()) {
542 if (board_is_x15_revb1() || board_is_am572x_evm_reva3()) {
543 pconf = core_padconf_array_delta_x15_sr2_0;
544 pconf_sz = ARRAY_SIZE(core_padconf_array_delta_x15_sr2_0);
545 } else {
546 pconf = core_padconf_array_delta_x15_sr1_1;
547 pconf_sz = ARRAY_SIZE(core_padconf_array_delta_x15_sr1_1);
548 }
549 do_set_mux32((*ctrl)->control_padconf_core_base, pconf, pconf_sz);
550 }
551
552 /* Setup IOdelay configuration */
553 ret = do_set_iodelay((*ctrl)->iodelay_config_base, iod, iod_sz);
554err:
555 /* Closeup.. remove isolation */
556 __recalibrate_iodelay_end(ret);
Lokesh Vutlaf91e0c42015-06-04 16:42:41 +0530557}
558#endif
559
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600560#if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_GENERIC_MMC)
561int board_mmc_init(bd_t *bis)
562{
563 omap_mmc_init(0, 0, 0, -1, -1);
564 omap_mmc_init(1, 0, 0, -1, -1);
565 return 0;
566}
567#endif
568
569#if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_OS_BOOT)
570int spl_start_uboot(void)
571{
572 /* break into full u-boot on 'c' */
573 if (serial_tstc() && serial_getc() == 'c')
574 return 1;
575
576#ifdef CONFIG_SPL_ENV_SUPPORT
577 env_init();
578 env_relocate_spec();
579 if (getenv_yesno("boot_os") != 1)
580 return 1;
581#endif
582
583 return 0;
584}
585#endif
586
Kishon Vijay Abraham I7c379aa2015-08-19 14:13:19 +0530587#ifdef CONFIG_USB_DWC3
Kishon Vijay Abraham I7c379aa2015-08-19 14:13:19 +0530588static struct dwc3_device usb_otg_ss2 = {
589 .maximum_speed = USB_SPEED_HIGH,
590 .base = DRA7_USB_OTG_SS2_BASE,
591 .tx_fifo_resize = false,
592 .index = 1,
593};
594
595static struct dwc3_omap_device usb_otg_ss2_glue = {
596 .base = (void *)DRA7_USB_OTG_SS2_GLUE_BASE,
597 .utmi_mode = DWC3_OMAP_UTMI_MODE_SW,
598 .index = 1,
599};
600
601static struct ti_usb_phy_device usb_phy2_device = {
602 .usb2_phy_power = (void *)DRA7_USB2_PHY2_POWER,
603 .index = 1,
604};
605
Kishon Vijay Abraham I7c379aa2015-08-19 14:13:19 +0530606int usb_gadget_handle_interrupts(int index)
607{
608 u32 status;
609
610 status = dwc3_omap_uboot_interrupt_status(index);
611 if (status)
612 dwc3_uboot_handle_interrupt(index);
613
614 return 0;
615}
Roger Quadros55efadd2016-05-23 17:37:48 +0300616#endif /* CONFIG_USB_DWC3 */
617
618#if defined(CONFIG_USB_DWC3) || defined(CONFIG_USB_XHCI_OMAP)
619int board_usb_init(int index, enum usb_init_type init)
620{
621 enable_usb_clocks(index);
622 switch (index) {
623 case 0:
624 if (init == USB_INIT_DEVICE) {
625 printf("port %d can't be used as device\n", index);
626 disable_usb_clocks(index);
627 return -EINVAL;
628 }
629 break;
630 case 1:
631 if (init == USB_INIT_DEVICE) {
632#ifdef CONFIG_USB_DWC3
633 usb_otg_ss2.dr_mode = USB_DR_MODE_PERIPHERAL;
634 usb_otg_ss2_glue.vbus_id_status = OMAP_DWC3_VBUS_VALID;
635 ti_usb_phy_uboot_init(&usb_phy2_device);
636 dwc3_omap_uboot_init(&usb_otg_ss2_glue);
637 dwc3_uboot_init(&usb_otg_ss2);
Kishon Vijay Abraham I7c379aa2015-08-19 14:13:19 +0530638#endif
Roger Quadros55efadd2016-05-23 17:37:48 +0300639 } else {
640 printf("port %d can't be used as host\n", index);
641 disable_usb_clocks(index);
642 return -EINVAL;
643 }
644
645 break;
646 default:
647 printf("Invalid Controller Index\n");
648 }
649
650 return 0;
651}
652
653int board_usb_cleanup(int index, enum usb_init_type init)
654{
655#ifdef CONFIG_USB_DWC3
656 switch (index) {
657 case 0:
658 case 1:
659 if (init == USB_INIT_DEVICE) {
660 ti_usb_phy_uboot_exit(index);
661 dwc3_uboot_exit(index);
662 dwc3_omap_uboot_exit(index);
663 }
664 break;
665 default:
666 printf("Invalid Controller Index\n");
667 }
668#endif
669 disable_usb_clocks(index);
670 return 0;
671}
672#endif /* defined(CONFIG_USB_DWC3) || defined(CONFIG_USB_XHCI_OMAP) */
Kishon Vijay Abraham I7c379aa2015-08-19 14:13:19 +0530673
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600674#ifdef CONFIG_DRIVER_TI_CPSW
675
676/* Delay value to add to calibrated value */
677#define RGMII0_TXCTL_DLY_VAL ((0x3 << 5) + 0x8)
678#define RGMII0_TXD0_DLY_VAL ((0x3 << 5) + 0x8)
679#define RGMII0_TXD1_DLY_VAL ((0x3 << 5) + 0x2)
680#define RGMII0_TXD2_DLY_VAL ((0x4 << 5) + 0x0)
681#define RGMII0_TXD3_DLY_VAL ((0x4 << 5) + 0x0)
682#define VIN2A_D13_DLY_VAL ((0x3 << 5) + 0x8)
683#define VIN2A_D17_DLY_VAL ((0x3 << 5) + 0x8)
684#define VIN2A_D16_DLY_VAL ((0x3 << 5) + 0x2)
685#define VIN2A_D15_DLY_VAL ((0x4 << 5) + 0x0)
686#define VIN2A_D14_DLY_VAL ((0x4 << 5) + 0x0)
687
688static void cpsw_control(int enabled)
689{
690 /* VTP can be added here */
691}
692
693static struct cpsw_slave_data cpsw_slaves[] = {
694 {
695 .slave_reg_ofs = 0x208,
696 .sliver_reg_ofs = 0xd80,
697 .phy_addr = 1,
698 },
699 {
700 .slave_reg_ofs = 0x308,
701 .sliver_reg_ofs = 0xdc0,
702 .phy_addr = 2,
703 },
704};
705
706static struct cpsw_platform_data cpsw_data = {
707 .mdio_base = CPSW_MDIO_BASE,
708 .cpsw_base = CPSW_BASE,
709 .mdio_div = 0xff,
710 .channels = 8,
711 .cpdma_reg_ofs = 0x800,
712 .slaves = 1,
713 .slave_data = cpsw_slaves,
714 .ale_reg_ofs = 0xd00,
715 .ale_entries = 1024,
716 .host_port_reg_ofs = 0x108,
717 .hw_stats_reg_ofs = 0x900,
718 .bd_ram_ofs = 0x2000,
719 .mac_control = (1 << 5),
720 .control = cpsw_control,
721 .host_port_num = 0,
722 .version = CPSW_CTRL_VERSION_2,
723};
724
Roger Quadros92667e82016-03-18 13:18:12 +0200725static u64 mac_to_u64(u8 mac[6])
726{
727 int i;
728 u64 addr = 0;
729
730 for (i = 0; i < 6; i++) {
731 addr <<= 8;
732 addr |= mac[i];
733 }
734
735 return addr;
736}
737
738static void u64_to_mac(u64 addr, u8 mac[6])
739{
740 mac[5] = addr;
741 mac[4] = addr >> 8;
742 mac[3] = addr >> 16;
743 mac[2] = addr >> 24;
744 mac[1] = addr >> 32;
745 mac[0] = addr >> 40;
746}
747
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600748int board_eth_init(bd_t *bis)
749{
750 int ret;
751 uint8_t mac_addr[6];
752 uint32_t mac_hi, mac_lo;
753 uint32_t ctrl_val;
Roger Quadros92667e82016-03-18 13:18:12 +0200754 int i;
755 u64 mac1, mac2;
756 u8 mac_addr1[6], mac_addr2[6];
757 int num_macs;
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600758
759 /* try reading mac address from efuse */
760 mac_lo = readl((*ctrl)->control_core_mac_id_0_lo);
761 mac_hi = readl((*ctrl)->control_core_mac_id_0_hi);
762 mac_addr[0] = (mac_hi & 0xFF0000) >> 16;
763 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
764 mac_addr[2] = mac_hi & 0xFF;
765 mac_addr[3] = (mac_lo & 0xFF0000) >> 16;
766 mac_addr[4] = (mac_lo & 0xFF00) >> 8;
767 mac_addr[5] = mac_lo & 0xFF;
768
769 if (!getenv("ethaddr")) {
770 printf("<ethaddr> not set. Validating first E-fuse MAC\n");
771
Joe Hershberger0adb5b72015-04-08 01:41:04 -0500772 if (is_valid_ethaddr(mac_addr))
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600773 eth_setenv_enetaddr("ethaddr", mac_addr);
774 }
775
776 mac_lo = readl((*ctrl)->control_core_mac_id_1_lo);
777 mac_hi = readl((*ctrl)->control_core_mac_id_1_hi);
778 mac_addr[0] = (mac_hi & 0xFF0000) >> 16;
779 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
780 mac_addr[2] = mac_hi & 0xFF;
781 mac_addr[3] = (mac_lo & 0xFF0000) >> 16;
782 mac_addr[4] = (mac_lo & 0xFF00) >> 8;
783 mac_addr[5] = mac_lo & 0xFF;
784
785 if (!getenv("eth1addr")) {
Joe Hershberger0adb5b72015-04-08 01:41:04 -0500786 if (is_valid_ethaddr(mac_addr))
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600787 eth_setenv_enetaddr("eth1addr", mac_addr);
788 }
789
790 ctrl_val = readl((*ctrl)->control_core_control_io1) & (~0x33);
791 ctrl_val |= 0x22;
792 writel(ctrl_val, (*ctrl)->control_core_control_io1);
793
Steve Kipisz4d8397c2016-11-25 11:14:24 +0530794 /* The phy address for the AM57xx IDK are different than x15 */
795 if (board_is_am572x_idk() || board_is_am571x_idk()) {
Steve Kipiszc020d352016-04-08 17:01:29 -0500796 cpsw_data.slave_data[0].phy_addr = 0;
797 cpsw_data.slave_data[1].phy_addr = 1;
798 }
799
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600800 ret = cpsw_register(&cpsw_data);
801 if (ret < 0)
802 printf("Error %d registering CPSW switch\n", ret);
803
Roger Quadros92667e82016-03-18 13:18:12 +0200804 /*
805 * Export any Ethernet MAC addresses from EEPROM.
806 * On AM57xx the 2 MAC addresses define the address range
807 */
808 board_ti_get_eth_mac_addr(0, mac_addr1);
809 board_ti_get_eth_mac_addr(1, mac_addr2);
810
811 if (is_valid_ethaddr(mac_addr1) && is_valid_ethaddr(mac_addr2)) {
812 mac1 = mac_to_u64(mac_addr1);
813 mac2 = mac_to_u64(mac_addr2);
814
815 /* must contain an address range */
816 num_macs = mac2 - mac1 + 1;
817 /* <= 50 to protect against user programming error */
818 if (num_macs > 0 && num_macs <= 50) {
819 for (i = 0; i < num_macs; i++) {
820 u64_to_mac(mac1 + i, mac_addr);
821 if (is_valid_ethaddr(mac_addr)) {
822 eth_setenv_enetaddr_by_index("eth",
823 i + 2,
824 mac_addr);
825 }
826 }
827 }
828 }
829
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600830 return ret;
831}
832#endif
Lokesh Vutla334bbb32015-06-16 20:36:05 +0530833
834#ifdef CONFIG_BOARD_EARLY_INIT_F
835/* VTT regulator enable */
836static inline void vtt_regulator_enable(void)
837{
838 if (omap_hw_init_context() == OMAP_INIT_CONTEXT_UBOOT_AFTER_SPL)
839 return;
840
841 gpio_request(GPIO_DDR_VTT_EN, "ddr_vtt_en");
842 gpio_direction_output(GPIO_DDR_VTT_EN, 1);
843}
844
845int board_early_init_f(void)
846{
847 vtt_regulator_enable();
848 return 0;
849}
850#endif
Daniel Allred62a09f02016-05-19 19:10:54 -0500851
852#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
853int ft_board_setup(void *blob, bd_t *bd)
854{
855 ft_cpu_setup(blob, bd);
856
857 return 0;
858}
859#endif
Lokesh Vutla7a0ea582016-06-10 09:35:43 +0530860
861#ifdef CONFIG_SPL_LOAD_FIT
862int board_fit_config_name_match(const char *name)
863{
Lokesh Vutlaf7f9f6b2016-11-25 11:14:20 +0530864 if (board_is_x15()) {
865 if (board_is_x15_revb1()) {
866 if (!strcmp(name, "am57xx-beagle-x15-revb1"))
867 return 0;
868 } else if (!strcmp(name, "am57xx-beagle-x15")) {
869 return 0;
870 }
871 } else if (board_is_am572x_evm() &&
872 !strcmp(name, "am57xx-beagle-x15")) {
Lokesh Vutla7a0ea582016-06-10 09:35:43 +0530873 return 0;
Lokesh Vutlaf7f9f6b2016-11-25 11:14:20 +0530874 } else if (board_is_am572x_idk() && !strcmp(name, "am572x-idk")) {
Lokesh Vutla7a0ea582016-06-10 09:35:43 +0530875 return 0;
Schuyler Patton45e7f7e2016-11-25 11:14:25 +0530876 } else if (board_is_am571x_idk() && !strcmp(name, "am571x-idk")) {
877 return 0;
Lokesh Vutlaf7f9f6b2016-11-25 11:14:20 +0530878 }
879
880 return -1;
Lokesh Vutla7a0ea582016-06-10 09:35:43 +0530881}
882#endif
Andreas Dannenberg17c29872016-06-27 09:19:22 -0500883
884#ifdef CONFIG_TI_SECURE_DEVICE
885void board_fit_image_post_process(void **p_image, size_t *p_size)
886{
887 secure_boot_verify_image(p_image, p_size);
888}
Andrew F. Davis1b597ad2016-11-29 16:33:26 -0600889
890void board_tee_image_process(ulong tee_image, size_t tee_size)
891{
892 secure_tee_install((u32)tee_image);
893}
894
895U_BOOT_FIT_LOADABLE_HANDLER(IH_TYPE_TEE, board_tee_image_process);
Andreas Dannenberg17c29872016-06-27 09:19:22 -0500896#endif