blob: 5e3bcff738a333a93520c30dfd4b52253daa5490 [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")
Kipisz, Steven212f96f2016-02-24 12:30:58 -060045
Felipe Balbi1e4ad742014-11-10 14:02:44 -060046#ifdef CONFIG_DRIVER_TI_CPSW
47#include <cpsw.h>
48#endif
49
50DECLARE_GLOBAL_DATA_PTR;
51
Lokesh Vutla334bbb32015-06-16 20:36:05 +053052/* GPIO 7_11 */
53#define GPIO_DDR_VTT_EN 203
54
Kipisz, Steven212f96f2016-02-24 12:30:58 -060055#define SYSINFO_BOARD_NAME_MAX_LEN 45
56
Felipe Balbi1e4ad742014-11-10 14:02:44 -060057const struct omap_sysinfo sysinfo = {
Kipisz, Steven212f96f2016-02-24 12:30:58 -060058 "Board: UNKNOWN(BeagleBoard X15?) REV UNKNOWN\n"
Felipe Balbi1e4ad742014-11-10 14:02:44 -060059};
60
61static const struct dmm_lisa_map_regs beagle_x15_lisa_regs = {
62 .dmm_lisa_map_3 = 0x80740300,
63 .is_ma_present = 0x1
64};
65
66void emif_get_dmm_regs(const struct dmm_lisa_map_regs **dmm_lisa_regs)
67{
68 *dmm_lisa_regs = &beagle_x15_lisa_regs;
69}
70
71static const struct emif_regs beagle_x15_emif1_ddr3_532mhz_emif_regs = {
Keerthyeafd4642016-05-24 11:45:07 +053072 .sdram_config_init = 0x61851b32,
73 .sdram_config = 0x61851b32,
74 .sdram_config2 = 0x08000000,
75 .ref_ctrl = 0x000040F1,
76 .ref_ctrl_final = 0x00001035,
77 .sdram_tim1 = 0xcccf36ab,
78 .sdram_tim2 = 0x308f7fda,
79 .sdram_tim3 = 0x409f88a8,
80 .read_idle_ctrl = 0x00050000,
81 .zq_config = 0x5007190b,
82 .temp_alert_config = 0x00000000,
83 .emif_ddr_phy_ctlr_1_init = 0x0024400b,
84 .emif_ddr_phy_ctlr_1 = 0x0e24400b,
85 .emif_ddr_ext_phy_ctrl_1 = 0x10040100,
86 .emif_ddr_ext_phy_ctrl_2 = 0x00910091,
87 .emif_ddr_ext_phy_ctrl_3 = 0x00950095,
88 .emif_ddr_ext_phy_ctrl_4 = 0x009b009b,
89 .emif_ddr_ext_phy_ctrl_5 = 0x009e009e,
90 .emif_rd_wr_lvl_rmp_win = 0x00000000,
91 .emif_rd_wr_lvl_rmp_ctl = 0x80000000,
92 .emif_rd_wr_lvl_ctl = 0x00000000,
93 .emif_rd_wr_exec_thresh = 0x00000305
Felipe Balbi1e4ad742014-11-10 14:02:44 -060094};
95
Lokesh Vutla6213db72015-06-03 14:43:21 +053096/* Ext phy ctrl regs 1-35 */
Felipe Balbi1e4ad742014-11-10 14:02:44 -060097static const u32 beagle_x15_emif1_ddr3_ext_phy_ctrl_const_regs[] = {
Lokesh Vutla6213db72015-06-03 14:43:21 +053098 0x10040100,
Lokesh Vutla11e2b042016-03-08 09:11:35 +053099 0x00910091,
100 0x00950095,
101 0x009B009B,
102 0x009E009E,
103 0x00980098,
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600104 0x00340034,
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600105 0x00350035,
Lokesh Vutla11e2b042016-03-08 09:11:35 +0530106 0x00340034,
107 0x00310031,
108 0x00340034,
109 0x007F007F,
110 0x007F007F,
111 0x007F007F,
112 0x007F007F,
113 0x007F007F,
114 0x00480048,
115 0x004A004A,
116 0x00520052,
117 0x00550055,
118 0x00500050,
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600119 0x00000000,
120 0x00600020,
Lokesh Vutla6213db72015-06-03 14:43:21 +0530121 0x40011080,
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600122 0x08102040,
Lokesh Vutla11e2b042016-03-08 09:11:35 +0530123 0x0,
124 0x0,
125 0x0,
126 0x0,
127 0x0,
Lokesh Vutla496edff2015-06-03 14:43:22 +0530128 0x0,
129 0x0,
130 0x0,
131 0x0,
132 0x0
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600133};
134
135static const struct emif_regs beagle_x15_emif2_ddr3_532mhz_emif_regs = {
Keerthyeafd4642016-05-24 11:45:07 +0530136 .sdram_config_init = 0x61851b32,
137 .sdram_config = 0x61851b32,
138 .sdram_config2 = 0x08000000,
139 .ref_ctrl = 0x000040F1,
140 .ref_ctrl_final = 0x00001035,
141 .sdram_tim1 = 0xcccf36b3,
142 .sdram_tim2 = 0x308f7fda,
143 .sdram_tim3 = 0x407f88a8,
144 .read_idle_ctrl = 0x00050000,
145 .zq_config = 0x5007190b,
146 .temp_alert_config = 0x00000000,
147 .emif_ddr_phy_ctlr_1_init = 0x0024400b,
148 .emif_ddr_phy_ctlr_1 = 0x0e24400b,
149 .emif_ddr_ext_phy_ctrl_1 = 0x10040100,
150 .emif_ddr_ext_phy_ctrl_2 = 0x00910091,
151 .emif_ddr_ext_phy_ctrl_3 = 0x00950095,
152 .emif_ddr_ext_phy_ctrl_4 = 0x009b009b,
153 .emif_ddr_ext_phy_ctrl_5 = 0x009e009e,
154 .emif_rd_wr_lvl_rmp_win = 0x00000000,
155 .emif_rd_wr_lvl_rmp_ctl = 0x80000000,
156 .emif_rd_wr_lvl_ctl = 0x00000000,
157 .emif_rd_wr_exec_thresh = 0x00000305
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600158};
159
160static const u32 beagle_x15_emif2_ddr3_ext_phy_ctrl_const_regs[] = {
Lokesh Vutla6213db72015-06-03 14:43:21 +0530161 0x10040100,
Lokesh Vutla11e2b042016-03-08 09:11:35 +0530162 0x00910091,
163 0x00950095,
164 0x009B009B,
165 0x009E009E,
166 0x00980098,
167 0x00340034,
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600168 0x00350035,
Lokesh Vutla11e2b042016-03-08 09:11:35 +0530169 0x00340034,
170 0x00310031,
171 0x00340034,
172 0x007F007F,
173 0x007F007F,
174 0x007F007F,
175 0x007F007F,
176 0x007F007F,
177 0x00480048,
178 0x004A004A,
179 0x00520052,
180 0x00550055,
181 0x00500050,
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600182 0x00000000,
183 0x00600020,
Lokesh Vutla6213db72015-06-03 14:43:21 +0530184 0x40011080,
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600185 0x08102040,
Lokesh Vutla11e2b042016-03-08 09:11:35 +0530186 0x0,
187 0x0,
188 0x0,
189 0x0,
190 0x0,
Lokesh Vutla496edff2015-06-03 14:43:22 +0530191 0x0,
192 0x0,
193 0x0,
194 0x0,
195 0x0
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600196};
197
198void emif_get_reg_dump(u32 emif_nr, const struct emif_regs **regs)
199{
200 switch (emif_nr) {
201 case 1:
202 *regs = &beagle_x15_emif1_ddr3_532mhz_emif_regs;
203 break;
204 case 2:
205 *regs = &beagle_x15_emif2_ddr3_532mhz_emif_regs;
206 break;
207 }
208}
209
210void emif_get_ext_phy_ctrl_const_regs(u32 emif_nr, const u32 **regs, u32 *size)
211{
212 switch (emif_nr) {
213 case 1:
214 *regs = beagle_x15_emif1_ddr3_ext_phy_ctrl_const_regs;
215 *size = ARRAY_SIZE(beagle_x15_emif1_ddr3_ext_phy_ctrl_const_regs);
216 break;
217 case 2:
218 *regs = beagle_x15_emif2_ddr3_ext_phy_ctrl_const_regs;
219 *size = ARRAY_SIZE(beagle_x15_emif2_ddr3_ext_phy_ctrl_const_regs);
220 break;
221 }
222}
223
224struct vcores_data beagle_x15_volts = {
Lokesh Vutlabeb71272016-11-23 12:54:39 +0530225 .mpu.value[OPP_NOM] = VDD_MPU_DRA7_NOM,
226 .mpu.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_MPU_NOM,
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600227 .mpu.efuse.reg_bits = DRA752_EFUSE_REGBITS,
228 .mpu.addr = TPS659038_REG_ADDR_SMPS12,
229 .mpu.pmic = &tps659038,
Keerthyeafd4642016-05-24 11:45:07 +0530230 .mpu.abb_tx_done_mask = OMAP_ABB_MPU_TXDONE_MASK,
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600231
Lokesh Vutlabeb71272016-11-23 12:54:39 +0530232 .eve.value[OPP_NOM] = VDD_EVE_DRA7_NOM,
233 .eve.value[OPP_OD] = VDD_EVE_DRA7_OD,
234 .eve.value[OPP_HIGH] = VDD_EVE_DRA7_HIGH,
235 .eve.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_DSPEVE_NOM,
236 .eve.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_DSPEVE_OD,
237 .eve.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_DSPEVE_HIGH,
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600238 .eve.efuse.reg_bits = DRA752_EFUSE_REGBITS,
239 .eve.addr = TPS659038_REG_ADDR_SMPS45,
240 .eve.pmic = &tps659038,
Nishanth Menone52e3342016-04-21 14:34:25 -0500241 .eve.abb_tx_done_mask = OMAP_ABB_EVE_TXDONE_MASK,
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600242
Lokesh Vutlabeb71272016-11-23 12:54:39 +0530243 .gpu.value[OPP_NOM] = VDD_GPU_DRA7_NOM,
244 .gpu.value[OPP_OD] = VDD_GPU_DRA7_OD,
245 .gpu.value[OPP_HIGH] = VDD_GPU_DRA7_HIGH,
246 .gpu.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_GPU_NOM,
247 .gpu.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_GPU_OD,
248 .gpu.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_GPU_HIGH,
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600249 .gpu.efuse.reg_bits = DRA752_EFUSE_REGBITS,
250 .gpu.addr = TPS659038_REG_ADDR_SMPS45,
251 .gpu.pmic = &tps659038,
Nishanth Menone52e3342016-04-21 14:34:25 -0500252 .gpu.abb_tx_done_mask = OMAP_ABB_GPU_TXDONE_MASK,
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600253
Lokesh Vutlabeb71272016-11-23 12:54:39 +0530254 .core.value[OPP_NOM] = VDD_CORE_DRA7_NOM,
255 .core.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_CORE_NOM,
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600256 .core.efuse.reg_bits = DRA752_EFUSE_REGBITS,
257 .core.addr = TPS659038_REG_ADDR_SMPS6,
258 .core.pmic = &tps659038,
259
Lokesh Vutlabeb71272016-11-23 12:54:39 +0530260 .iva.value[OPP_NOM] = VDD_IVA_DRA7_NOM,
261 .iva.value[OPP_OD] = VDD_IVA_DRA7_OD,
262 .iva.value[OPP_HIGH] = VDD_IVA_DRA7_HIGH,
263 .iva.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_IVA_NOM,
264 .iva.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_IVA_OD,
265 .iva.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_IVA_HIGH,
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600266 .iva.efuse.reg_bits = DRA752_EFUSE_REGBITS,
267 .iva.addr = TPS659038_REG_ADDR_SMPS45,
268 .iva.pmic = &tps659038,
Nishanth Menone52e3342016-04-21 14:34:25 -0500269 .iva.abb_tx_done_mask = OMAP_ABB_IVA_TXDONE_MASK,
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600270};
271
Keerthyd60198d2016-05-24 11:45:06 +0530272struct vcores_data am572x_idk_volts = {
Lokesh Vutlabeb71272016-11-23 12:54:39 +0530273 .mpu.value[OPP_NOM] = VDD_MPU_DRA7_NOM,
274 .mpu.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_MPU_NOM,
Keerthyd60198d2016-05-24 11:45:06 +0530275 .mpu.efuse.reg_bits = DRA752_EFUSE_REGBITS,
276 .mpu.addr = TPS659038_REG_ADDR_SMPS12,
277 .mpu.pmic = &tps659038,
278 .mpu.abb_tx_done_mask = OMAP_ABB_MPU_TXDONE_MASK,
279
Lokesh Vutlabeb71272016-11-23 12:54:39 +0530280 .eve.value[OPP_NOM] = VDD_EVE_DRA7_NOM,
281 .eve.value[OPP_OD] = VDD_EVE_DRA7_OD,
282 .eve.value[OPP_HIGH] = VDD_EVE_DRA7_HIGH,
283 .eve.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_DSPEVE_NOM,
284 .eve.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_DSPEVE_OD,
285 .eve.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_DSPEVE_HIGH,
Keerthyd60198d2016-05-24 11:45:06 +0530286 .eve.efuse.reg_bits = DRA752_EFUSE_REGBITS,
287 .eve.addr = TPS659038_REG_ADDR_SMPS45,
288 .eve.pmic = &tps659038,
289 .eve.abb_tx_done_mask = OMAP_ABB_EVE_TXDONE_MASK,
290
Lokesh Vutlabeb71272016-11-23 12:54:39 +0530291 .gpu.value[OPP_NOM] = VDD_GPU_DRA7_NOM,
292 .gpu.value[OPP_OD] = VDD_GPU_DRA7_OD,
293 .gpu.value[OPP_HIGH] = VDD_GPU_DRA7_HIGH,
294 .gpu.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_GPU_NOM,
295 .gpu.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_GPU_OD,
296 .gpu.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_GPU_HIGH,
Keerthyd60198d2016-05-24 11:45:06 +0530297 .gpu.efuse.reg_bits = DRA752_EFUSE_REGBITS,
298 .gpu.addr = TPS659038_REG_ADDR_SMPS6,
299 .gpu.pmic = &tps659038,
300 .gpu.abb_tx_done_mask = OMAP_ABB_GPU_TXDONE_MASK,
301
Lokesh Vutlabeb71272016-11-23 12:54:39 +0530302 .core.value[OPP_NOM] = VDD_CORE_DRA7_NOM,
303 .core.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_CORE_NOM,
Keerthyd60198d2016-05-24 11:45:06 +0530304 .core.efuse.reg_bits = DRA752_EFUSE_REGBITS,
305 .core.addr = TPS659038_REG_ADDR_SMPS7,
306 .core.pmic = &tps659038,
307
Lokesh Vutlabeb71272016-11-23 12:54:39 +0530308 .iva.value[OPP_NOM] = VDD_IVA_DRA7_NOM,
309 .iva.value[OPP_OD] = VDD_IVA_DRA7_OD,
310 .iva.value[OPP_HIGH] = VDD_IVA_DRA7_HIGH,
311 .iva.efuse.reg[OPP_NOM] = STD_FUSE_OPP_VMIN_IVA_NOM,
312 .iva.efuse.reg[OPP_OD] = STD_FUSE_OPP_VMIN_IVA_OD,
313 .iva.efuse.reg[OPP_HIGH] = STD_FUSE_OPP_VMIN_IVA_HIGH,
Keerthyd60198d2016-05-24 11:45:06 +0530314 .iva.efuse.reg_bits = DRA752_EFUSE_REGBITS,
315 .iva.addr = TPS659038_REG_ADDR_SMPS8,
316 .iva.pmic = &tps659038,
317 .iva.abb_tx_done_mask = OMAP_ABB_IVA_TXDONE_MASK,
318};
319
Lokesh Vutlabeb71272016-11-23 12:54:39 +0530320int get_voltrail_opp(int rail_offset)
321{
322 int opp;
323
324 switch (rail_offset) {
325 case VOLT_MPU:
326 opp = DRA7_MPU_OPP;
327 break;
328 case VOLT_CORE:
329 opp = DRA7_CORE_OPP;
330 break;
331 case VOLT_GPU:
332 opp = DRA7_GPU_OPP;
333 break;
334 case VOLT_EVE:
335 opp = DRA7_DSPEVE_OPP;
336 break;
337 case VOLT_IVA:
338 opp = DRA7_IVA_OPP;
339 break;
340 default:
341 opp = OPP_NOM;
342 }
343
344 return opp;
345}
346
347
Kipisz, Steven212f96f2016-02-24 12:30:58 -0600348#ifdef CONFIG_SPL_BUILD
349/* No env to setup for SPL */
350static inline void setup_board_eeprom_env(void) { }
351
352/* Override function to read eeprom information */
353void do_board_detect(void)
354{
355 int rc;
356
357 rc = ti_i2c_eeprom_am_get(CONFIG_EEPROM_BUS_ADDRESS,
358 CONFIG_EEPROM_CHIP_ADDRESS);
359 if (rc)
360 printf("ti_i2c_eeprom_init failed %d\n", rc);
361}
362
363#else /* CONFIG_SPL_BUILD */
364
365/* Override function to read eeprom information: actual i2c read done by SPL*/
366void do_board_detect(void)
367{
368 char *bname = NULL;
369 int rc;
370
371 rc = ti_i2c_eeprom_am_get(CONFIG_EEPROM_BUS_ADDRESS,
372 CONFIG_EEPROM_CHIP_ADDRESS);
373 if (rc)
374 printf("ti_i2c_eeprom_init failed %d\n", rc);
375
376 if (board_is_x15())
377 bname = "BeagleBoard X15";
378 else if (board_is_am572x_evm())
379 bname = "AM572x EVM";
Steve Kipiszc020d352016-04-08 17:01:29 -0500380 else if (board_is_am572x_idk())
381 bname = "AM572x IDK";
Kipisz, Steven212f96f2016-02-24 12:30:58 -0600382
383 if (bname)
384 snprintf(sysinfo.board_string, SYSINFO_BOARD_NAME_MAX_LEN,
385 "Board: %s REV %s\n", bname, board_ti_get_rev());
386}
387
388static void setup_board_eeprom_env(void)
389{
390 char *name = "beagle_x15";
391 int rc;
392
393 rc = ti_i2c_eeprom_am_get(CONFIG_EEPROM_BUS_ADDRESS,
394 CONFIG_EEPROM_CHIP_ADDRESS);
395 if (rc)
396 goto invalid_eeprom;
397
Nishanth Menonbf43ce62016-11-25 11:14:19 +0530398 if (board_is_x15()) {
Lokesh Vutlaf7f9f6b2016-11-25 11:14:20 +0530399 if (board_is_x15_revb1())
400 name = "beagle_x15_revb1";
401 else
402 name = "beagle_x15";
Nishanth Menonbf43ce62016-11-25 11:14:19 +0530403 } else if (board_is_am572x_evm()) {
404 if (board_is_am572x_evm_reva3())
405 name = "am57xx_evm_reva3";
406 else
407 name = "am57xx_evm";
408 } else if (board_is_am572x_idk()) {
Steve Kipiszc020d352016-04-08 17:01:29 -0500409 name = "am572x_idk";
Nishanth Menonbf43ce62016-11-25 11:14:19 +0530410 } else {
Kipisz, Steven212f96f2016-02-24 12:30:58 -0600411 printf("Unidentified board claims %s in eeprom header\n",
412 board_ti_get_name());
Nishanth Menonbf43ce62016-11-25 11:14:19 +0530413 }
Kipisz, Steven212f96f2016-02-24 12:30:58 -0600414
415invalid_eeprom:
416 set_board_info_env(name);
417}
418
419#endif /* CONFIG_SPL_BUILD */
420
Keerthyd60198d2016-05-24 11:45:06 +0530421void vcores_init(void)
422{
423 if (board_is_am572x_idk())
424 *omap_vcores = &am572x_idk_volts;
425 else
426 *omap_vcores = &beagle_x15_volts;
427}
428
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600429void hw_data_init(void)
430{
431 *prcm = &dra7xx_prcm;
432 *dplls_data = &dra7xx_dplls;
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600433 *ctrl = &dra7xx_ctrl;
434}
435
436int board_init(void)
437{
438 gpmc_init();
439 gd->bd->bi_boot_params = (CONFIG_SYS_SDRAM_BASE + 0x100);
440
441 return 0;
442}
443
444int board_late_init(void)
445{
Kipisz, Steven212f96f2016-02-24 12:30:58 -0600446 setup_board_eeprom_env();
447
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600448 /*
449 * DEV_CTRL.DEV_ON = 1 please - else palmas switches off in 8 seconds
450 * This is the POWERHOLD-in-Low behavior.
451 */
452 palmas_i2c_write_u8(TPS65903X_CHIP_P1, 0xA0, 0x1);
Lokesh Vutla82cca5a2016-11-29 11:58:02 +0530453
454 /*
455 * Default FIT boot on HS devices. Non FIT images are not allowed
456 * on HS devices.
457 */
458 if (get_device_type() == HS_DEVICE)
459 setenv("boot_fit", "1");
460
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600461 return 0;
462}
463
Paul Kocialkowski3ef56e62016-02-27 19:18:56 +0100464void set_muxconf_regs(void)
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600465{
466 do_set_mux32((*ctrl)->control_padconf_core_base,
Lokesh Vutlaf91e0c42015-06-04 16:42:41 +0530467 early_padconf, ARRAY_SIZE(early_padconf));
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600468}
469
Lokesh Vutlaf91e0c42015-06-04 16:42:41 +0530470#ifdef CONFIG_IODELAY_RECALIBRATION
471void recalibrate_iodelay(void)
472{
Steve Kipiszc020d352016-04-08 17:01:29 -0500473 const struct pad_conf_entry *pconf;
474 const struct iodelay_cfg_entry *iod;
475 int pconf_sz, iod_sz;
Nishanth Menon89a38952016-11-25 11:14:22 +0530476 int ret;
Steve Kipiszc020d352016-04-08 17:01:29 -0500477
478 if (board_is_am572x_idk()) {
479 pconf = core_padconf_array_essential_am572x_idk;
480 pconf_sz = ARRAY_SIZE(core_padconf_array_essential_am572x_idk);
481 iod = iodelay_cfg_array_am572x_idk;
482 iod_sz = ARRAY_SIZE(iodelay_cfg_array_am572x_idk);
483 } else {
484 /* Common for X15/GPEVM */
485 pconf = core_padconf_array_essential_x15;
486 pconf_sz = ARRAY_SIZE(core_padconf_array_essential_x15);
Nishanth Menon89a38952016-11-25 11:14:22 +0530487 /* There never was an SR1.0 X15.. So.. */
488 if (omap_revision() == DRA752_ES1_1) {
489 iod = iodelay_cfg_array_x15_sr1_1;
490 iod_sz = ARRAY_SIZE(iodelay_cfg_array_x15_sr1_1);
491 } else {
492 /* Since full production should switch to SR2.0 */
493 iod = iodelay_cfg_array_x15_sr2_0;
494 iod_sz = ARRAY_SIZE(iodelay_cfg_array_x15_sr2_0);
495 }
Steve Kipiszc020d352016-04-08 17:01:29 -0500496 }
497
Nishanth Menon89a38952016-11-25 11:14:22 +0530498 /* Setup I/O isolation */
499 ret = __recalibrate_iodelay_start();
500 if (ret)
501 goto err;
502
503 /* Do the muxing here */
504 do_set_mux32((*ctrl)->control_padconf_core_base, pconf, pconf_sz);
505
506 /* Now do the weird minor deltas that should be safe */
507 if (board_is_x15() || board_is_am572x_evm()) {
508 if (board_is_x15_revb1() || board_is_am572x_evm_reva3()) {
509 pconf = core_padconf_array_delta_x15_sr2_0;
510 pconf_sz = ARRAY_SIZE(core_padconf_array_delta_x15_sr2_0);
511 } else {
512 pconf = core_padconf_array_delta_x15_sr1_1;
513 pconf_sz = ARRAY_SIZE(core_padconf_array_delta_x15_sr1_1);
514 }
515 do_set_mux32((*ctrl)->control_padconf_core_base, pconf, pconf_sz);
516 }
517
518 /* Setup IOdelay configuration */
519 ret = do_set_iodelay((*ctrl)->iodelay_config_base, iod, iod_sz);
520err:
521 /* Closeup.. remove isolation */
522 __recalibrate_iodelay_end(ret);
Lokesh Vutlaf91e0c42015-06-04 16:42:41 +0530523}
524#endif
525
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600526#if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_GENERIC_MMC)
527int board_mmc_init(bd_t *bis)
528{
529 omap_mmc_init(0, 0, 0, -1, -1);
530 omap_mmc_init(1, 0, 0, -1, -1);
531 return 0;
532}
533#endif
534
535#if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_OS_BOOT)
536int spl_start_uboot(void)
537{
538 /* break into full u-boot on 'c' */
539 if (serial_tstc() && serial_getc() == 'c')
540 return 1;
541
542#ifdef CONFIG_SPL_ENV_SUPPORT
543 env_init();
544 env_relocate_spec();
545 if (getenv_yesno("boot_os") != 1)
546 return 1;
547#endif
548
549 return 0;
550}
551#endif
552
Kishon Vijay Abraham I7c379aa2015-08-19 14:13:19 +0530553#ifdef CONFIG_USB_DWC3
Kishon Vijay Abraham I7c379aa2015-08-19 14:13:19 +0530554static struct dwc3_device usb_otg_ss2 = {
555 .maximum_speed = USB_SPEED_HIGH,
556 .base = DRA7_USB_OTG_SS2_BASE,
557 .tx_fifo_resize = false,
558 .index = 1,
559};
560
561static struct dwc3_omap_device usb_otg_ss2_glue = {
562 .base = (void *)DRA7_USB_OTG_SS2_GLUE_BASE,
563 .utmi_mode = DWC3_OMAP_UTMI_MODE_SW,
564 .index = 1,
565};
566
567static struct ti_usb_phy_device usb_phy2_device = {
568 .usb2_phy_power = (void *)DRA7_USB2_PHY2_POWER,
569 .index = 1,
570};
571
Kishon Vijay Abraham I7c379aa2015-08-19 14:13:19 +0530572int usb_gadget_handle_interrupts(int index)
573{
574 u32 status;
575
576 status = dwc3_omap_uboot_interrupt_status(index);
577 if (status)
578 dwc3_uboot_handle_interrupt(index);
579
580 return 0;
581}
Roger Quadros55efadd2016-05-23 17:37:48 +0300582#endif /* CONFIG_USB_DWC3 */
583
584#if defined(CONFIG_USB_DWC3) || defined(CONFIG_USB_XHCI_OMAP)
585int board_usb_init(int index, enum usb_init_type init)
586{
587 enable_usb_clocks(index);
588 switch (index) {
589 case 0:
590 if (init == USB_INIT_DEVICE) {
591 printf("port %d can't be used as device\n", index);
592 disable_usb_clocks(index);
593 return -EINVAL;
594 }
595 break;
596 case 1:
597 if (init == USB_INIT_DEVICE) {
598#ifdef CONFIG_USB_DWC3
599 usb_otg_ss2.dr_mode = USB_DR_MODE_PERIPHERAL;
600 usb_otg_ss2_glue.vbus_id_status = OMAP_DWC3_VBUS_VALID;
601 ti_usb_phy_uboot_init(&usb_phy2_device);
602 dwc3_omap_uboot_init(&usb_otg_ss2_glue);
603 dwc3_uboot_init(&usb_otg_ss2);
Kishon Vijay Abraham I7c379aa2015-08-19 14:13:19 +0530604#endif
Roger Quadros55efadd2016-05-23 17:37:48 +0300605 } else {
606 printf("port %d can't be used as host\n", index);
607 disable_usb_clocks(index);
608 return -EINVAL;
609 }
610
611 break;
612 default:
613 printf("Invalid Controller Index\n");
614 }
615
616 return 0;
617}
618
619int board_usb_cleanup(int index, enum usb_init_type init)
620{
621#ifdef CONFIG_USB_DWC3
622 switch (index) {
623 case 0:
624 case 1:
625 if (init == USB_INIT_DEVICE) {
626 ti_usb_phy_uboot_exit(index);
627 dwc3_uboot_exit(index);
628 dwc3_omap_uboot_exit(index);
629 }
630 break;
631 default:
632 printf("Invalid Controller Index\n");
633 }
634#endif
635 disable_usb_clocks(index);
636 return 0;
637}
638#endif /* defined(CONFIG_USB_DWC3) || defined(CONFIG_USB_XHCI_OMAP) */
Kishon Vijay Abraham I7c379aa2015-08-19 14:13:19 +0530639
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600640#ifdef CONFIG_DRIVER_TI_CPSW
641
642/* Delay value to add to calibrated value */
643#define RGMII0_TXCTL_DLY_VAL ((0x3 << 5) + 0x8)
644#define RGMII0_TXD0_DLY_VAL ((0x3 << 5) + 0x8)
645#define RGMII0_TXD1_DLY_VAL ((0x3 << 5) + 0x2)
646#define RGMII0_TXD2_DLY_VAL ((0x4 << 5) + 0x0)
647#define RGMII0_TXD3_DLY_VAL ((0x4 << 5) + 0x0)
648#define VIN2A_D13_DLY_VAL ((0x3 << 5) + 0x8)
649#define VIN2A_D17_DLY_VAL ((0x3 << 5) + 0x8)
650#define VIN2A_D16_DLY_VAL ((0x3 << 5) + 0x2)
651#define VIN2A_D15_DLY_VAL ((0x4 << 5) + 0x0)
652#define VIN2A_D14_DLY_VAL ((0x4 << 5) + 0x0)
653
654static void cpsw_control(int enabled)
655{
656 /* VTP can be added here */
657}
658
659static struct cpsw_slave_data cpsw_slaves[] = {
660 {
661 .slave_reg_ofs = 0x208,
662 .sliver_reg_ofs = 0xd80,
663 .phy_addr = 1,
664 },
665 {
666 .slave_reg_ofs = 0x308,
667 .sliver_reg_ofs = 0xdc0,
668 .phy_addr = 2,
669 },
670};
671
672static struct cpsw_platform_data cpsw_data = {
673 .mdio_base = CPSW_MDIO_BASE,
674 .cpsw_base = CPSW_BASE,
675 .mdio_div = 0xff,
676 .channels = 8,
677 .cpdma_reg_ofs = 0x800,
678 .slaves = 1,
679 .slave_data = cpsw_slaves,
680 .ale_reg_ofs = 0xd00,
681 .ale_entries = 1024,
682 .host_port_reg_ofs = 0x108,
683 .hw_stats_reg_ofs = 0x900,
684 .bd_ram_ofs = 0x2000,
685 .mac_control = (1 << 5),
686 .control = cpsw_control,
687 .host_port_num = 0,
688 .version = CPSW_CTRL_VERSION_2,
689};
690
Roger Quadros92667e82016-03-18 13:18:12 +0200691static u64 mac_to_u64(u8 mac[6])
692{
693 int i;
694 u64 addr = 0;
695
696 for (i = 0; i < 6; i++) {
697 addr <<= 8;
698 addr |= mac[i];
699 }
700
701 return addr;
702}
703
704static void u64_to_mac(u64 addr, u8 mac[6])
705{
706 mac[5] = addr;
707 mac[4] = addr >> 8;
708 mac[3] = addr >> 16;
709 mac[2] = addr >> 24;
710 mac[1] = addr >> 32;
711 mac[0] = addr >> 40;
712}
713
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600714int board_eth_init(bd_t *bis)
715{
716 int ret;
717 uint8_t mac_addr[6];
718 uint32_t mac_hi, mac_lo;
719 uint32_t ctrl_val;
Roger Quadros92667e82016-03-18 13:18:12 +0200720 int i;
721 u64 mac1, mac2;
722 u8 mac_addr1[6], mac_addr2[6];
723 int num_macs;
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600724
725 /* try reading mac address from efuse */
726 mac_lo = readl((*ctrl)->control_core_mac_id_0_lo);
727 mac_hi = readl((*ctrl)->control_core_mac_id_0_hi);
728 mac_addr[0] = (mac_hi & 0xFF0000) >> 16;
729 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
730 mac_addr[2] = mac_hi & 0xFF;
731 mac_addr[3] = (mac_lo & 0xFF0000) >> 16;
732 mac_addr[4] = (mac_lo & 0xFF00) >> 8;
733 mac_addr[5] = mac_lo & 0xFF;
734
735 if (!getenv("ethaddr")) {
736 printf("<ethaddr> not set. Validating first E-fuse MAC\n");
737
Joe Hershberger0adb5b72015-04-08 01:41:04 -0500738 if (is_valid_ethaddr(mac_addr))
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600739 eth_setenv_enetaddr("ethaddr", mac_addr);
740 }
741
742 mac_lo = readl((*ctrl)->control_core_mac_id_1_lo);
743 mac_hi = readl((*ctrl)->control_core_mac_id_1_hi);
744 mac_addr[0] = (mac_hi & 0xFF0000) >> 16;
745 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
746 mac_addr[2] = mac_hi & 0xFF;
747 mac_addr[3] = (mac_lo & 0xFF0000) >> 16;
748 mac_addr[4] = (mac_lo & 0xFF00) >> 8;
749 mac_addr[5] = mac_lo & 0xFF;
750
751 if (!getenv("eth1addr")) {
Joe Hershberger0adb5b72015-04-08 01:41:04 -0500752 if (is_valid_ethaddr(mac_addr))
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600753 eth_setenv_enetaddr("eth1addr", mac_addr);
754 }
755
756 ctrl_val = readl((*ctrl)->control_core_control_io1) & (~0x33);
757 ctrl_val |= 0x22;
758 writel(ctrl_val, (*ctrl)->control_core_control_io1);
759
Steve Kipiszc020d352016-04-08 17:01:29 -0500760 /* The phy address for the AM572x IDK are different than x15 */
761 if (board_is_am572x_idk()) {
762 cpsw_data.slave_data[0].phy_addr = 0;
763 cpsw_data.slave_data[1].phy_addr = 1;
764 }
765
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600766 ret = cpsw_register(&cpsw_data);
767 if (ret < 0)
768 printf("Error %d registering CPSW switch\n", ret);
769
Roger Quadros92667e82016-03-18 13:18:12 +0200770 /*
771 * Export any Ethernet MAC addresses from EEPROM.
772 * On AM57xx the 2 MAC addresses define the address range
773 */
774 board_ti_get_eth_mac_addr(0, mac_addr1);
775 board_ti_get_eth_mac_addr(1, mac_addr2);
776
777 if (is_valid_ethaddr(mac_addr1) && is_valid_ethaddr(mac_addr2)) {
778 mac1 = mac_to_u64(mac_addr1);
779 mac2 = mac_to_u64(mac_addr2);
780
781 /* must contain an address range */
782 num_macs = mac2 - mac1 + 1;
783 /* <= 50 to protect against user programming error */
784 if (num_macs > 0 && num_macs <= 50) {
785 for (i = 0; i < num_macs; i++) {
786 u64_to_mac(mac1 + i, mac_addr);
787 if (is_valid_ethaddr(mac_addr)) {
788 eth_setenv_enetaddr_by_index("eth",
789 i + 2,
790 mac_addr);
791 }
792 }
793 }
794 }
795
Felipe Balbi1e4ad742014-11-10 14:02:44 -0600796 return ret;
797}
798#endif
Lokesh Vutla334bbb32015-06-16 20:36:05 +0530799
800#ifdef CONFIG_BOARD_EARLY_INIT_F
801/* VTT regulator enable */
802static inline void vtt_regulator_enable(void)
803{
804 if (omap_hw_init_context() == OMAP_INIT_CONTEXT_UBOOT_AFTER_SPL)
805 return;
806
807 gpio_request(GPIO_DDR_VTT_EN, "ddr_vtt_en");
808 gpio_direction_output(GPIO_DDR_VTT_EN, 1);
809}
810
811int board_early_init_f(void)
812{
813 vtt_regulator_enable();
814 return 0;
815}
816#endif
Daniel Allred62a09f02016-05-19 19:10:54 -0500817
818#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
819int ft_board_setup(void *blob, bd_t *bd)
820{
821 ft_cpu_setup(blob, bd);
822
823 return 0;
824}
825#endif
Lokesh Vutla7a0ea582016-06-10 09:35:43 +0530826
827#ifdef CONFIG_SPL_LOAD_FIT
828int board_fit_config_name_match(const char *name)
829{
Lokesh Vutlaf7f9f6b2016-11-25 11:14:20 +0530830 if (board_is_x15()) {
831 if (board_is_x15_revb1()) {
832 if (!strcmp(name, "am57xx-beagle-x15-revb1"))
833 return 0;
834 } else if (!strcmp(name, "am57xx-beagle-x15")) {
835 return 0;
836 }
837 } else if (board_is_am572x_evm() &&
838 !strcmp(name, "am57xx-beagle-x15")) {
Lokesh Vutla7a0ea582016-06-10 09:35:43 +0530839 return 0;
Lokesh Vutlaf7f9f6b2016-11-25 11:14:20 +0530840 } else if (board_is_am572x_idk() && !strcmp(name, "am572x-idk")) {
Lokesh Vutla7a0ea582016-06-10 09:35:43 +0530841 return 0;
Lokesh Vutlaf7f9f6b2016-11-25 11:14:20 +0530842 }
843
844 return -1;
Lokesh Vutla7a0ea582016-06-10 09:35:43 +0530845}
846#endif
Andreas Dannenberg17c29872016-06-27 09:19:22 -0500847
848#ifdef CONFIG_TI_SECURE_DEVICE
849void board_fit_image_post_process(void **p_image, size_t *p_size)
850{
851 secure_boot_verify_image(p_image, p_size);
852}
Andrew F. Davis1b597ad2016-11-29 16:33:26 -0600853
854void board_tee_image_process(ulong tee_image, size_t tee_size)
855{
856 secure_tee_install((u32)tee_image);
857}
858
859U_BOOT_FIT_LOADABLE_HANDLER(IH_TYPE_TEE, board_tee_image_process);
Andreas Dannenberg17c29872016-06-27 09:19:22 -0500860#endif