blob: 797d7a4c0c200f571b25af5a44f4406672fbd8ab [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
Felipe Balbi1e4ad742014-11-10 14:02:44 -060058const struct omap_sysinfo sysinfo = {
Kipisz, Steven212f96f2016-02-24 12:30:58 -060059 "Board: UNKNOWN(BeagleBoard X15?) REV UNKNOWN\n"
Felipe Balbi1e4ad742014-11-10 14:02:44 -060060};
61
62static const struct dmm_lisa_map_regs beagle_x15_lisa_regs = {
63 .dmm_lisa_map_3 = 0x80740300,
64 .is_ma_present = 0x1
65};
66
Steve Kipisz4d8397c2016-11-25 11:14:24 +053067static const struct dmm_lisa_map_regs am571x_idk_lisa_regs = {
68 .dmm_lisa_map_3 = 0x80640100,
69 .is_ma_present = 0x1
70};
71
Felipe Balbi1e4ad742014-11-10 14:02:44 -060072void emif_get_dmm_regs(const struct dmm_lisa_map_regs **dmm_lisa_regs)
73{
Steve Kipisz4d8397c2016-11-25 11:14:24 +053074 if (board_is_am571x_idk())
75 *dmm_lisa_regs = &am571x_idk_lisa_regs;
76 else
77 *dmm_lisa_regs = &beagle_x15_lisa_regs;
Felipe Balbi1e4ad742014-11-10 14:02:44 -060078}
79
80static const struct emif_regs beagle_x15_emif1_ddr3_532mhz_emif_regs = {
Keerthyeafd4642016-05-24 11:45:07 +053081 .sdram_config_init = 0x61851b32,
82 .sdram_config = 0x61851b32,
83 .sdram_config2 = 0x08000000,
84 .ref_ctrl = 0x000040F1,
85 .ref_ctrl_final = 0x00001035,
86 .sdram_tim1 = 0xcccf36ab,
87 .sdram_tim2 = 0x308f7fda,
88 .sdram_tim3 = 0x409f88a8,
89 .read_idle_ctrl = 0x00050000,
90 .zq_config = 0x5007190b,
91 .temp_alert_config = 0x00000000,
92 .emif_ddr_phy_ctlr_1_init = 0x0024400b,
93 .emif_ddr_phy_ctlr_1 = 0x0e24400b,
94 .emif_ddr_ext_phy_ctrl_1 = 0x10040100,
95 .emif_ddr_ext_phy_ctrl_2 = 0x00910091,
96 .emif_ddr_ext_phy_ctrl_3 = 0x00950095,
97 .emif_ddr_ext_phy_ctrl_4 = 0x009b009b,
98 .emif_ddr_ext_phy_ctrl_5 = 0x009e009e,
99 .emif_rd_wr_lvl_rmp_win = 0x00000000,
100 .emif_rd_wr_lvl_rmp_ctl = 0x80000000,
101 .emif_rd_wr_lvl_ctl = 0x00000000,
102 .emif_rd_wr_exec_thresh = 0x00000305
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600103};
104
Lokesh Vutla6213db72015-06-03 14:43:21 +0530105/* Ext phy ctrl regs 1-35 */
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600106static const u32 beagle_x15_emif1_ddr3_ext_phy_ctrl_const_regs[] = {
Lokesh Vutla6213db72015-06-03 14:43:21 +0530107 0x10040100,
Lokesh Vutla11e2b042016-03-08 09:11:35 +0530108 0x00910091,
109 0x00950095,
110 0x009B009B,
111 0x009E009E,
112 0x00980098,
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600113 0x00340034,
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600114 0x00350035,
Lokesh Vutla11e2b042016-03-08 09:11:35 +0530115 0x00340034,
116 0x00310031,
117 0x00340034,
118 0x007F007F,
119 0x007F007F,
120 0x007F007F,
121 0x007F007F,
122 0x007F007F,
123 0x00480048,
124 0x004A004A,
125 0x00520052,
126 0x00550055,
127 0x00500050,
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600128 0x00000000,
129 0x00600020,
Lokesh Vutla6213db72015-06-03 14:43:21 +0530130 0x40011080,
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600131 0x08102040,
Lokesh Vutla11e2b042016-03-08 09:11:35 +0530132 0x0,
133 0x0,
134 0x0,
135 0x0,
136 0x0,
Lokesh Vutla496edff2015-06-03 14:43:22 +0530137 0x0,
138 0x0,
139 0x0,
140 0x0,
141 0x0
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600142};
143
144static const struct emif_regs beagle_x15_emif2_ddr3_532mhz_emif_regs = {
Keerthyeafd4642016-05-24 11:45:07 +0530145 .sdram_config_init = 0x61851b32,
146 .sdram_config = 0x61851b32,
147 .sdram_config2 = 0x08000000,
148 .ref_ctrl = 0x000040F1,
149 .ref_ctrl_final = 0x00001035,
150 .sdram_tim1 = 0xcccf36b3,
151 .sdram_tim2 = 0x308f7fda,
152 .sdram_tim3 = 0x407f88a8,
153 .read_idle_ctrl = 0x00050000,
154 .zq_config = 0x5007190b,
155 .temp_alert_config = 0x00000000,
156 .emif_ddr_phy_ctlr_1_init = 0x0024400b,
157 .emif_ddr_phy_ctlr_1 = 0x0e24400b,
158 .emif_ddr_ext_phy_ctrl_1 = 0x10040100,
159 .emif_ddr_ext_phy_ctrl_2 = 0x00910091,
160 .emif_ddr_ext_phy_ctrl_3 = 0x00950095,
161 .emif_ddr_ext_phy_ctrl_4 = 0x009b009b,
162 .emif_ddr_ext_phy_ctrl_5 = 0x009e009e,
163 .emif_rd_wr_lvl_rmp_win = 0x00000000,
164 .emif_rd_wr_lvl_rmp_ctl = 0x80000000,
165 .emif_rd_wr_lvl_ctl = 0x00000000,
166 .emif_rd_wr_exec_thresh = 0x00000305
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600167};
168
169static const u32 beagle_x15_emif2_ddr3_ext_phy_ctrl_const_regs[] = {
Lokesh Vutla6213db72015-06-03 14:43:21 +0530170 0x10040100,
Lokesh Vutla11e2b042016-03-08 09:11:35 +0530171 0x00910091,
172 0x00950095,
173 0x009B009B,
174 0x009E009E,
175 0x00980098,
176 0x00340034,
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600177 0x00350035,
Lokesh Vutla11e2b042016-03-08 09:11:35 +0530178 0x00340034,
179 0x00310031,
180 0x00340034,
181 0x007F007F,
182 0x007F007F,
183 0x007F007F,
184 0x007F007F,
185 0x007F007F,
186 0x00480048,
187 0x004A004A,
188 0x00520052,
189 0x00550055,
190 0x00500050,
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600191 0x00000000,
192 0x00600020,
Lokesh Vutla6213db72015-06-03 14:43:21 +0530193 0x40011080,
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600194 0x08102040,
Lokesh Vutla11e2b042016-03-08 09:11:35 +0530195 0x0,
196 0x0,
197 0x0,
198 0x0,
199 0x0,
Lokesh Vutla496edff2015-06-03 14:43:22 +0530200 0x0,
201 0x0,
202 0x0,
203 0x0,
204 0x0
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600205};
206
207void emif_get_reg_dump(u32 emif_nr, const struct emif_regs **regs)
208{
209 switch (emif_nr) {
210 case 1:
211 *regs = &beagle_x15_emif1_ddr3_532mhz_emif_regs;
212 break;
213 case 2:
214 *regs = &beagle_x15_emif2_ddr3_532mhz_emif_regs;
215 break;
216 }
217}
218
219void emif_get_ext_phy_ctrl_const_regs(u32 emif_nr, const u32 **regs, u32 *size)
220{
221 switch (emif_nr) {
222 case 1:
223 *regs = beagle_x15_emif1_ddr3_ext_phy_ctrl_const_regs;
224 *size = ARRAY_SIZE(beagle_x15_emif1_ddr3_ext_phy_ctrl_const_regs);
225 break;
226 case 2:
227 *regs = beagle_x15_emif2_ddr3_ext_phy_ctrl_const_regs;
228 *size = ARRAY_SIZE(beagle_x15_emif2_ddr3_ext_phy_ctrl_const_regs);
229 break;
230 }
231}
232
233struct vcores_data beagle_x15_volts = {
Lokesh Vutlabeb71272016-11-23 12:54:39 +0530234 .mpu.value[OPP_NOM] = VDD_MPU_DRA7_NOM,
235 .mpu.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_MPU_NOM,
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600236 .mpu.efuse.reg_bits = DRA752_EFUSE_REGBITS,
237 .mpu.addr = TPS659038_REG_ADDR_SMPS12,
238 .mpu.pmic = &tps659038,
Keerthyeafd4642016-05-24 11:45:07 +0530239 .mpu.abb_tx_done_mask = OMAP_ABB_MPU_TXDONE_MASK,
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600240
Lokesh Vutlabeb71272016-11-23 12:54:39 +0530241 .eve.value[OPP_NOM] = VDD_EVE_DRA7_NOM,
242 .eve.value[OPP_OD] = VDD_EVE_DRA7_OD,
243 .eve.value[OPP_HIGH] = VDD_EVE_DRA7_HIGH,
244 .eve.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_DSPEVE_NOM,
245 .eve.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_DSPEVE_OD,
246 .eve.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_DSPEVE_HIGH,
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600247 .eve.efuse.reg_bits = DRA752_EFUSE_REGBITS,
248 .eve.addr = TPS659038_REG_ADDR_SMPS45,
249 .eve.pmic = &tps659038,
Nishanth Menone52e3342016-04-21 14:34:25 -0500250 .eve.abb_tx_done_mask = OMAP_ABB_EVE_TXDONE_MASK,
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600251
Lokesh Vutlabeb71272016-11-23 12:54:39 +0530252 .gpu.value[OPP_NOM] = VDD_GPU_DRA7_NOM,
253 .gpu.value[OPP_OD] = VDD_GPU_DRA7_OD,
254 .gpu.value[OPP_HIGH] = VDD_GPU_DRA7_HIGH,
255 .gpu.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_GPU_NOM,
256 .gpu.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_GPU_OD,
257 .gpu.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_GPU_HIGH,
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600258 .gpu.efuse.reg_bits = DRA752_EFUSE_REGBITS,
259 .gpu.addr = TPS659038_REG_ADDR_SMPS45,
260 .gpu.pmic = &tps659038,
Nishanth Menone52e3342016-04-21 14:34:25 -0500261 .gpu.abb_tx_done_mask = OMAP_ABB_GPU_TXDONE_MASK,
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600262
Lokesh Vutlabeb71272016-11-23 12:54:39 +0530263 .core.value[OPP_NOM] = VDD_CORE_DRA7_NOM,
264 .core.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_CORE_NOM,
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600265 .core.efuse.reg_bits = DRA752_EFUSE_REGBITS,
266 .core.addr = TPS659038_REG_ADDR_SMPS6,
267 .core.pmic = &tps659038,
268
Lokesh Vutlabeb71272016-11-23 12:54:39 +0530269 .iva.value[OPP_NOM] = VDD_IVA_DRA7_NOM,
270 .iva.value[OPP_OD] = VDD_IVA_DRA7_OD,
271 .iva.value[OPP_HIGH] = VDD_IVA_DRA7_HIGH,
272 .iva.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_IVA_NOM,
273 .iva.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_IVA_OD,
274 .iva.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_IVA_HIGH,
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600275 .iva.efuse.reg_bits = DRA752_EFUSE_REGBITS,
276 .iva.addr = TPS659038_REG_ADDR_SMPS45,
277 .iva.pmic = &tps659038,
Nishanth Menone52e3342016-04-21 14:34:25 -0500278 .iva.abb_tx_done_mask = OMAP_ABB_IVA_TXDONE_MASK,
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600279};
280
Keerthyd60198d2016-05-24 11:45:06 +0530281struct vcores_data am572x_idk_volts = {
Lokesh Vutlabeb71272016-11-23 12:54:39 +0530282 .mpu.value[OPP_NOM] = VDD_MPU_DRA7_NOM,
283 .mpu.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_MPU_NOM,
Keerthyd60198d2016-05-24 11:45:06 +0530284 .mpu.efuse.reg_bits = DRA752_EFUSE_REGBITS,
285 .mpu.addr = TPS659038_REG_ADDR_SMPS12,
286 .mpu.pmic = &tps659038,
287 .mpu.abb_tx_done_mask = OMAP_ABB_MPU_TXDONE_MASK,
288
Lokesh Vutlabeb71272016-11-23 12:54:39 +0530289 .eve.value[OPP_NOM] = VDD_EVE_DRA7_NOM,
290 .eve.value[OPP_OD] = VDD_EVE_DRA7_OD,
291 .eve.value[OPP_HIGH] = VDD_EVE_DRA7_HIGH,
292 .eve.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_DSPEVE_NOM,
293 .eve.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_DSPEVE_OD,
294 .eve.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_DSPEVE_HIGH,
Keerthyd60198d2016-05-24 11:45:06 +0530295 .eve.efuse.reg_bits = DRA752_EFUSE_REGBITS,
296 .eve.addr = TPS659038_REG_ADDR_SMPS45,
297 .eve.pmic = &tps659038,
298 .eve.abb_tx_done_mask = OMAP_ABB_EVE_TXDONE_MASK,
299
Lokesh Vutlabeb71272016-11-23 12:54:39 +0530300 .gpu.value[OPP_NOM] = VDD_GPU_DRA7_NOM,
301 .gpu.value[OPP_OD] = VDD_GPU_DRA7_OD,
302 .gpu.value[OPP_HIGH] = VDD_GPU_DRA7_HIGH,
303 .gpu.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_GPU_NOM,
304 .gpu.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_GPU_OD,
305 .gpu.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_GPU_HIGH,
Keerthyd60198d2016-05-24 11:45:06 +0530306 .gpu.efuse.reg_bits = DRA752_EFUSE_REGBITS,
307 .gpu.addr = TPS659038_REG_ADDR_SMPS6,
308 .gpu.pmic = &tps659038,
309 .gpu.abb_tx_done_mask = OMAP_ABB_GPU_TXDONE_MASK,
310
Lokesh Vutlabeb71272016-11-23 12:54:39 +0530311 .core.value[OPP_NOM] = VDD_CORE_DRA7_NOM,
312 .core.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_CORE_NOM,
Keerthyd60198d2016-05-24 11:45:06 +0530313 .core.efuse.reg_bits = DRA752_EFUSE_REGBITS,
314 .core.addr = TPS659038_REG_ADDR_SMPS7,
315 .core.pmic = &tps659038,
316
Lokesh Vutlabeb71272016-11-23 12:54:39 +0530317 .iva.value[OPP_NOM] = VDD_IVA_DRA7_NOM,
318 .iva.value[OPP_OD] = VDD_IVA_DRA7_OD,
319 .iva.value[OPP_HIGH] = VDD_IVA_DRA7_HIGH,
320 .iva.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_IVA_NOM,
321 .iva.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_IVA_OD,
322 .iva.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_IVA_HIGH,
Keerthyd60198d2016-05-24 11:45:06 +0530323 .iva.efuse.reg_bits = DRA752_EFUSE_REGBITS,
324 .iva.addr = TPS659038_REG_ADDR_SMPS8,
325 .iva.pmic = &tps659038,
326 .iva.abb_tx_done_mask = OMAP_ABB_IVA_TXDONE_MASK,
327};
328
Lokesh Vutlabeb71272016-11-23 12:54:39 +0530329int get_voltrail_opp(int rail_offset)
330{
331 int opp;
332
333 switch (rail_offset) {
334 case VOLT_MPU:
335 opp = DRA7_MPU_OPP;
336 break;
337 case VOLT_CORE:
338 opp = DRA7_CORE_OPP;
339 break;
340 case VOLT_GPU:
341 opp = DRA7_GPU_OPP;
342 break;
343 case VOLT_EVE:
344 opp = DRA7_DSPEVE_OPP;
345 break;
346 case VOLT_IVA:
347 opp = DRA7_IVA_OPP;
348 break;
349 default:
350 opp = OPP_NOM;
351 }
352
353 return opp;
354}
355
356
Kipisz, Steven212f96f2016-02-24 12:30:58 -0600357#ifdef CONFIG_SPL_BUILD
358/* No env to setup for SPL */
359static inline void setup_board_eeprom_env(void) { }
360
361/* Override function to read eeprom information */
362void do_board_detect(void)
363{
364 int rc;
365
366 rc = ti_i2c_eeprom_am_get(CONFIG_EEPROM_BUS_ADDRESS,
367 CONFIG_EEPROM_CHIP_ADDRESS);
368 if (rc)
369 printf("ti_i2c_eeprom_init failed %d\n", rc);
370}
371
372#else /* CONFIG_SPL_BUILD */
373
374/* Override function to read eeprom information: actual i2c read done by SPL*/
375void do_board_detect(void)
376{
377 char *bname = NULL;
378 int rc;
379
380 rc = ti_i2c_eeprom_am_get(CONFIG_EEPROM_BUS_ADDRESS,
381 CONFIG_EEPROM_CHIP_ADDRESS);
382 if (rc)
383 printf("ti_i2c_eeprom_init failed %d\n", rc);
384
385 if (board_is_x15())
386 bname = "BeagleBoard X15";
387 else if (board_is_am572x_evm())
388 bname = "AM572x EVM";
Steve Kipiszc020d352016-04-08 17:01:29 -0500389 else if (board_is_am572x_idk())
390 bname = "AM572x IDK";
Steve Kipisz4d8397c2016-11-25 11:14:24 +0530391 else if (board_is_am571x_idk())
392 bname = "AM571x IDK";
Kipisz, Steven212f96f2016-02-24 12:30:58 -0600393
394 if (bname)
395 snprintf(sysinfo.board_string, SYSINFO_BOARD_NAME_MAX_LEN,
396 "Board: %s REV %s\n", bname, board_ti_get_rev());
397}
398
399static void setup_board_eeprom_env(void)
400{
401 char *name = "beagle_x15";
402 int rc;
403
404 rc = ti_i2c_eeprom_am_get(CONFIG_EEPROM_BUS_ADDRESS,
405 CONFIG_EEPROM_CHIP_ADDRESS);
406 if (rc)
407 goto invalid_eeprom;
408
Nishanth Menonbf43ce62016-11-25 11:14:19 +0530409 if (board_is_x15()) {
Lokesh Vutlaf7f9f6b2016-11-25 11:14:20 +0530410 if (board_is_x15_revb1())
411 name = "beagle_x15_revb1";
412 else
413 name = "beagle_x15";
Nishanth Menonbf43ce62016-11-25 11:14:19 +0530414 } else if (board_is_am572x_evm()) {
415 if (board_is_am572x_evm_reva3())
416 name = "am57xx_evm_reva3";
417 else
418 name = "am57xx_evm";
419 } else if (board_is_am572x_idk()) {
Steve Kipiszc020d352016-04-08 17:01:29 -0500420 name = "am572x_idk";
Steve Kipisz4d8397c2016-11-25 11:14:24 +0530421 } else if (board_is_am571x_idk()) {
422 name = "am571x_idk";
Nishanth Menonbf43ce62016-11-25 11:14:19 +0530423 } else {
Kipisz, Steven212f96f2016-02-24 12:30:58 -0600424 printf("Unidentified board claims %s in eeprom header\n",
425 board_ti_get_name());
Nishanth Menonbf43ce62016-11-25 11:14:19 +0530426 }
Kipisz, Steven212f96f2016-02-24 12:30:58 -0600427
428invalid_eeprom:
429 set_board_info_env(name);
430}
431
432#endif /* CONFIG_SPL_BUILD */
433
Keerthyd60198d2016-05-24 11:45:06 +0530434void vcores_init(void)
435{
436 if (board_is_am572x_idk())
437 *omap_vcores = &am572x_idk_volts;
438 else
439 *omap_vcores = &beagle_x15_volts;
440}
441
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600442void hw_data_init(void)
443{
444 *prcm = &dra7xx_prcm;
445 *dplls_data = &dra7xx_dplls;
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600446 *ctrl = &dra7xx_ctrl;
447}
448
449int board_init(void)
450{
451 gpmc_init();
452 gd->bd->bi_boot_params = (CONFIG_SYS_SDRAM_BASE + 0x100);
453
454 return 0;
455}
456
457int board_late_init(void)
458{
Kipisz, Steven212f96f2016-02-24 12:30:58 -0600459 setup_board_eeprom_env();
460
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600461 /*
462 * DEV_CTRL.DEV_ON = 1 please - else palmas switches off in 8 seconds
463 * This is the POWERHOLD-in-Low behavior.
464 */
465 palmas_i2c_write_u8(TPS65903X_CHIP_P1, 0xA0, 0x1);
Lokesh Vutla82cca5a2016-11-29 11:58:02 +0530466
467 /*
468 * Default FIT boot on HS devices. Non FIT images are not allowed
469 * on HS devices.
470 */
471 if (get_device_type() == HS_DEVICE)
472 setenv("boot_fit", "1");
473
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600474 return 0;
475}
476
Paul Kocialkowski3ef56e62016-02-27 19:18:56 +0100477void set_muxconf_regs(void)
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600478{
479 do_set_mux32((*ctrl)->control_padconf_core_base,
Lokesh Vutlaf91e0c42015-06-04 16:42:41 +0530480 early_padconf, ARRAY_SIZE(early_padconf));
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600481}
482
Lokesh Vutlaf91e0c42015-06-04 16:42:41 +0530483#ifdef CONFIG_IODELAY_RECALIBRATION
484void recalibrate_iodelay(void)
485{
Steve Kipiszc020d352016-04-08 17:01:29 -0500486 const struct pad_conf_entry *pconf;
487 const struct iodelay_cfg_entry *iod;
488 int pconf_sz, iod_sz;
Nishanth Menon89a38952016-11-25 11:14:22 +0530489 int ret;
Steve Kipiszc020d352016-04-08 17:01:29 -0500490
491 if (board_is_am572x_idk()) {
492 pconf = core_padconf_array_essential_am572x_idk;
493 pconf_sz = ARRAY_SIZE(core_padconf_array_essential_am572x_idk);
494 iod = iodelay_cfg_array_am572x_idk;
495 iod_sz = ARRAY_SIZE(iodelay_cfg_array_am572x_idk);
Steve Kipisz4d8397c2016-11-25 11:14:24 +0530496 } else if (board_is_am571x_idk()) {
497 pconf = core_padconf_array_essential_am571x_idk;
498 pconf_sz = ARRAY_SIZE(core_padconf_array_essential_am571x_idk);
499 iod = iodelay_cfg_array_am571x_idk;
500 iod_sz = ARRAY_SIZE(iodelay_cfg_array_am571x_idk);
Steve Kipiszc020d352016-04-08 17:01:29 -0500501 } else {
502 /* Common for X15/GPEVM */
503 pconf = core_padconf_array_essential_x15;
504 pconf_sz = ARRAY_SIZE(core_padconf_array_essential_x15);
Nishanth Menon89a38952016-11-25 11:14:22 +0530505 /* There never was an SR1.0 X15.. So.. */
506 if (omap_revision() == DRA752_ES1_1) {
507 iod = iodelay_cfg_array_x15_sr1_1;
508 iod_sz = ARRAY_SIZE(iodelay_cfg_array_x15_sr1_1);
509 } else {
510 /* Since full production should switch to SR2.0 */
511 iod = iodelay_cfg_array_x15_sr2_0;
512 iod_sz = ARRAY_SIZE(iodelay_cfg_array_x15_sr2_0);
513 }
Steve Kipiszc020d352016-04-08 17:01:29 -0500514 }
515
Nishanth Menon89a38952016-11-25 11:14:22 +0530516 /* Setup I/O isolation */
517 ret = __recalibrate_iodelay_start();
518 if (ret)
519 goto err;
520
521 /* Do the muxing here */
522 do_set_mux32((*ctrl)->control_padconf_core_base, pconf, pconf_sz);
523
524 /* Now do the weird minor deltas that should be safe */
525 if (board_is_x15() || board_is_am572x_evm()) {
526 if (board_is_x15_revb1() || board_is_am572x_evm_reva3()) {
527 pconf = core_padconf_array_delta_x15_sr2_0;
528 pconf_sz = ARRAY_SIZE(core_padconf_array_delta_x15_sr2_0);
529 } else {
530 pconf = core_padconf_array_delta_x15_sr1_1;
531 pconf_sz = ARRAY_SIZE(core_padconf_array_delta_x15_sr1_1);
532 }
533 do_set_mux32((*ctrl)->control_padconf_core_base, pconf, pconf_sz);
534 }
535
536 /* Setup IOdelay configuration */
537 ret = do_set_iodelay((*ctrl)->iodelay_config_base, iod, iod_sz);
538err:
539 /* Closeup.. remove isolation */
540 __recalibrate_iodelay_end(ret);
Lokesh Vutlaf91e0c42015-06-04 16:42:41 +0530541}
542#endif
543
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600544#if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_GENERIC_MMC)
545int board_mmc_init(bd_t *bis)
546{
547 omap_mmc_init(0, 0, 0, -1, -1);
548 omap_mmc_init(1, 0, 0, -1, -1);
549 return 0;
550}
551#endif
552
553#if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_OS_BOOT)
554int spl_start_uboot(void)
555{
556 /* break into full u-boot on 'c' */
557 if (serial_tstc() && serial_getc() == 'c')
558 return 1;
559
560#ifdef CONFIG_SPL_ENV_SUPPORT
561 env_init();
562 env_relocate_spec();
563 if (getenv_yesno("boot_os") != 1)
564 return 1;
565#endif
566
567 return 0;
568}
569#endif
570
Kishon Vijay Abraham I7c379aa2015-08-19 14:13:19 +0530571#ifdef CONFIG_USB_DWC3
Kishon Vijay Abraham I7c379aa2015-08-19 14:13:19 +0530572static struct dwc3_device usb_otg_ss2 = {
573 .maximum_speed = USB_SPEED_HIGH,
574 .base = DRA7_USB_OTG_SS2_BASE,
575 .tx_fifo_resize = false,
576 .index = 1,
577};
578
579static struct dwc3_omap_device usb_otg_ss2_glue = {
580 .base = (void *)DRA7_USB_OTG_SS2_GLUE_BASE,
581 .utmi_mode = DWC3_OMAP_UTMI_MODE_SW,
582 .index = 1,
583};
584
585static struct ti_usb_phy_device usb_phy2_device = {
586 .usb2_phy_power = (void *)DRA7_USB2_PHY2_POWER,
587 .index = 1,
588};
589
Kishon Vijay Abraham I7c379aa2015-08-19 14:13:19 +0530590int usb_gadget_handle_interrupts(int index)
591{
592 u32 status;
593
594 status = dwc3_omap_uboot_interrupt_status(index);
595 if (status)
596 dwc3_uboot_handle_interrupt(index);
597
598 return 0;
599}
Roger Quadros55efadd2016-05-23 17:37:48 +0300600#endif /* CONFIG_USB_DWC3 */
601
602#if defined(CONFIG_USB_DWC3) || defined(CONFIG_USB_XHCI_OMAP)
603int board_usb_init(int index, enum usb_init_type init)
604{
605 enable_usb_clocks(index);
606 switch (index) {
607 case 0:
608 if (init == USB_INIT_DEVICE) {
609 printf("port %d can't be used as device\n", index);
610 disable_usb_clocks(index);
611 return -EINVAL;
612 }
613 break;
614 case 1:
615 if (init == USB_INIT_DEVICE) {
616#ifdef CONFIG_USB_DWC3
617 usb_otg_ss2.dr_mode = USB_DR_MODE_PERIPHERAL;
618 usb_otg_ss2_glue.vbus_id_status = OMAP_DWC3_VBUS_VALID;
619 ti_usb_phy_uboot_init(&usb_phy2_device);
620 dwc3_omap_uboot_init(&usb_otg_ss2_glue);
621 dwc3_uboot_init(&usb_otg_ss2);
Kishon Vijay Abraham I7c379aa2015-08-19 14:13:19 +0530622#endif
Roger Quadros55efadd2016-05-23 17:37:48 +0300623 } else {
624 printf("port %d can't be used as host\n", index);
625 disable_usb_clocks(index);
626 return -EINVAL;
627 }
628
629 break;
630 default:
631 printf("Invalid Controller Index\n");
632 }
633
634 return 0;
635}
636
637int board_usb_cleanup(int index, enum usb_init_type init)
638{
639#ifdef CONFIG_USB_DWC3
640 switch (index) {
641 case 0:
642 case 1:
643 if (init == USB_INIT_DEVICE) {
644 ti_usb_phy_uboot_exit(index);
645 dwc3_uboot_exit(index);
646 dwc3_omap_uboot_exit(index);
647 }
648 break;
649 default:
650 printf("Invalid Controller Index\n");
651 }
652#endif
653 disable_usb_clocks(index);
654 return 0;
655}
656#endif /* defined(CONFIG_USB_DWC3) || defined(CONFIG_USB_XHCI_OMAP) */
Kishon Vijay Abraham I7c379aa2015-08-19 14:13:19 +0530657
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600658#ifdef CONFIG_DRIVER_TI_CPSW
659
660/* Delay value to add to calibrated value */
661#define RGMII0_TXCTL_DLY_VAL ((0x3 << 5) + 0x8)
662#define RGMII0_TXD0_DLY_VAL ((0x3 << 5) + 0x8)
663#define RGMII0_TXD1_DLY_VAL ((0x3 << 5) + 0x2)
664#define RGMII0_TXD2_DLY_VAL ((0x4 << 5) + 0x0)
665#define RGMII0_TXD3_DLY_VAL ((0x4 << 5) + 0x0)
666#define VIN2A_D13_DLY_VAL ((0x3 << 5) + 0x8)
667#define VIN2A_D17_DLY_VAL ((0x3 << 5) + 0x8)
668#define VIN2A_D16_DLY_VAL ((0x3 << 5) + 0x2)
669#define VIN2A_D15_DLY_VAL ((0x4 << 5) + 0x0)
670#define VIN2A_D14_DLY_VAL ((0x4 << 5) + 0x0)
671
672static void cpsw_control(int enabled)
673{
674 /* VTP can be added here */
675}
676
677static struct cpsw_slave_data cpsw_slaves[] = {
678 {
679 .slave_reg_ofs = 0x208,
680 .sliver_reg_ofs = 0xd80,
681 .phy_addr = 1,
682 },
683 {
684 .slave_reg_ofs = 0x308,
685 .sliver_reg_ofs = 0xdc0,
686 .phy_addr = 2,
687 },
688};
689
690static struct cpsw_platform_data cpsw_data = {
691 .mdio_base = CPSW_MDIO_BASE,
692 .cpsw_base = CPSW_BASE,
693 .mdio_div = 0xff,
694 .channels = 8,
695 .cpdma_reg_ofs = 0x800,
696 .slaves = 1,
697 .slave_data = cpsw_slaves,
698 .ale_reg_ofs = 0xd00,
699 .ale_entries = 1024,
700 .host_port_reg_ofs = 0x108,
701 .hw_stats_reg_ofs = 0x900,
702 .bd_ram_ofs = 0x2000,
703 .mac_control = (1 << 5),
704 .control = cpsw_control,
705 .host_port_num = 0,
706 .version = CPSW_CTRL_VERSION_2,
707};
708
Roger Quadros92667e82016-03-18 13:18:12 +0200709static u64 mac_to_u64(u8 mac[6])
710{
711 int i;
712 u64 addr = 0;
713
714 for (i = 0; i < 6; i++) {
715 addr <<= 8;
716 addr |= mac[i];
717 }
718
719 return addr;
720}
721
722static void u64_to_mac(u64 addr, u8 mac[6])
723{
724 mac[5] = addr;
725 mac[4] = addr >> 8;
726 mac[3] = addr >> 16;
727 mac[2] = addr >> 24;
728 mac[1] = addr >> 32;
729 mac[0] = addr >> 40;
730}
731
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600732int board_eth_init(bd_t *bis)
733{
734 int ret;
735 uint8_t mac_addr[6];
736 uint32_t mac_hi, mac_lo;
737 uint32_t ctrl_val;
Roger Quadros92667e82016-03-18 13:18:12 +0200738 int i;
739 u64 mac1, mac2;
740 u8 mac_addr1[6], mac_addr2[6];
741 int num_macs;
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600742
743 /* try reading mac address from efuse */
744 mac_lo = readl((*ctrl)->control_core_mac_id_0_lo);
745 mac_hi = readl((*ctrl)->control_core_mac_id_0_hi);
746 mac_addr[0] = (mac_hi & 0xFF0000) >> 16;
747 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
748 mac_addr[2] = mac_hi & 0xFF;
749 mac_addr[3] = (mac_lo & 0xFF0000) >> 16;
750 mac_addr[4] = (mac_lo & 0xFF00) >> 8;
751 mac_addr[5] = mac_lo & 0xFF;
752
753 if (!getenv("ethaddr")) {
754 printf("<ethaddr> not set. Validating first E-fuse MAC\n");
755
Joe Hershberger0adb5b72015-04-08 01:41:04 -0500756 if (is_valid_ethaddr(mac_addr))
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600757 eth_setenv_enetaddr("ethaddr", mac_addr);
758 }
759
760 mac_lo = readl((*ctrl)->control_core_mac_id_1_lo);
761 mac_hi = readl((*ctrl)->control_core_mac_id_1_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("eth1addr")) {
Joe Hershberger0adb5b72015-04-08 01:41:04 -0500770 if (is_valid_ethaddr(mac_addr))
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600771 eth_setenv_enetaddr("eth1addr", mac_addr);
772 }
773
774 ctrl_val = readl((*ctrl)->control_core_control_io1) & (~0x33);
775 ctrl_val |= 0x22;
776 writel(ctrl_val, (*ctrl)->control_core_control_io1);
777
Steve Kipisz4d8397c2016-11-25 11:14:24 +0530778 /* The phy address for the AM57xx IDK are different than x15 */
779 if (board_is_am572x_idk() || board_is_am571x_idk()) {
Steve Kipiszc020d352016-04-08 17:01:29 -0500780 cpsw_data.slave_data[0].phy_addr = 0;
781 cpsw_data.slave_data[1].phy_addr = 1;
782 }
783
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600784 ret = cpsw_register(&cpsw_data);
785 if (ret < 0)
786 printf("Error %d registering CPSW switch\n", ret);
787
Roger Quadros92667e82016-03-18 13:18:12 +0200788 /*
789 * Export any Ethernet MAC addresses from EEPROM.
790 * On AM57xx the 2 MAC addresses define the address range
791 */
792 board_ti_get_eth_mac_addr(0, mac_addr1);
793 board_ti_get_eth_mac_addr(1, mac_addr2);
794
795 if (is_valid_ethaddr(mac_addr1) && is_valid_ethaddr(mac_addr2)) {
796 mac1 = mac_to_u64(mac_addr1);
797 mac2 = mac_to_u64(mac_addr2);
798
799 /* must contain an address range */
800 num_macs = mac2 - mac1 + 1;
801 /* <= 50 to protect against user programming error */
802 if (num_macs > 0 && num_macs <= 50) {
803 for (i = 0; i < num_macs; i++) {
804 u64_to_mac(mac1 + i, mac_addr);
805 if (is_valid_ethaddr(mac_addr)) {
806 eth_setenv_enetaddr_by_index("eth",
807 i + 2,
808 mac_addr);
809 }
810 }
811 }
812 }
813
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600814 return ret;
815}
816#endif
Lokesh Vutla334bbb32015-06-16 20:36:05 +0530817
818#ifdef CONFIG_BOARD_EARLY_INIT_F
819/* VTT regulator enable */
820static inline void vtt_regulator_enable(void)
821{
822 if (omap_hw_init_context() == OMAP_INIT_CONTEXT_UBOOT_AFTER_SPL)
823 return;
824
825 gpio_request(GPIO_DDR_VTT_EN, "ddr_vtt_en");
826 gpio_direction_output(GPIO_DDR_VTT_EN, 1);
827}
828
829int board_early_init_f(void)
830{
831 vtt_regulator_enable();
832 return 0;
833}
834#endif
Daniel Allred62a09f02016-05-19 19:10:54 -0500835
836#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
837int ft_board_setup(void *blob, bd_t *bd)
838{
839 ft_cpu_setup(blob, bd);
840
841 return 0;
842}
843#endif
Lokesh Vutla7a0ea582016-06-10 09:35:43 +0530844
845#ifdef CONFIG_SPL_LOAD_FIT
846int board_fit_config_name_match(const char *name)
847{
Lokesh Vutlaf7f9f6b2016-11-25 11:14:20 +0530848 if (board_is_x15()) {
849 if (board_is_x15_revb1()) {
850 if (!strcmp(name, "am57xx-beagle-x15-revb1"))
851 return 0;
852 } else if (!strcmp(name, "am57xx-beagle-x15")) {
853 return 0;
854 }
855 } else if (board_is_am572x_evm() &&
856 !strcmp(name, "am57xx-beagle-x15")) {
Lokesh Vutla7a0ea582016-06-10 09:35:43 +0530857 return 0;
Lokesh Vutlaf7f9f6b2016-11-25 11:14:20 +0530858 } else if (board_is_am572x_idk() && !strcmp(name, "am572x-idk")) {
Lokesh Vutla7a0ea582016-06-10 09:35:43 +0530859 return 0;
Schuyler Patton45e7f7e2016-11-25 11:14:25 +0530860 } else if (board_is_am571x_idk() && !strcmp(name, "am571x-idk")) {
861 return 0;
Lokesh Vutlaf7f9f6b2016-11-25 11:14:20 +0530862 }
863
864 return -1;
Lokesh Vutla7a0ea582016-06-10 09:35:43 +0530865}
866#endif
Andreas Dannenberg17c29872016-06-27 09:19:22 -0500867
868#ifdef CONFIG_TI_SECURE_DEVICE
869void board_fit_image_post_process(void **p_image, size_t *p_size)
870{
871 secure_boot_verify_image(p_image, p_size);
872}
Andrew F. Davis1b597ad2016-11-29 16:33:26 -0600873
874void board_tee_image_process(ulong tee_image, size_t tee_size)
875{
876 secure_tee_install((u32)tee_image);
877}
878
879U_BOOT_FIT_LOADABLE_HANDLER(IH_TYPE_TEE, board_tee_image_process);
Andreas Dannenberg17c29872016-06-27 09:19:22 -0500880#endif