blob: d142cccb939529f5fe87dbb87c840f142afb538a [file] [log] [blame]
Lokesh Vutla687054a2013-02-12 21:29:08 +00001/*
2 * (C) Copyright 2013
3 * Texas Instruments Incorporated, <www.ti.com>
4 *
5 * Lokesh Vutla <lokeshvutla@ti.com>
6 *
7 * Based on previous work by:
8 * Aneesh V <aneesh@ti.com>
9 * Steve Sakoman <steve@sakoman.com>
10 *
Wolfgang Denk1a459662013-07-08 09:37:19 +020011 * SPDX-License-Identifier: GPL-2.0+
Lokesh Vutla687054a2013-02-12 21:29:08 +000012 */
13#include <common.h>
Nishanth Menoncb199102013-03-26 05:20:54 +000014#include <palmas.h>
Dan Murphye9024ef2014-02-03 06:59:02 -060015#include <sata.h>
Lokesh Vutla25afe552016-03-08 09:18:05 +053016#include <linux/string.h>
Lokesh Vutla7b922522014-08-04 19:42:24 +053017#include <asm/gpio.h>
Kishon Vijay Abraham Ia17188c2015-02-23 18:40:19 +053018#include <usb.h>
19#include <linux/usb/gadget.h>
Lokesh Vutla7b922522014-08-04 19:42:24 +053020#include <asm/arch/gpio.h>
Lokesh Vutla706dd342015-06-04 16:42:38 +053021#include <asm/arch/dra7xx_iodelay.h>
Lokesh Vutlaa7638832016-03-08 09:18:06 +053022#include <asm/emif.h>
Lokesh Vutla687054a2013-02-12 21:29:08 +000023#include <asm/arch/sys_proto.h>
24#include <asm/arch/mmc_host_def.h>
Roger Quadros21914ee2013-11-11 16:56:44 +020025#include <asm/arch/sata.h>
Tom Rini79b079f2014-04-03 07:52:56 -040026#include <environment.h>
Kishon Vijay Abraham Ia17188c2015-02-23 18:40:19 +053027#include <dwc3-uboot.h>
28#include <dwc3-omap-uboot.h>
29#include <ti-usb-phy-uboot.h>
Lokesh Vutla687054a2013-02-12 21:29:08 +000030
31#include "mux_data.h"
Lokesh Vutla25afe552016-03-08 09:18:05 +053032#include "../common/board_detect.h"
33
34#define board_is_dra74x_evm() board_ti_is("5777xCPU")
35#define board_is_dra74x_revh_or_later() board_is_dra74x_evm() && \
36 (strncmp("H", board_ti_get_rev(), 1) <= 0)
Lokesh Vutlac4a27362016-03-08 09:18:08 +053037#define board_ti_get_emif_size() board_ti_get_emif1_size() + \
38 board_ti_get_emif2_size()
Lokesh Vutla687054a2013-02-12 21:29:08 +000039
Mugunthan V Nb1e26e32013-07-08 16:04:41 +053040#ifdef CONFIG_DRIVER_TI_CPSW
41#include <cpsw.h>
42#endif
43
Lokesh Vutla687054a2013-02-12 21:29:08 +000044DECLARE_GLOBAL_DATA_PTR;
45
Lokesh Vutla7b922522014-08-04 19:42:24 +053046/* GPIO 7_11 */
47#define GPIO_DDR_VTT_EN 203
48
Lokesh Vutla25afe552016-03-08 09:18:05 +053049#define SYSINFO_BOARD_NAME_MAX_LEN 37
50
Lokesh Vutla687054a2013-02-12 21:29:08 +000051const struct omap_sysinfo sysinfo = {
Lokesh Vutla25afe552016-03-08 09:18:05 +053052 "Board: UNKNOWN(DRA7 EVM) REV UNKNOWN\n"
Lokesh Vutla687054a2013-02-12 21:29:08 +000053};
54
Lokesh Vutlaa7638832016-03-08 09:18:06 +053055static const struct emif_regs emif1_ddr3_532_mhz_1cs = {
56 .sdram_config_init = 0x61851ab2,
57 .sdram_config = 0x61851ab2,
58 .sdram_config2 = 0x08000000,
59 .ref_ctrl = 0x000040F1,
60 .ref_ctrl_final = 0x00001035,
61 .sdram_tim1 = 0xCCCF36B3,
62 .sdram_tim2 = 0x308F7FDA,
63 .sdram_tim3 = 0x427F88A8,
64 .read_idle_ctrl = 0x00050000,
65 .zq_config = 0x0007190B,
66 .temp_alert_config = 0x00000000,
67 .emif_ddr_phy_ctlr_1_init = 0x0024400B,
68 .emif_ddr_phy_ctlr_1 = 0x0E24400B,
69 .emif_ddr_ext_phy_ctrl_1 = 0x10040100,
70 .emif_ddr_ext_phy_ctrl_2 = 0x00910091,
71 .emif_ddr_ext_phy_ctrl_3 = 0x00950095,
72 .emif_ddr_ext_phy_ctrl_4 = 0x009B009B,
73 .emif_ddr_ext_phy_ctrl_5 = 0x009E009E,
74 .emif_rd_wr_lvl_rmp_win = 0x00000000,
75 .emif_rd_wr_lvl_rmp_ctl = 0x80000000,
76 .emif_rd_wr_lvl_ctl = 0x00000000,
77 .emif_rd_wr_exec_thresh = 0x00000305
78};
79
80static const struct emif_regs emif2_ddr3_532_mhz_1cs = {
81 .sdram_config_init = 0x61851B32,
82 .sdram_config = 0x61851B32,
83 .sdram_config2 = 0x08000000,
84 .ref_ctrl = 0x000040F1,
85 .ref_ctrl_final = 0x00001035,
86 .sdram_tim1 = 0xCCCF36B3,
87 .sdram_tim2 = 0x308F7FDA,
88 .sdram_tim3 = 0x427F88A8,
89 .read_idle_ctrl = 0x00050000,
90 .zq_config = 0x0007190B,
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
103};
104
105static const struct emif_regs emif_1_regs_ddr3_666_mhz_1cs_dra_es1 = {
106 .sdram_config_init = 0x61862B32,
107 .sdram_config = 0x61862B32,
108 .sdram_config2 = 0x08000000,
109 .ref_ctrl = 0x0000514C,
110 .ref_ctrl_final = 0x0000144A,
111 .sdram_tim1 = 0xD113781C,
112 .sdram_tim2 = 0x30717FE3,
113 .sdram_tim3 = 0x409F86A8,
114 .read_idle_ctrl = 0x00050000,
115 .zq_config = 0x5007190B,
116 .temp_alert_config = 0x00000000,
117 .emif_ddr_phy_ctlr_1_init = 0x0024400D,
118 .emif_ddr_phy_ctlr_1 = 0x0E24400D,
119 .emif_ddr_ext_phy_ctrl_1 = 0x10040100,
120 .emif_ddr_ext_phy_ctrl_2 = 0x00A400A4,
121 .emif_ddr_ext_phy_ctrl_3 = 0x00A900A9,
122 .emif_ddr_ext_phy_ctrl_4 = 0x00B000B0,
123 .emif_ddr_ext_phy_ctrl_5 = 0x00B000B0,
124 .emif_rd_wr_lvl_rmp_win = 0x00000000,
125 .emif_rd_wr_lvl_rmp_ctl = 0x80000000,
126 .emif_rd_wr_lvl_ctl = 0x00000000,
127 .emif_rd_wr_exec_thresh = 0x00000305
128};
129
Lokesh Vutlac4a27362016-03-08 09:18:08 +0530130const struct emif_regs emif1_ddr3_532_mhz_1cs_2G = {
131 .sdram_config_init = 0x61851ab2,
132 .sdram_config = 0x61851ab2,
133 .sdram_config2 = 0x08000000,
134 .ref_ctrl = 0x000040F1,
135 .ref_ctrl_final = 0x00001035,
136 .sdram_tim1 = 0xCCCF36B3,
137 .sdram_tim2 = 0x30BF7FDA,
138 .sdram_tim3 = 0x427F8BA8,
139 .read_idle_ctrl = 0x00050000,
140 .zq_config = 0x0007190B,
141 .temp_alert_config = 0x00000000,
142 .emif_ddr_phy_ctlr_1_init = 0x0024400B,
143 .emif_ddr_phy_ctlr_1 = 0x0E24400B,
144 .emif_ddr_ext_phy_ctrl_1 = 0x10040100,
145 .emif_ddr_ext_phy_ctrl_2 = 0x00910091,
146 .emif_ddr_ext_phy_ctrl_3 = 0x00950095,
147 .emif_ddr_ext_phy_ctrl_4 = 0x009B009B,
148 .emif_ddr_ext_phy_ctrl_5 = 0x009E009E,
149 .emif_rd_wr_lvl_rmp_win = 0x00000000,
150 .emif_rd_wr_lvl_rmp_ctl = 0x80000000,
151 .emif_rd_wr_lvl_ctl = 0x00000000,
152 .emif_rd_wr_exec_thresh = 0x00000305
153};
154
155const struct emif_regs emif2_ddr3_532_mhz_1cs_2G = {
156 .sdram_config_init = 0x61851B32,
157 .sdram_config = 0x61851B32,
158 .sdram_config2 = 0x08000000,
159 .ref_ctrl = 0x000040F1,
160 .ref_ctrl_final = 0x00001035,
161 .sdram_tim1 = 0xCCCF36B3,
162 .sdram_tim2 = 0x308F7FDA,
163 .sdram_tim3 = 0x427F88A8,
164 .read_idle_ctrl = 0x00050000,
165 .zq_config = 0x0007190B,
166 .temp_alert_config = 0x00000000,
167 .emif_ddr_phy_ctlr_1_init = 0x0024400B,
168 .emif_ddr_phy_ctlr_1 = 0x0E24400B,
169 .emif_ddr_ext_phy_ctrl_1 = 0x10040100,
170 .emif_ddr_ext_phy_ctrl_2 = 0x00910091,
171 .emif_ddr_ext_phy_ctrl_3 = 0x00950095,
172 .emif_ddr_ext_phy_ctrl_4 = 0x009B009B,
173 .emif_ddr_ext_phy_ctrl_5 = 0x009E009E,
174 .emif_rd_wr_lvl_rmp_win = 0x00000000,
175 .emif_rd_wr_lvl_rmp_ctl = 0x80000000,
176 .emif_rd_wr_lvl_ctl = 0x00000000,
177 .emif_rd_wr_exec_thresh = 0x00000305
178};
179
Lokesh Vutlaa7638832016-03-08 09:18:06 +0530180void emif_get_reg_dump(u32 emif_nr, const struct emif_regs **regs)
181{
Lokesh Vutlac4a27362016-03-08 09:18:08 +0530182 u64 ram_size;
183
184 ram_size = board_ti_get_emif_size();
185
Lokesh Vutlaa7638832016-03-08 09:18:06 +0530186 switch (omap_revision()) {
187 case DRA752_ES1_0:
188 case DRA752_ES1_1:
189 case DRA752_ES2_0:
190 switch (emif_nr) {
191 case 1:
Lokesh Vutlac4a27362016-03-08 09:18:08 +0530192 if (ram_size > CONFIG_MAX_MEM_MAPPED)
193 *regs = &emif1_ddr3_532_mhz_1cs_2G;
194 else
195 *regs = &emif1_ddr3_532_mhz_1cs;
Lokesh Vutlaa7638832016-03-08 09:18:06 +0530196 break;
197 case 2:
Lokesh Vutlac4a27362016-03-08 09:18:08 +0530198 if (ram_size > CONFIG_MAX_MEM_MAPPED)
199 *regs = &emif2_ddr3_532_mhz_1cs_2G;
200 else
201 *regs = &emif2_ddr3_532_mhz_1cs;
Lokesh Vutlaa7638832016-03-08 09:18:06 +0530202 break;
203 }
204 break;
205 case DRA722_ES1_0:
206 *regs = &emif_1_regs_ddr3_666_mhz_1cs_dra_es1;
207 break;
208 default:
209 *regs = &emif1_ddr3_532_mhz_1cs;
210 }
211}
212
213static const struct dmm_lisa_map_regs lisa_map_dra7_1536MB = {
214 .dmm_lisa_map_0 = 0x0,
215 .dmm_lisa_map_1 = 0x80640300,
216 .dmm_lisa_map_2 = 0xC0500220,
217 .dmm_lisa_map_3 = 0xFF020100,
218 .is_ma_present = 0x1
219};
220
221static const struct dmm_lisa_map_regs lisa_map_2G_x_2 = {
222 .dmm_lisa_map_0 = 0x0,
223 .dmm_lisa_map_1 = 0x0,
224 .dmm_lisa_map_2 = 0x80600100,
225 .dmm_lisa_map_3 = 0xFF020100,
226 .is_ma_present = 0x1
227};
228
Lokesh Vutlac4a27362016-03-08 09:18:08 +0530229const struct dmm_lisa_map_regs lisa_map_dra7_2GB = {
230 .dmm_lisa_map_0 = 0x0,
231 .dmm_lisa_map_1 = 0x0,
232 .dmm_lisa_map_2 = 0x80740300,
233 .dmm_lisa_map_3 = 0xFF020100,
234 .is_ma_present = 0x1
235};
236
Lokesh Vutlaa7638832016-03-08 09:18:06 +0530237void emif_get_dmm_regs(const struct dmm_lisa_map_regs **dmm_lisa_regs)
238{
Lokesh Vutlac4a27362016-03-08 09:18:08 +0530239 u64 ram_size;
240
241 ram_size = board_ti_get_emif_size();
242
Lokesh Vutlaa7638832016-03-08 09:18:06 +0530243 switch (omap_revision()) {
244 case DRA752_ES1_0:
245 case DRA752_ES1_1:
246 case DRA752_ES2_0:
Lokesh Vutlac4a27362016-03-08 09:18:08 +0530247 if (ram_size > CONFIG_MAX_MEM_MAPPED)
248 *dmm_lisa_regs = &lisa_map_dra7_2GB;
249 else
250 *dmm_lisa_regs = &lisa_map_dra7_1536MB;
Lokesh Vutlaa7638832016-03-08 09:18:06 +0530251 break;
252 case DRA722_ES1_0:
253 default:
254 *dmm_lisa_regs = &lisa_map_2G_x_2;
255 }
256}
257
Lokesh Vutla687054a2013-02-12 21:29:08 +0000258/**
259 * @brief board_init
260 *
261 * @return 0
262 */
263int board_init(void)
264{
265 gpmc_init();
266 gd->bd->bi_boot_params = (0x80000000 + 0x100); /* boot param addr */
267
268 return 0;
269}
270
Roger Quadros21914ee2013-11-11 16:56:44 +0200271int board_late_init(void)
272{
Lokesh Vutla4ec3f6e2014-07-14 19:57:58 +0530273#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
Lokesh Vutla25afe552016-03-08 09:18:05 +0530274 char *name = "unknown";
275
276 if (is_dra72x())
277 name = "dra72x";
Lokesh Vutla4ec3f6e2014-07-14 19:57:58 +0530278 else
Lokesh Vutla25afe552016-03-08 09:18:05 +0530279 name = "dra7xx";
280
281 set_board_info_env(name);
Dileep Kattaf12467d2015-03-25 04:04:51 +0530282
Paul Kocialkowski07815eb2015-08-27 19:37:12 +0200283 omap_die_id_serial();
Lokesh Vutla4ec3f6e2014-07-14 19:57:58 +0530284#endif
Roger Quadros21914ee2013-11-11 16:56:44 +0200285 return 0;
286}
287
Lokesh Vutla25afe552016-03-08 09:18:05 +0530288#ifdef CONFIG_SPL_BUILD
289void do_board_detect(void)
290{
291 int rc;
292
293 rc = ti_i2c_eeprom_dra7_get(CONFIG_EEPROM_BUS_ADDRESS,
294 CONFIG_EEPROM_CHIP_ADDRESS);
295 if (rc)
296 printf("ti_i2c_eeprom_init failed %d\n", rc);
297}
298
299#else
300
301void do_board_detect(void)
302{
303 char *bname = NULL;
304 int rc;
305
306 rc = ti_i2c_eeprom_dra7_get(CONFIG_EEPROM_BUS_ADDRESS,
307 CONFIG_EEPROM_CHIP_ADDRESS);
308 if (rc)
309 printf("ti_i2c_eeprom_init failed %d\n", rc);
310
311 if (board_is_dra74x_evm()) {
312 bname = "DRA74x EVM";
313 /* If EEPROM is not populated */
314 } else {
315 if (is_dra72x())
316 bname = "DRA72x EVM";
317 else
318 bname = "DRA74x EVM";
319 }
320
321 if (bname)
322 snprintf(sysinfo.board_string, SYSINFO_BOARD_NAME_MAX_LEN,
323 "Board: %s REV %s\n", bname, board_ti_get_rev());
324}
325#endif /* CONFIG_SPL_BUILD */
326
Lokesh Vutla687054a2013-02-12 21:29:08 +0000327void set_muxconf_regs_essential(void)
328{
329 do_set_mux32((*ctrl)->control_padconf_core_base,
Lokesh Vutla706dd342015-06-04 16:42:38 +0530330 early_padconf, ARRAY_SIZE(early_padconf));
Lokesh Vutla687054a2013-02-12 21:29:08 +0000331}
332
Lokesh Vutla706dd342015-06-04 16:42:38 +0530333#ifdef CONFIG_IODELAY_RECALIBRATION
334void recalibrate_iodelay(void)
335{
Nishanth Menon03589232015-08-13 09:50:59 -0500336 struct pad_conf_entry const *pads;
337 struct iodelay_cfg_entry const *iodelay;
338 int npads, niodelays;
339
340 switch (omap_revision()) {
341 case DRA722_ES1_0:
342 pads = core_padconf_array_essential;
343 npads = ARRAY_SIZE(core_padconf_array_essential);
344 iodelay = iodelay_cfg_array;
345 niodelays = ARRAY_SIZE(iodelay_cfg_array);
346 break;
347 case DRA752_ES1_0:
348 case DRA752_ES1_1:
349 pads = dra74x_core_padconf_array;
350 npads = ARRAY_SIZE(dra74x_core_padconf_array);
351 iodelay = dra742_es1_1_iodelay_cfg_array;
352 niodelays = ARRAY_SIZE(dra742_es1_1_iodelay_cfg_array);
353 break;
354 default:
355 case DRA752_ES2_0:
356 pads = dra74x_core_padconf_array;
357 npads = ARRAY_SIZE(dra74x_core_padconf_array);
358 iodelay = dra742_es2_0_iodelay_cfg_array;
359 niodelays = ARRAY_SIZE(dra742_es2_0_iodelay_cfg_array);
Nishanth Menon76cff2b2015-08-13 09:51:00 -0500360 /* Setup port1 and port2 for rgmii with 'no-id' mode */
361 clrset_spare_register(1, 0, RGMII2_ID_MODE_N_MASK |
362 RGMII1_ID_MODE_N_MASK);
Nishanth Menon03589232015-08-13 09:50:59 -0500363 break;
Nishanth Menon27d170a2015-06-04 16:42:39 +0530364 }
Nishanth Menon03589232015-08-13 09:50:59 -0500365 __recalibrate_iodelay(pads, npads, iodelay, niodelays);
Lokesh Vutla706dd342015-06-04 16:42:38 +0530366}
367#endif
368
Lokesh Vutla687054a2013-02-12 21:29:08 +0000369#if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_GENERIC_MMC)
370int board_mmc_init(bd_t *bis)
371{
372 omap_mmc_init(0, 0, 0, -1, -1);
373 omap_mmc_init(1, 0, 0, -1, -1);
374 return 0;
375}
376#endif
Mugunthan V Nb1e26e32013-07-08 16:04:41 +0530377
Kishon Vijay Abraham Ia17188c2015-02-23 18:40:19 +0530378#ifdef CONFIG_USB_DWC3
379static struct dwc3_device usb_otg_ss1 = {
380 .maximum_speed = USB_SPEED_SUPER,
381 .base = DRA7_USB_OTG_SS1_BASE,
382 .tx_fifo_resize = false,
383 .index = 0,
384};
385
386static struct dwc3_omap_device usb_otg_ss1_glue = {
387 .base = (void *)DRA7_USB_OTG_SS1_GLUE_BASE,
388 .utmi_mode = DWC3_OMAP_UTMI_MODE_SW,
Kishon Vijay Abraham Ia17188c2015-02-23 18:40:19 +0530389 .index = 0,
390};
391
392static struct ti_usb_phy_device usb_phy1_device = {
393 .pll_ctrl_base = (void *)DRA7_USB3_PHY1_PLL_CTRL,
394 .usb2_phy_power = (void *)DRA7_USB2_PHY1_POWER,
395 .usb3_phy_power = (void *)DRA7_USB3_PHY1_POWER,
396 .index = 0,
397};
398
399static struct dwc3_device usb_otg_ss2 = {
400 .maximum_speed = USB_SPEED_SUPER,
401 .base = DRA7_USB_OTG_SS2_BASE,
402 .tx_fifo_resize = false,
403 .index = 1,
404};
405
406static struct dwc3_omap_device usb_otg_ss2_glue = {
407 .base = (void *)DRA7_USB_OTG_SS2_GLUE_BASE,
408 .utmi_mode = DWC3_OMAP_UTMI_MODE_SW,
Kishon Vijay Abraham Ia17188c2015-02-23 18:40:19 +0530409 .index = 1,
410};
411
412static struct ti_usb_phy_device usb_phy2_device = {
413 .usb2_phy_power = (void *)DRA7_USB2_PHY2_POWER,
414 .index = 1,
415};
416
417int board_usb_init(int index, enum usb_init_type init)
418{
Kishon Vijay Abraham I6f1af1e2015-08-19 16:16:27 +0530419 enable_usb_clocks(index);
Kishon Vijay Abraham Ia17188c2015-02-23 18:40:19 +0530420 switch (index) {
421 case 0:
422 if (init == USB_INIT_DEVICE) {
423 usb_otg_ss1.dr_mode = USB_DR_MODE_PERIPHERAL;
424 usb_otg_ss1_glue.vbus_id_status = OMAP_DWC3_VBUS_VALID;
425 } else {
426 usb_otg_ss1.dr_mode = USB_DR_MODE_HOST;
427 usb_otg_ss1_glue.vbus_id_status = OMAP_DWC3_ID_GROUND;
428 }
429
430 ti_usb_phy_uboot_init(&usb_phy1_device);
431 dwc3_omap_uboot_init(&usb_otg_ss1_glue);
432 dwc3_uboot_init(&usb_otg_ss1);
433 break;
434 case 1:
435 if (init == USB_INIT_DEVICE) {
436 usb_otg_ss2.dr_mode = USB_DR_MODE_PERIPHERAL;
437 usb_otg_ss2_glue.vbus_id_status = OMAP_DWC3_VBUS_VALID;
438 } else {
439 usb_otg_ss2.dr_mode = USB_DR_MODE_HOST;
440 usb_otg_ss2_glue.vbus_id_status = OMAP_DWC3_ID_GROUND;
441 }
442
443 ti_usb_phy_uboot_init(&usb_phy2_device);
444 dwc3_omap_uboot_init(&usb_otg_ss2_glue);
445 dwc3_uboot_init(&usb_otg_ss2);
446 break;
447 default:
448 printf("Invalid Controller Index\n");
449 }
450
451 return 0;
452}
453
454int board_usb_cleanup(int index, enum usb_init_type init)
455{
456 switch (index) {
457 case 0:
458 case 1:
459 ti_usb_phy_uboot_exit(index);
460 dwc3_uboot_exit(index);
461 dwc3_omap_uboot_exit(index);
462 break;
463 default:
464 printf("Invalid Controller Index\n");
465 }
Kishon Vijay Abraham I6f1af1e2015-08-19 16:16:27 +0530466 disable_usb_clocks(index);
Kishon Vijay Abraham Ia17188c2015-02-23 18:40:19 +0530467 return 0;
468}
469
Kishon Vijay Abraham I2d48aa62015-02-23 18:40:23 +0530470int usb_gadget_handle_interrupts(int index)
Kishon Vijay Abraham Ia17188c2015-02-23 18:40:19 +0530471{
472 u32 status;
473
Kishon Vijay Abraham I2d48aa62015-02-23 18:40:23 +0530474 status = dwc3_omap_uboot_interrupt_status(index);
Kishon Vijay Abraham Ia17188c2015-02-23 18:40:19 +0530475 if (status)
Kishon Vijay Abraham I2d48aa62015-02-23 18:40:23 +0530476 dwc3_uboot_handle_interrupt(index);
Kishon Vijay Abraham Ia17188c2015-02-23 18:40:19 +0530477
478 return 0;
479}
480#endif
481
Tom Rini79b079f2014-04-03 07:52:56 -0400482#if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_OS_BOOT)
483int spl_start_uboot(void)
484{
485 /* break into full u-boot on 'c' */
486 if (serial_tstc() && serial_getc() == 'c')
487 return 1;
488
489#ifdef CONFIG_SPL_ENV_SUPPORT
490 env_init();
491 env_relocate_spec();
492 if (getenv_yesno("boot_os") != 1)
493 return 1;
494#endif
495
496 return 0;
497}
498#endif
499
Mugunthan V Nb1e26e32013-07-08 16:04:41 +0530500#ifdef CONFIG_DRIVER_TI_CPSW
Mugunthan V N4c8014b2014-05-22 14:37:12 +0530501extern u32 *const omap_si_rev;
502
Mugunthan V Nb1e26e32013-07-08 16:04:41 +0530503static void cpsw_control(int enabled)
504{
505 /* VTP can be added here */
506
507 return;
508}
509
510static struct cpsw_slave_data cpsw_slaves[] = {
511 {
512 .slave_reg_ofs = 0x208,
513 .sliver_reg_ofs = 0xd80,
Mugunthan V N9c653aa2014-02-18 07:31:52 -0500514 .phy_addr = 2,
Mugunthan V Nb1e26e32013-07-08 16:04:41 +0530515 },
516 {
517 .slave_reg_ofs = 0x308,
518 .sliver_reg_ofs = 0xdc0,
Mugunthan V N9c653aa2014-02-18 07:31:52 -0500519 .phy_addr = 3,
Mugunthan V Nb1e26e32013-07-08 16:04:41 +0530520 },
521};
522
523static struct cpsw_platform_data cpsw_data = {
524 .mdio_base = CPSW_MDIO_BASE,
525 .cpsw_base = CPSW_BASE,
526 .mdio_div = 0xff,
527 .channels = 8,
528 .cpdma_reg_ofs = 0x800,
Mugunthan V N4c8014b2014-05-22 14:37:12 +0530529 .slaves = 2,
Mugunthan V Nb1e26e32013-07-08 16:04:41 +0530530 .slave_data = cpsw_slaves,
531 .ale_reg_ofs = 0xd00,
532 .ale_entries = 1024,
533 .host_port_reg_ofs = 0x108,
534 .hw_stats_reg_ofs = 0x900,
535 .bd_ram_ofs = 0x2000,
536 .mac_control = (1 << 5),
537 .control = cpsw_control,
538 .host_port_num = 0,
539 .version = CPSW_CTRL_VERSION_2,
540};
541
542int board_eth_init(bd_t *bis)
543{
544 int ret;
545 uint8_t mac_addr[6];
546 uint32_t mac_hi, mac_lo;
547 uint32_t ctrl_val;
Mugunthan V Nb1e26e32013-07-08 16:04:41 +0530548
549 /* try reading mac address from efuse */
550 mac_lo = readl((*ctrl)->control_core_mac_id_0_lo);
551 mac_hi = readl((*ctrl)->control_core_mac_id_0_hi);
Mugunthan V Ne0a1d592014-01-07 19:57:38 +0530552 mac_addr[0] = (mac_hi & 0xFF0000) >> 16;
Mugunthan V Nb1e26e32013-07-08 16:04:41 +0530553 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
Mugunthan V Ne0a1d592014-01-07 19:57:38 +0530554 mac_addr[2] = mac_hi & 0xFF;
555 mac_addr[3] = (mac_lo & 0xFF0000) >> 16;
Mugunthan V Nb1e26e32013-07-08 16:04:41 +0530556 mac_addr[4] = (mac_lo & 0xFF00) >> 8;
Mugunthan V Ne0a1d592014-01-07 19:57:38 +0530557 mac_addr[5] = mac_lo & 0xFF;
Mugunthan V Nb1e26e32013-07-08 16:04:41 +0530558
559 if (!getenv("ethaddr")) {
560 printf("<ethaddr> not set. Validating first E-fuse MAC\n");
561
Joe Hershberger0adb5b72015-04-08 01:41:04 -0500562 if (is_valid_ethaddr(mac_addr))
Mugunthan V Nb1e26e32013-07-08 16:04:41 +0530563 eth_setenv_enetaddr("ethaddr", mac_addr);
564 }
Mugunthan V N8feb37b2014-02-18 07:31:56 -0500565
566 mac_lo = readl((*ctrl)->control_core_mac_id_1_lo);
567 mac_hi = readl((*ctrl)->control_core_mac_id_1_hi);
568 mac_addr[0] = (mac_hi & 0xFF0000) >> 16;
569 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
570 mac_addr[2] = mac_hi & 0xFF;
571 mac_addr[3] = (mac_lo & 0xFF0000) >> 16;
572 mac_addr[4] = (mac_lo & 0xFF00) >> 8;
573 mac_addr[5] = mac_lo & 0xFF;
574
575 if (!getenv("eth1addr")) {
Joe Hershberger0adb5b72015-04-08 01:41:04 -0500576 if (is_valid_ethaddr(mac_addr))
Mugunthan V N8feb37b2014-02-18 07:31:56 -0500577 eth_setenv_enetaddr("eth1addr", mac_addr);
578 }
579
Mugunthan V Nb1e26e32013-07-08 16:04:41 +0530580 ctrl_val = readl((*ctrl)->control_core_control_io1) & (~0x33);
581 ctrl_val |= 0x22;
582 writel(ctrl_val, (*ctrl)->control_core_control_io1);
583
Mugunthan V N4c8014b2014-05-22 14:37:12 +0530584 if (*omap_si_rev == DRA722_ES1_0)
585 cpsw_data.active_slave = 1;
586
Mugunthan V Nb1e26e32013-07-08 16:04:41 +0530587 ret = cpsw_register(&cpsw_data);
588 if (ret < 0)
589 printf("Error %d registering CPSW switch\n", ret);
590
591 return ret;
592}
593#endif
Lokesh Vutla7b922522014-08-04 19:42:24 +0530594
595#ifdef CONFIG_BOARD_EARLY_INIT_F
596/* VTT regulator enable */
597static inline void vtt_regulator_enable(void)
598{
599 if (omap_hw_init_context() == OMAP_INIT_CONTEXT_UBOOT_AFTER_SPL)
600 return;
601
602 /* Do not enable VTT for DRA722 */
603 if (omap_revision() == DRA722_ES1_0)
604 return;
605
606 /*
607 * EVM Rev G and later use gpio7_11 for DDR3 termination.
608 * This is safe enough to do on older revs.
609 */
610 gpio_request(GPIO_DDR_VTT_EN, "ddr_vtt_en");
611 gpio_direction_output(GPIO_DDR_VTT_EN, 1);
612}
613
614int board_early_init_f(void)
615{
616 vtt_regulator_enable();
617 return 0;
618}
619#endif