xref: /rk3399_rockchip-uboot/board/ti/dra7xx/evm.c (revision 3ef56e61c8cbfdfdca155f5b1e2cd4d5cb5e048a)
1687054a7SLokesh Vutla /*
2687054a7SLokesh Vutla  * (C) Copyright 2013
3687054a7SLokesh Vutla  * Texas Instruments Incorporated, <www.ti.com>
4687054a7SLokesh Vutla  *
5687054a7SLokesh Vutla  * Lokesh Vutla <lokeshvutla@ti.com>
6687054a7SLokesh Vutla  *
7687054a7SLokesh Vutla  * Based on previous work by:
8687054a7SLokesh Vutla  * Aneesh V       <aneesh@ti.com>
9687054a7SLokesh Vutla  * Steve Sakoman  <steve@sakoman.com>
10687054a7SLokesh Vutla  *
111a459660SWolfgang Denk  * SPDX-License-Identifier:	GPL-2.0+
12687054a7SLokesh Vutla  */
13687054a7SLokesh Vutla #include <common.h>
14cb199102SNishanth Menon #include <palmas.h>
15e9024ef2SDan Murphy #include <sata.h>
1625afe55dSLokesh Vutla #include <linux/string.h>
177b922523SLokesh Vutla #include <asm/gpio.h>
18a17188c1SKishon Vijay Abraham I #include <usb.h>
19a17188c1SKishon Vijay Abraham I #include <linux/usb/gadget.h>
207b922523SLokesh Vutla #include <asm/arch/gpio.h>
21706dd348SLokesh Vutla #include <asm/arch/dra7xx_iodelay.h>
22a7638833SLokesh Vutla #include <asm/emif.h>
23687054a7SLokesh Vutla #include <asm/arch/sys_proto.h>
24687054a7SLokesh Vutla #include <asm/arch/mmc_host_def.h>
2521914ee6SRoger Quadros #include <asm/arch/sata.h>
2679b079f3STom Rini #include <environment.h>
27a17188c1SKishon Vijay Abraham I #include <dwc3-uboot.h>
28a17188c1SKishon Vijay Abraham I #include <dwc3-omap-uboot.h>
29a17188c1SKishon Vijay Abraham I #include <ti-usb-phy-uboot.h>
30687054a7SLokesh Vutla 
31687054a7SLokesh Vutla #include "mux_data.h"
3225afe55dSLokesh Vutla #include "../common/board_detect.h"
3325afe55dSLokesh Vutla 
3425afe55dSLokesh Vutla #define board_is_dra74x_evm()		board_ti_is("5777xCPU")
3525afe55dSLokesh Vutla #define board_is_dra74x_revh_or_later() board_is_dra74x_evm() &&	\
3625afe55dSLokesh Vutla 				(strncmp("H", board_ti_get_rev(), 1) <= 0)
37c4a2736cSLokesh Vutla #define board_ti_get_emif_size()	board_ti_get_emif1_size() +	\
38c4a2736cSLokesh Vutla 					board_ti_get_emif2_size()
39687054a7SLokesh Vutla 
40b1e26e3bSMugunthan V N #ifdef CONFIG_DRIVER_TI_CPSW
41b1e26e3bSMugunthan V N #include <cpsw.h>
42b1e26e3bSMugunthan V N #endif
43b1e26e3bSMugunthan V N 
44687054a7SLokesh Vutla DECLARE_GLOBAL_DATA_PTR;
45687054a7SLokesh Vutla 
467b922523SLokesh Vutla /* GPIO 7_11 */
477b922523SLokesh Vutla #define GPIO_DDR_VTT_EN 203
487b922523SLokesh Vutla 
4925afe55dSLokesh Vutla #define SYSINFO_BOARD_NAME_MAX_LEN	37
5025afe55dSLokesh Vutla 
51687054a7SLokesh Vutla const struct omap_sysinfo sysinfo = {
5225afe55dSLokesh Vutla 	"Board: UNKNOWN(DRA7 EVM) REV UNKNOWN\n"
53687054a7SLokesh Vutla };
54687054a7SLokesh Vutla 
55a7638833SLokesh Vutla static const struct emif_regs emif1_ddr3_532_mhz_1cs = {
56a7638833SLokesh Vutla 	.sdram_config_init              = 0x61851ab2,
57a7638833SLokesh Vutla 	.sdram_config                   = 0x61851ab2,
58a7638833SLokesh Vutla 	.sdram_config2			= 0x08000000,
59a7638833SLokesh Vutla 	.ref_ctrl                       = 0x000040F1,
60a7638833SLokesh Vutla 	.ref_ctrl_final			= 0x00001035,
61a7638833SLokesh Vutla 	.sdram_tim1                     = 0xCCCF36B3,
62a7638833SLokesh Vutla 	.sdram_tim2                     = 0x308F7FDA,
63a7638833SLokesh Vutla 	.sdram_tim3                     = 0x427F88A8,
64a7638833SLokesh Vutla 	.read_idle_ctrl                 = 0x00050000,
65a7638833SLokesh Vutla 	.zq_config                      = 0x0007190B,
66a7638833SLokesh Vutla 	.temp_alert_config              = 0x00000000,
67a7638833SLokesh Vutla 	.emif_ddr_phy_ctlr_1_init       = 0x0024400B,
68a7638833SLokesh Vutla 	.emif_ddr_phy_ctlr_1            = 0x0E24400B,
69a7638833SLokesh Vutla 	.emif_ddr_ext_phy_ctrl_1        = 0x10040100,
70a7638833SLokesh Vutla 	.emif_ddr_ext_phy_ctrl_2        = 0x00910091,
71a7638833SLokesh Vutla 	.emif_ddr_ext_phy_ctrl_3        = 0x00950095,
72a7638833SLokesh Vutla 	.emif_ddr_ext_phy_ctrl_4        = 0x009B009B,
73a7638833SLokesh Vutla 	.emif_ddr_ext_phy_ctrl_5        = 0x009E009E,
74a7638833SLokesh Vutla 	.emif_rd_wr_lvl_rmp_win         = 0x00000000,
75a7638833SLokesh Vutla 	.emif_rd_wr_lvl_rmp_ctl         = 0x80000000,
76a7638833SLokesh Vutla 	.emif_rd_wr_lvl_ctl             = 0x00000000,
77a7638833SLokesh Vutla 	.emif_rd_wr_exec_thresh         = 0x00000305
78a7638833SLokesh Vutla };
79a7638833SLokesh Vutla 
80a7638833SLokesh Vutla static const struct emif_regs emif2_ddr3_532_mhz_1cs = {
81a7638833SLokesh Vutla 	.sdram_config_init              = 0x61851B32,
82a7638833SLokesh Vutla 	.sdram_config                   = 0x61851B32,
83a7638833SLokesh Vutla 	.sdram_config2			= 0x08000000,
84a7638833SLokesh Vutla 	.ref_ctrl                       = 0x000040F1,
85a7638833SLokesh Vutla 	.ref_ctrl_final			= 0x00001035,
86a7638833SLokesh Vutla 	.sdram_tim1                     = 0xCCCF36B3,
87a7638833SLokesh Vutla 	.sdram_tim2                     = 0x308F7FDA,
88a7638833SLokesh Vutla 	.sdram_tim3                     = 0x427F88A8,
89a7638833SLokesh Vutla 	.read_idle_ctrl                 = 0x00050000,
90a7638833SLokesh Vutla 	.zq_config                      = 0x0007190B,
91a7638833SLokesh Vutla 	.temp_alert_config              = 0x00000000,
92a7638833SLokesh Vutla 	.emif_ddr_phy_ctlr_1_init       = 0x0024400B,
93a7638833SLokesh Vutla 	.emif_ddr_phy_ctlr_1            = 0x0E24400B,
94a7638833SLokesh Vutla 	.emif_ddr_ext_phy_ctrl_1        = 0x10040100,
95a7638833SLokesh Vutla 	.emif_ddr_ext_phy_ctrl_2        = 0x00910091,
96a7638833SLokesh Vutla 	.emif_ddr_ext_phy_ctrl_3        = 0x00950095,
97a7638833SLokesh Vutla 	.emif_ddr_ext_phy_ctrl_4        = 0x009B009B,
98a7638833SLokesh Vutla 	.emif_ddr_ext_phy_ctrl_5        = 0x009E009E,
99a7638833SLokesh Vutla 	.emif_rd_wr_lvl_rmp_win         = 0x00000000,
100a7638833SLokesh Vutla 	.emif_rd_wr_lvl_rmp_ctl         = 0x80000000,
101a7638833SLokesh Vutla 	.emif_rd_wr_lvl_ctl             = 0x00000000,
102a7638833SLokesh Vutla 	.emif_rd_wr_exec_thresh         = 0x00000305
103a7638833SLokesh Vutla };
104a7638833SLokesh Vutla 
105a7638833SLokesh Vutla static const struct emif_regs emif_1_regs_ddr3_666_mhz_1cs_dra_es1 = {
106a7638833SLokesh Vutla 	.sdram_config_init              = 0x61862B32,
107a7638833SLokesh Vutla 	.sdram_config                   = 0x61862B32,
108a7638833SLokesh Vutla 	.sdram_config2			= 0x08000000,
109a7638833SLokesh Vutla 	.ref_ctrl                       = 0x0000514C,
110a7638833SLokesh Vutla 	.ref_ctrl_final			= 0x0000144A,
111a7638833SLokesh Vutla 	.sdram_tim1                     = 0xD113781C,
112a7638833SLokesh Vutla 	.sdram_tim2                     = 0x30717FE3,
113a7638833SLokesh Vutla 	.sdram_tim3                     = 0x409F86A8,
114a7638833SLokesh Vutla 	.read_idle_ctrl                 = 0x00050000,
115a7638833SLokesh Vutla 	.zq_config                      = 0x5007190B,
116a7638833SLokesh Vutla 	.temp_alert_config              = 0x00000000,
117a7638833SLokesh Vutla 	.emif_ddr_phy_ctlr_1_init       = 0x0024400D,
118a7638833SLokesh Vutla 	.emif_ddr_phy_ctlr_1            = 0x0E24400D,
119a7638833SLokesh Vutla 	.emif_ddr_ext_phy_ctrl_1        = 0x10040100,
120a7638833SLokesh Vutla 	.emif_ddr_ext_phy_ctrl_2        = 0x00A400A4,
121a7638833SLokesh Vutla 	.emif_ddr_ext_phy_ctrl_3        = 0x00A900A9,
122a7638833SLokesh Vutla 	.emif_ddr_ext_phy_ctrl_4        = 0x00B000B0,
123a7638833SLokesh Vutla 	.emif_ddr_ext_phy_ctrl_5        = 0x00B000B0,
124a7638833SLokesh Vutla 	.emif_rd_wr_lvl_rmp_win         = 0x00000000,
125a7638833SLokesh Vutla 	.emif_rd_wr_lvl_rmp_ctl         = 0x80000000,
126a7638833SLokesh Vutla 	.emif_rd_wr_lvl_ctl             = 0x00000000,
127a7638833SLokesh Vutla 	.emif_rd_wr_exec_thresh         = 0x00000305
128a7638833SLokesh Vutla };
129a7638833SLokesh Vutla 
130c4a2736cSLokesh Vutla const struct emif_regs emif1_ddr3_532_mhz_1cs_2G = {
131c4a2736cSLokesh Vutla 	.sdram_config_init              = 0x61851ab2,
132c4a2736cSLokesh Vutla 	.sdram_config                   = 0x61851ab2,
133c4a2736cSLokesh Vutla 	.sdram_config2			= 0x08000000,
134c4a2736cSLokesh Vutla 	.ref_ctrl                       = 0x000040F1,
135c4a2736cSLokesh Vutla 	.ref_ctrl_final			= 0x00001035,
136c4a2736cSLokesh Vutla 	.sdram_tim1                     = 0xCCCF36B3,
137c4a2736cSLokesh Vutla 	.sdram_tim2                     = 0x30BF7FDA,
138c4a2736cSLokesh Vutla 	.sdram_tim3                     = 0x427F8BA8,
139c4a2736cSLokesh Vutla 	.read_idle_ctrl                 = 0x00050000,
140c4a2736cSLokesh Vutla 	.zq_config                      = 0x0007190B,
141c4a2736cSLokesh Vutla 	.temp_alert_config              = 0x00000000,
142c4a2736cSLokesh Vutla 	.emif_ddr_phy_ctlr_1_init       = 0x0024400B,
143c4a2736cSLokesh Vutla 	.emif_ddr_phy_ctlr_1            = 0x0E24400B,
144c4a2736cSLokesh Vutla 	.emif_ddr_ext_phy_ctrl_1        = 0x10040100,
145c4a2736cSLokesh Vutla 	.emif_ddr_ext_phy_ctrl_2        = 0x00910091,
146c4a2736cSLokesh Vutla 	.emif_ddr_ext_phy_ctrl_3        = 0x00950095,
147c4a2736cSLokesh Vutla 	.emif_ddr_ext_phy_ctrl_4        = 0x009B009B,
148c4a2736cSLokesh Vutla 	.emif_ddr_ext_phy_ctrl_5        = 0x009E009E,
149c4a2736cSLokesh Vutla 	.emif_rd_wr_lvl_rmp_win         = 0x00000000,
150c4a2736cSLokesh Vutla 	.emif_rd_wr_lvl_rmp_ctl         = 0x80000000,
151c4a2736cSLokesh Vutla 	.emif_rd_wr_lvl_ctl             = 0x00000000,
152c4a2736cSLokesh Vutla 	.emif_rd_wr_exec_thresh         = 0x00000305
153c4a2736cSLokesh Vutla };
154c4a2736cSLokesh Vutla 
155c4a2736cSLokesh Vutla const struct emif_regs emif2_ddr3_532_mhz_1cs_2G = {
156c4a2736cSLokesh Vutla 	.sdram_config_init              = 0x61851B32,
157c4a2736cSLokesh Vutla 	.sdram_config                   = 0x61851B32,
158c4a2736cSLokesh Vutla 	.sdram_config2			= 0x08000000,
159c4a2736cSLokesh Vutla 	.ref_ctrl                       = 0x000040F1,
160c4a2736cSLokesh Vutla 	.ref_ctrl_final			= 0x00001035,
161c4a2736cSLokesh Vutla 	.sdram_tim1                     = 0xCCCF36B3,
162c4a2736cSLokesh Vutla 	.sdram_tim2                     = 0x308F7FDA,
163c4a2736cSLokesh Vutla 	.sdram_tim3                     = 0x427F88A8,
164c4a2736cSLokesh Vutla 	.read_idle_ctrl                 = 0x00050000,
165c4a2736cSLokesh Vutla 	.zq_config                      = 0x0007190B,
166c4a2736cSLokesh Vutla 	.temp_alert_config              = 0x00000000,
167c4a2736cSLokesh Vutla 	.emif_ddr_phy_ctlr_1_init       = 0x0024400B,
168c4a2736cSLokesh Vutla 	.emif_ddr_phy_ctlr_1            = 0x0E24400B,
169c4a2736cSLokesh Vutla 	.emif_ddr_ext_phy_ctrl_1        = 0x10040100,
170c4a2736cSLokesh Vutla 	.emif_ddr_ext_phy_ctrl_2        = 0x00910091,
171c4a2736cSLokesh Vutla 	.emif_ddr_ext_phy_ctrl_3        = 0x00950095,
172c4a2736cSLokesh Vutla 	.emif_ddr_ext_phy_ctrl_4        = 0x009B009B,
173c4a2736cSLokesh Vutla 	.emif_ddr_ext_phy_ctrl_5        = 0x009E009E,
174c4a2736cSLokesh Vutla 	.emif_rd_wr_lvl_rmp_win         = 0x00000000,
175c4a2736cSLokesh Vutla 	.emif_rd_wr_lvl_rmp_ctl         = 0x80000000,
176c4a2736cSLokesh Vutla 	.emif_rd_wr_lvl_ctl             = 0x00000000,
177c4a2736cSLokesh Vutla 	.emif_rd_wr_exec_thresh         = 0x00000305
178c4a2736cSLokesh Vutla };
179c4a2736cSLokesh Vutla 
180a7638833SLokesh Vutla void emif_get_reg_dump(u32 emif_nr, const struct emif_regs **regs)
181a7638833SLokesh Vutla {
182c4a2736cSLokesh Vutla 	u64 ram_size;
183c4a2736cSLokesh Vutla 
184c4a2736cSLokesh Vutla 	ram_size = board_ti_get_emif_size();
185c4a2736cSLokesh Vutla 
186a7638833SLokesh Vutla 	switch (omap_revision()) {
187a7638833SLokesh Vutla 	case DRA752_ES1_0:
188a7638833SLokesh Vutla 	case DRA752_ES1_1:
189a7638833SLokesh Vutla 	case DRA752_ES2_0:
190a7638833SLokesh Vutla 		switch (emif_nr) {
191a7638833SLokesh Vutla 		case 1:
192c4a2736cSLokesh Vutla 			if (ram_size > CONFIG_MAX_MEM_MAPPED)
193c4a2736cSLokesh Vutla 				*regs = &emif1_ddr3_532_mhz_1cs_2G;
194c4a2736cSLokesh Vutla 			else
195a7638833SLokesh Vutla 				*regs = &emif1_ddr3_532_mhz_1cs;
196a7638833SLokesh Vutla 			break;
197a7638833SLokesh Vutla 		case 2:
198c4a2736cSLokesh Vutla 			if (ram_size > CONFIG_MAX_MEM_MAPPED)
199c4a2736cSLokesh Vutla 				*regs = &emif2_ddr3_532_mhz_1cs_2G;
200c4a2736cSLokesh Vutla 			else
201a7638833SLokesh Vutla 				*regs = &emif2_ddr3_532_mhz_1cs;
202a7638833SLokesh Vutla 			break;
203a7638833SLokesh Vutla 		}
204a7638833SLokesh Vutla 		break;
205a7638833SLokesh Vutla 	case DRA722_ES1_0:
206a7638833SLokesh Vutla 		*regs = &emif_1_regs_ddr3_666_mhz_1cs_dra_es1;
207a7638833SLokesh Vutla 		break;
208a7638833SLokesh Vutla 	default:
209a7638833SLokesh Vutla 		*regs = &emif1_ddr3_532_mhz_1cs;
210a7638833SLokesh Vutla 	}
211a7638833SLokesh Vutla }
212a7638833SLokesh Vutla 
213a7638833SLokesh Vutla static const struct dmm_lisa_map_regs lisa_map_dra7_1536MB = {
214a7638833SLokesh Vutla 	.dmm_lisa_map_0 = 0x0,
215a7638833SLokesh Vutla 	.dmm_lisa_map_1 = 0x80640300,
216a7638833SLokesh Vutla 	.dmm_lisa_map_2 = 0xC0500220,
217a7638833SLokesh Vutla 	.dmm_lisa_map_3 = 0xFF020100,
218a7638833SLokesh Vutla 	.is_ma_present	= 0x1
219a7638833SLokesh Vutla };
220a7638833SLokesh Vutla 
221a7638833SLokesh Vutla static const struct dmm_lisa_map_regs lisa_map_2G_x_2 = {
222a7638833SLokesh Vutla 	.dmm_lisa_map_0 = 0x0,
223a7638833SLokesh Vutla 	.dmm_lisa_map_1 = 0x0,
224a7638833SLokesh Vutla 	.dmm_lisa_map_2 = 0x80600100,
225a7638833SLokesh Vutla 	.dmm_lisa_map_3 = 0xFF020100,
226a7638833SLokesh Vutla 	.is_ma_present	= 0x1
227a7638833SLokesh Vutla };
228a7638833SLokesh Vutla 
229c4a2736cSLokesh Vutla const struct dmm_lisa_map_regs lisa_map_dra7_2GB = {
230c4a2736cSLokesh Vutla 	.dmm_lisa_map_0 = 0x0,
231c4a2736cSLokesh Vutla 	.dmm_lisa_map_1 = 0x0,
232c4a2736cSLokesh Vutla 	.dmm_lisa_map_2 = 0x80740300,
233c4a2736cSLokesh Vutla 	.dmm_lisa_map_3 = 0xFF020100,
234c4a2736cSLokesh Vutla 	.is_ma_present	= 0x1
235c4a2736cSLokesh Vutla };
236c4a2736cSLokesh Vutla 
237a7638833SLokesh Vutla void emif_get_dmm_regs(const struct dmm_lisa_map_regs **dmm_lisa_regs)
238a7638833SLokesh Vutla {
239c4a2736cSLokesh Vutla 	u64 ram_size;
240c4a2736cSLokesh Vutla 
241c4a2736cSLokesh Vutla 	ram_size = board_ti_get_emif_size();
242c4a2736cSLokesh Vutla 
243a7638833SLokesh Vutla 	switch (omap_revision()) {
244a7638833SLokesh Vutla 	case DRA752_ES1_0:
245a7638833SLokesh Vutla 	case DRA752_ES1_1:
246a7638833SLokesh Vutla 	case DRA752_ES2_0:
247c4a2736cSLokesh Vutla 		if (ram_size > CONFIG_MAX_MEM_MAPPED)
248c4a2736cSLokesh Vutla 			*dmm_lisa_regs = &lisa_map_dra7_2GB;
249c4a2736cSLokesh Vutla 		else
250a7638833SLokesh Vutla 			*dmm_lisa_regs = &lisa_map_dra7_1536MB;
251a7638833SLokesh Vutla 		break;
252a7638833SLokesh Vutla 	case DRA722_ES1_0:
253a7638833SLokesh Vutla 	default:
254a7638833SLokesh Vutla 		*dmm_lisa_regs = &lisa_map_2G_x_2;
255a7638833SLokesh Vutla 	}
256a7638833SLokesh Vutla }
257a7638833SLokesh Vutla 
258687054a7SLokesh Vutla /**
259687054a7SLokesh Vutla  * @brief board_init
260687054a7SLokesh Vutla  *
261687054a7SLokesh Vutla  * @return 0
262687054a7SLokesh Vutla  */
263687054a7SLokesh Vutla int board_init(void)
264687054a7SLokesh Vutla {
265687054a7SLokesh Vutla 	gpmc_init();
266687054a7SLokesh Vutla 	gd->bd->bi_boot_params = (0x80000000 + 0x100); /* boot param addr */
267687054a7SLokesh Vutla 
268687054a7SLokesh Vutla 	return 0;
269687054a7SLokesh Vutla }
270687054a7SLokesh Vutla 
271d468b178SLokesh Vutla void dram_init_banksize(void)
272d468b178SLokesh Vutla {
273d468b178SLokesh Vutla 	u64 ram_size;
274d468b178SLokesh Vutla 
275d468b178SLokesh Vutla 	ram_size = board_ti_get_emif_size();
276d468b178SLokesh Vutla 
277d468b178SLokesh Vutla 	gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
278d468b178SLokesh Vutla 	gd->bd->bi_dram[0].size = get_effective_memsize();
279d468b178SLokesh Vutla 	if (ram_size > CONFIG_MAX_MEM_MAPPED) {
280d468b178SLokesh Vutla 		gd->bd->bi_dram[1].start = 0x200000000;
281d468b178SLokesh Vutla 		gd->bd->bi_dram[1].size = ram_size - CONFIG_MAX_MEM_MAPPED;
282d468b178SLokesh Vutla 	}
283d468b178SLokesh Vutla }
284d468b178SLokesh Vutla 
28521914ee6SRoger Quadros int board_late_init(void)
28621914ee6SRoger Quadros {
2874ec3f6e5SLokesh Vutla #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
28825afe55dSLokesh Vutla 	char *name = "unknown";
28925afe55dSLokesh Vutla 
29025afe55dSLokesh Vutla 	if (is_dra72x())
29125afe55dSLokesh Vutla 		name = "dra72x";
2924ec3f6e5SLokesh Vutla 	else
29325afe55dSLokesh Vutla 		name = "dra7xx";
29425afe55dSLokesh Vutla 
29525afe55dSLokesh Vutla 	set_board_info_env(name);
296f12467d1SDileep Katta 
29707815eb9SPaul Kocialkowski 	omap_die_id_serial();
2984ec3f6e5SLokesh Vutla #endif
29921914ee6SRoger Quadros 	return 0;
30021914ee6SRoger Quadros }
30121914ee6SRoger Quadros 
30225afe55dSLokesh Vutla #ifdef CONFIG_SPL_BUILD
30325afe55dSLokesh Vutla void do_board_detect(void)
30425afe55dSLokesh Vutla {
30525afe55dSLokesh Vutla 	int rc;
30625afe55dSLokesh Vutla 
30725afe55dSLokesh Vutla 	rc = ti_i2c_eeprom_dra7_get(CONFIG_EEPROM_BUS_ADDRESS,
30825afe55dSLokesh Vutla 				    CONFIG_EEPROM_CHIP_ADDRESS);
30925afe55dSLokesh Vutla 	if (rc)
31025afe55dSLokesh Vutla 		printf("ti_i2c_eeprom_init failed %d\n", rc);
31125afe55dSLokesh Vutla }
31225afe55dSLokesh Vutla 
31325afe55dSLokesh Vutla #else
31425afe55dSLokesh Vutla 
31525afe55dSLokesh Vutla void do_board_detect(void)
31625afe55dSLokesh Vutla {
31725afe55dSLokesh Vutla 	char *bname = NULL;
31825afe55dSLokesh Vutla 	int rc;
31925afe55dSLokesh Vutla 
32025afe55dSLokesh Vutla 	rc = ti_i2c_eeprom_dra7_get(CONFIG_EEPROM_BUS_ADDRESS,
32125afe55dSLokesh Vutla 				    CONFIG_EEPROM_CHIP_ADDRESS);
32225afe55dSLokesh Vutla 	if (rc)
32325afe55dSLokesh Vutla 		printf("ti_i2c_eeprom_init failed %d\n", rc);
32425afe55dSLokesh Vutla 
32525afe55dSLokesh Vutla 	if (board_is_dra74x_evm()) {
32625afe55dSLokesh Vutla 		bname = "DRA74x EVM";
32725afe55dSLokesh Vutla 	/* If EEPROM is not populated */
32825afe55dSLokesh Vutla 	} else {
32925afe55dSLokesh Vutla 		if (is_dra72x())
33025afe55dSLokesh Vutla 			bname = "DRA72x EVM";
33125afe55dSLokesh Vutla 		else
33225afe55dSLokesh Vutla 			bname = "DRA74x EVM";
33325afe55dSLokesh Vutla 	}
33425afe55dSLokesh Vutla 
33525afe55dSLokesh Vutla 	if (bname)
33625afe55dSLokesh Vutla 		snprintf(sysinfo.board_string, SYSINFO_BOARD_NAME_MAX_LEN,
33725afe55dSLokesh Vutla 			 "Board: %s REV %s\n", bname, board_ti_get_rev());
33825afe55dSLokesh Vutla }
33925afe55dSLokesh Vutla #endif	/* CONFIG_SPL_BUILD */
34025afe55dSLokesh Vutla 
341*3ef56e61SPaul Kocialkowski void set_muxconf_regs(void)
342687054a7SLokesh Vutla {
343687054a7SLokesh Vutla 	do_set_mux32((*ctrl)->control_padconf_core_base,
344706dd348SLokesh Vutla 		     early_padconf, ARRAY_SIZE(early_padconf));
345687054a7SLokesh Vutla }
346687054a7SLokesh Vutla 
347706dd348SLokesh Vutla #ifdef CONFIG_IODELAY_RECALIBRATION
348706dd348SLokesh Vutla void recalibrate_iodelay(void)
349706dd348SLokesh Vutla {
35003589234SNishanth Menon 	struct pad_conf_entry const *pads;
35103589234SNishanth Menon 	struct iodelay_cfg_entry const *iodelay;
35203589234SNishanth Menon 	int npads, niodelays;
35303589234SNishanth Menon 
35403589234SNishanth Menon 	switch (omap_revision()) {
35503589234SNishanth Menon 	case DRA722_ES1_0:
35626eccf31SLokesh Vutla 		pads = dra72x_core_padconf_array;
35726eccf31SLokesh Vutla 		npads = ARRAY_SIZE(dra72x_core_padconf_array);
35826eccf31SLokesh Vutla 		iodelay = dra72_iodelay_cfg_array;
35926eccf31SLokesh Vutla 		niodelays = ARRAY_SIZE(dra72_iodelay_cfg_array);
36003589234SNishanth Menon 		break;
36103589234SNishanth Menon 	case DRA752_ES1_0:
36203589234SNishanth Menon 	case DRA752_ES1_1:
36303589234SNishanth Menon 		pads = dra74x_core_padconf_array;
36403589234SNishanth Menon 		npads = ARRAY_SIZE(dra74x_core_padconf_array);
36503589234SNishanth Menon 		iodelay = dra742_es1_1_iodelay_cfg_array;
36603589234SNishanth Menon 		niodelays = ARRAY_SIZE(dra742_es1_1_iodelay_cfg_array);
36703589234SNishanth Menon 		break;
36803589234SNishanth Menon 	default:
36903589234SNishanth Menon 	case DRA752_ES2_0:
37003589234SNishanth Menon 		pads = dra74x_core_padconf_array;
37103589234SNishanth Menon 		npads = ARRAY_SIZE(dra74x_core_padconf_array);
37203589234SNishanth Menon 		iodelay = dra742_es2_0_iodelay_cfg_array;
37303589234SNishanth Menon 		niodelays = ARRAY_SIZE(dra742_es2_0_iodelay_cfg_array);
37476cff2b1SNishanth Menon 		/* Setup port1 and port2 for rgmii with 'no-id' mode */
37576cff2b1SNishanth Menon 		clrset_spare_register(1, 0, RGMII2_ID_MODE_N_MASK |
37676cff2b1SNishanth Menon 				      RGMII1_ID_MODE_N_MASK);
37703589234SNishanth Menon 		break;
37827d170afSNishanth Menon 	}
37903589234SNishanth Menon 	__recalibrate_iodelay(pads, npads, iodelay, niodelays);
380706dd348SLokesh Vutla }
381706dd348SLokesh Vutla #endif
382706dd348SLokesh Vutla 
383687054a7SLokesh Vutla #if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_GENERIC_MMC)
384687054a7SLokesh Vutla int board_mmc_init(bd_t *bis)
385687054a7SLokesh Vutla {
386687054a7SLokesh Vutla 	omap_mmc_init(0, 0, 0, -1, -1);
387687054a7SLokesh Vutla 	omap_mmc_init(1, 0, 0, -1, -1);
388687054a7SLokesh Vutla 	return 0;
389687054a7SLokesh Vutla }
390687054a7SLokesh Vutla #endif
391b1e26e3bSMugunthan V N 
392a17188c1SKishon Vijay Abraham I #ifdef CONFIG_USB_DWC3
393a17188c1SKishon Vijay Abraham I static struct dwc3_device usb_otg_ss1 = {
394a17188c1SKishon Vijay Abraham I 	.maximum_speed = USB_SPEED_SUPER,
395a17188c1SKishon Vijay Abraham I 	.base = DRA7_USB_OTG_SS1_BASE,
396a17188c1SKishon Vijay Abraham I 	.tx_fifo_resize = false,
397a17188c1SKishon Vijay Abraham I 	.index = 0,
398a17188c1SKishon Vijay Abraham I };
399a17188c1SKishon Vijay Abraham I 
400a17188c1SKishon Vijay Abraham I static struct dwc3_omap_device usb_otg_ss1_glue = {
401a17188c1SKishon Vijay Abraham I 	.base = (void *)DRA7_USB_OTG_SS1_GLUE_BASE,
402a17188c1SKishon Vijay Abraham I 	.utmi_mode = DWC3_OMAP_UTMI_MODE_SW,
403a17188c1SKishon Vijay Abraham I 	.index = 0,
404a17188c1SKishon Vijay Abraham I };
405a17188c1SKishon Vijay Abraham I 
406a17188c1SKishon Vijay Abraham I static struct ti_usb_phy_device usb_phy1_device = {
407a17188c1SKishon Vijay Abraham I 	.pll_ctrl_base = (void *)DRA7_USB3_PHY1_PLL_CTRL,
408a17188c1SKishon Vijay Abraham I 	.usb2_phy_power = (void *)DRA7_USB2_PHY1_POWER,
409a17188c1SKishon Vijay Abraham I 	.usb3_phy_power = (void *)DRA7_USB3_PHY1_POWER,
410a17188c1SKishon Vijay Abraham I 	.index = 0,
411a17188c1SKishon Vijay Abraham I };
412a17188c1SKishon Vijay Abraham I 
413a17188c1SKishon Vijay Abraham I static struct dwc3_device usb_otg_ss2 = {
414a17188c1SKishon Vijay Abraham I 	.maximum_speed = USB_SPEED_SUPER,
415a17188c1SKishon Vijay Abraham I 	.base = DRA7_USB_OTG_SS2_BASE,
416a17188c1SKishon Vijay Abraham I 	.tx_fifo_resize = false,
417a17188c1SKishon Vijay Abraham I 	.index = 1,
418a17188c1SKishon Vijay Abraham I };
419a17188c1SKishon Vijay Abraham I 
420a17188c1SKishon Vijay Abraham I static struct dwc3_omap_device usb_otg_ss2_glue = {
421a17188c1SKishon Vijay Abraham I 	.base = (void *)DRA7_USB_OTG_SS2_GLUE_BASE,
422a17188c1SKishon Vijay Abraham I 	.utmi_mode = DWC3_OMAP_UTMI_MODE_SW,
423a17188c1SKishon Vijay Abraham I 	.index = 1,
424a17188c1SKishon Vijay Abraham I };
425a17188c1SKishon Vijay Abraham I 
426a17188c1SKishon Vijay Abraham I static struct ti_usb_phy_device usb_phy2_device = {
427a17188c1SKishon Vijay Abraham I 	.usb2_phy_power = (void *)DRA7_USB2_PHY2_POWER,
428a17188c1SKishon Vijay Abraham I 	.index = 1,
429a17188c1SKishon Vijay Abraham I };
430a17188c1SKishon Vijay Abraham I 
431a17188c1SKishon Vijay Abraham I int board_usb_init(int index, enum usb_init_type init)
432a17188c1SKishon Vijay Abraham I {
4336f1af1e3SKishon Vijay Abraham I 	enable_usb_clocks(index);
434a17188c1SKishon Vijay Abraham I 	switch (index) {
435a17188c1SKishon Vijay Abraham I 	case 0:
436a17188c1SKishon Vijay Abraham I 		if (init == USB_INIT_DEVICE) {
437a17188c1SKishon Vijay Abraham I 			usb_otg_ss1.dr_mode = USB_DR_MODE_PERIPHERAL;
438a17188c1SKishon Vijay Abraham I 			usb_otg_ss1_glue.vbus_id_status = OMAP_DWC3_VBUS_VALID;
439a17188c1SKishon Vijay Abraham I 		} else {
440a17188c1SKishon Vijay Abraham I 			usb_otg_ss1.dr_mode = USB_DR_MODE_HOST;
441a17188c1SKishon Vijay Abraham I 			usb_otg_ss1_glue.vbus_id_status = OMAP_DWC3_ID_GROUND;
442a17188c1SKishon Vijay Abraham I 		}
443a17188c1SKishon Vijay Abraham I 
444a17188c1SKishon Vijay Abraham I 		ti_usb_phy_uboot_init(&usb_phy1_device);
445a17188c1SKishon Vijay Abraham I 		dwc3_omap_uboot_init(&usb_otg_ss1_glue);
446a17188c1SKishon Vijay Abraham I 		dwc3_uboot_init(&usb_otg_ss1);
447a17188c1SKishon Vijay Abraham I 		break;
448a17188c1SKishon Vijay Abraham I 	case 1:
449a17188c1SKishon Vijay Abraham I 		if (init == USB_INIT_DEVICE) {
450a17188c1SKishon Vijay Abraham I 			usb_otg_ss2.dr_mode = USB_DR_MODE_PERIPHERAL;
451a17188c1SKishon Vijay Abraham I 			usb_otg_ss2_glue.vbus_id_status = OMAP_DWC3_VBUS_VALID;
452a17188c1SKishon Vijay Abraham I 		} else {
453a17188c1SKishon Vijay Abraham I 			usb_otg_ss2.dr_mode = USB_DR_MODE_HOST;
454a17188c1SKishon Vijay Abraham I 			usb_otg_ss2_glue.vbus_id_status = OMAP_DWC3_ID_GROUND;
455a17188c1SKishon Vijay Abraham I 		}
456a17188c1SKishon Vijay Abraham I 
457a17188c1SKishon Vijay Abraham I 		ti_usb_phy_uboot_init(&usb_phy2_device);
458a17188c1SKishon Vijay Abraham I 		dwc3_omap_uboot_init(&usb_otg_ss2_glue);
459a17188c1SKishon Vijay Abraham I 		dwc3_uboot_init(&usb_otg_ss2);
460a17188c1SKishon Vijay Abraham I 		break;
461a17188c1SKishon Vijay Abraham I 	default:
462a17188c1SKishon Vijay Abraham I 		printf("Invalid Controller Index\n");
463a17188c1SKishon Vijay Abraham I 	}
464a17188c1SKishon Vijay Abraham I 
465a17188c1SKishon Vijay Abraham I 	return 0;
466a17188c1SKishon Vijay Abraham I }
467a17188c1SKishon Vijay Abraham I 
468a17188c1SKishon Vijay Abraham I int board_usb_cleanup(int index, enum usb_init_type init)
469a17188c1SKishon Vijay Abraham I {
470a17188c1SKishon Vijay Abraham I 	switch (index) {
471a17188c1SKishon Vijay Abraham I 	case 0:
472a17188c1SKishon Vijay Abraham I 	case 1:
473a17188c1SKishon Vijay Abraham I 		ti_usb_phy_uboot_exit(index);
474a17188c1SKishon Vijay Abraham I 		dwc3_uboot_exit(index);
475a17188c1SKishon Vijay Abraham I 		dwc3_omap_uboot_exit(index);
476a17188c1SKishon Vijay Abraham I 		break;
477a17188c1SKishon Vijay Abraham I 	default:
478a17188c1SKishon Vijay Abraham I 		printf("Invalid Controller Index\n");
479a17188c1SKishon Vijay Abraham I 	}
4806f1af1e3SKishon Vijay Abraham I 	disable_usb_clocks(index);
481a17188c1SKishon Vijay Abraham I 	return 0;
482a17188c1SKishon Vijay Abraham I }
483a17188c1SKishon Vijay Abraham I 
4842d48aa69SKishon Vijay Abraham I int usb_gadget_handle_interrupts(int index)
485a17188c1SKishon Vijay Abraham I {
486a17188c1SKishon Vijay Abraham I 	u32 status;
487a17188c1SKishon Vijay Abraham I 
4882d48aa69SKishon Vijay Abraham I 	status = dwc3_omap_uboot_interrupt_status(index);
489a17188c1SKishon Vijay Abraham I 	if (status)
4902d48aa69SKishon Vijay Abraham I 		dwc3_uboot_handle_interrupt(index);
491a17188c1SKishon Vijay Abraham I 
492a17188c1SKishon Vijay Abraham I 	return 0;
493a17188c1SKishon Vijay Abraham I }
494a17188c1SKishon Vijay Abraham I #endif
495a17188c1SKishon Vijay Abraham I 
49679b079f3STom Rini #if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_OS_BOOT)
49779b079f3STom Rini int spl_start_uboot(void)
49879b079f3STom Rini {
49979b079f3STom Rini 	/* break into full u-boot on 'c' */
50079b079f3STom Rini 	if (serial_tstc() && serial_getc() == 'c')
50179b079f3STom Rini 		return 1;
50279b079f3STom Rini 
50379b079f3STom Rini #ifdef CONFIG_SPL_ENV_SUPPORT
50479b079f3STom Rini 	env_init();
50579b079f3STom Rini 	env_relocate_spec();
50679b079f3STom Rini 	if (getenv_yesno("boot_os") != 1)
50779b079f3STom Rini 		return 1;
50879b079f3STom Rini #endif
50979b079f3STom Rini 
51079b079f3STom Rini 	return 0;
51179b079f3STom Rini }
51279b079f3STom Rini #endif
51379b079f3STom Rini 
514b1e26e3bSMugunthan V N #ifdef CONFIG_DRIVER_TI_CPSW
5154c8014b9SMugunthan V N extern u32 *const omap_si_rev;
5164c8014b9SMugunthan V N 
517b1e26e3bSMugunthan V N static void cpsw_control(int enabled)
518b1e26e3bSMugunthan V N {
519b1e26e3bSMugunthan V N 	/* VTP can be added here */
520b1e26e3bSMugunthan V N 
521b1e26e3bSMugunthan V N 	return;
522b1e26e3bSMugunthan V N }
523b1e26e3bSMugunthan V N 
524b1e26e3bSMugunthan V N static struct cpsw_slave_data cpsw_slaves[] = {
525b1e26e3bSMugunthan V N 	{
526b1e26e3bSMugunthan V N 		.slave_reg_ofs	= 0x208,
527b1e26e3bSMugunthan V N 		.sliver_reg_ofs	= 0xd80,
5289c653aadSMugunthan V N 		.phy_addr	= 2,
529b1e26e3bSMugunthan V N 	},
530b1e26e3bSMugunthan V N 	{
531b1e26e3bSMugunthan V N 		.slave_reg_ofs	= 0x308,
532b1e26e3bSMugunthan V N 		.sliver_reg_ofs	= 0xdc0,
5339c653aadSMugunthan V N 		.phy_addr	= 3,
534b1e26e3bSMugunthan V N 	},
535b1e26e3bSMugunthan V N };
536b1e26e3bSMugunthan V N 
537b1e26e3bSMugunthan V N static struct cpsw_platform_data cpsw_data = {
538b1e26e3bSMugunthan V N 	.mdio_base		= CPSW_MDIO_BASE,
539b1e26e3bSMugunthan V N 	.cpsw_base		= CPSW_BASE,
540b1e26e3bSMugunthan V N 	.mdio_div		= 0xff,
541b1e26e3bSMugunthan V N 	.channels		= 8,
542b1e26e3bSMugunthan V N 	.cpdma_reg_ofs		= 0x800,
5434c8014b9SMugunthan V N 	.slaves			= 2,
544b1e26e3bSMugunthan V N 	.slave_data		= cpsw_slaves,
545b1e26e3bSMugunthan V N 	.ale_reg_ofs		= 0xd00,
546b1e26e3bSMugunthan V N 	.ale_entries		= 1024,
547b1e26e3bSMugunthan V N 	.host_port_reg_ofs	= 0x108,
548b1e26e3bSMugunthan V N 	.hw_stats_reg_ofs	= 0x900,
549b1e26e3bSMugunthan V N 	.bd_ram_ofs		= 0x2000,
550b1e26e3bSMugunthan V N 	.mac_control		= (1 << 5),
551b1e26e3bSMugunthan V N 	.control		= cpsw_control,
552b1e26e3bSMugunthan V N 	.host_port_num		= 0,
553b1e26e3bSMugunthan V N 	.version		= CPSW_CTRL_VERSION_2,
554b1e26e3bSMugunthan V N };
555b1e26e3bSMugunthan V N 
556b1e26e3bSMugunthan V N int board_eth_init(bd_t *bis)
557b1e26e3bSMugunthan V N {
558b1e26e3bSMugunthan V N 	int ret;
559b1e26e3bSMugunthan V N 	uint8_t mac_addr[6];
560b1e26e3bSMugunthan V N 	uint32_t mac_hi, mac_lo;
561b1e26e3bSMugunthan V N 	uint32_t ctrl_val;
562b1e26e3bSMugunthan V N 
563b1e26e3bSMugunthan V N 	/* try reading mac address from efuse */
564b1e26e3bSMugunthan V N 	mac_lo = readl((*ctrl)->control_core_mac_id_0_lo);
565b1e26e3bSMugunthan V N 	mac_hi = readl((*ctrl)->control_core_mac_id_0_hi);
566e0a1d598SMugunthan V N 	mac_addr[0] = (mac_hi & 0xFF0000) >> 16;
567b1e26e3bSMugunthan V N 	mac_addr[1] = (mac_hi & 0xFF00) >> 8;
568e0a1d598SMugunthan V N 	mac_addr[2] = mac_hi & 0xFF;
569e0a1d598SMugunthan V N 	mac_addr[3] = (mac_lo & 0xFF0000) >> 16;
570b1e26e3bSMugunthan V N 	mac_addr[4] = (mac_lo & 0xFF00) >> 8;
571e0a1d598SMugunthan V N 	mac_addr[5] = mac_lo & 0xFF;
572b1e26e3bSMugunthan V N 
573b1e26e3bSMugunthan V N 	if (!getenv("ethaddr")) {
574b1e26e3bSMugunthan V N 		printf("<ethaddr> not set. Validating first E-fuse MAC\n");
575b1e26e3bSMugunthan V N 
5760adb5b76SJoe Hershberger 		if (is_valid_ethaddr(mac_addr))
577b1e26e3bSMugunthan V N 			eth_setenv_enetaddr("ethaddr", mac_addr);
578b1e26e3bSMugunthan V N 	}
5798feb37b9SMugunthan V N 
5808feb37b9SMugunthan V N 	mac_lo = readl((*ctrl)->control_core_mac_id_1_lo);
5818feb37b9SMugunthan V N 	mac_hi = readl((*ctrl)->control_core_mac_id_1_hi);
5828feb37b9SMugunthan V N 	mac_addr[0] = (mac_hi & 0xFF0000) >> 16;
5838feb37b9SMugunthan V N 	mac_addr[1] = (mac_hi & 0xFF00) >> 8;
5848feb37b9SMugunthan V N 	mac_addr[2] = mac_hi & 0xFF;
5858feb37b9SMugunthan V N 	mac_addr[3] = (mac_lo & 0xFF0000) >> 16;
5868feb37b9SMugunthan V N 	mac_addr[4] = (mac_lo & 0xFF00) >> 8;
5878feb37b9SMugunthan V N 	mac_addr[5] = mac_lo & 0xFF;
5888feb37b9SMugunthan V N 
5898feb37b9SMugunthan V N 	if (!getenv("eth1addr")) {
5900adb5b76SJoe Hershberger 		if (is_valid_ethaddr(mac_addr))
5918feb37b9SMugunthan V N 			eth_setenv_enetaddr("eth1addr", mac_addr);
5928feb37b9SMugunthan V N 	}
5938feb37b9SMugunthan V N 
594b1e26e3bSMugunthan V N 	ctrl_val = readl((*ctrl)->control_core_control_io1) & (~0x33);
595b1e26e3bSMugunthan V N 	ctrl_val |= 0x22;
596b1e26e3bSMugunthan V N 	writel(ctrl_val, (*ctrl)->control_core_control_io1);
597b1e26e3bSMugunthan V N 
5984c8014b9SMugunthan V N 	if (*omap_si_rev == DRA722_ES1_0)
5994c8014b9SMugunthan V N 		cpsw_data.active_slave = 1;
6004c8014b9SMugunthan V N 
601b1e26e3bSMugunthan V N 	ret = cpsw_register(&cpsw_data);
602b1e26e3bSMugunthan V N 	if (ret < 0)
603b1e26e3bSMugunthan V N 		printf("Error %d registering CPSW switch\n", ret);
604b1e26e3bSMugunthan V N 
605b1e26e3bSMugunthan V N 	return ret;
606b1e26e3bSMugunthan V N }
607b1e26e3bSMugunthan V N #endif
6087b922523SLokesh Vutla 
6097b922523SLokesh Vutla #ifdef CONFIG_BOARD_EARLY_INIT_F
6107b922523SLokesh Vutla /* VTT regulator enable */
6117b922523SLokesh Vutla static inline void vtt_regulator_enable(void)
6127b922523SLokesh Vutla {
6137b922523SLokesh Vutla 	if (omap_hw_init_context() == OMAP_INIT_CONTEXT_UBOOT_AFTER_SPL)
6147b922523SLokesh Vutla 		return;
6157b922523SLokesh Vutla 
6167b922523SLokesh Vutla 	/* Do not enable VTT for DRA722 */
6177b922523SLokesh Vutla 	if (omap_revision() == DRA722_ES1_0)
6187b922523SLokesh Vutla 		return;
6197b922523SLokesh Vutla 
6207b922523SLokesh Vutla 	/*
6217b922523SLokesh Vutla 	 * EVM Rev G and later use gpio7_11 for DDR3 termination.
6227b922523SLokesh Vutla 	 * This is safe enough to do on older revs.
6237b922523SLokesh Vutla 	 */
6247b922523SLokesh Vutla 	gpio_request(GPIO_DDR_VTT_EN, "ddr_vtt_en");
6257b922523SLokesh Vutla 	gpio_direction_output(GPIO_DDR_VTT_EN, 1);
6267b922523SLokesh Vutla }
6277b922523SLokesh Vutla 
6287b922523SLokesh Vutla int board_early_init_f(void)
6297b922523SLokesh Vutla {
6307b922523SLokesh Vutla 	vtt_regulator_enable();
6317b922523SLokesh Vutla 	return 0;
6327b922523SLokesh Vutla }
6337b922523SLokesh Vutla #endif
634