blob: a47122b27c0dd8d8014c1534bd1cdcb91d72a319 [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 Vutla687054a2013-02-12 21:29:08 +000022#include <asm/arch/sys_proto.h>
23#include <asm/arch/mmc_host_def.h>
Roger Quadros21914ee2013-11-11 16:56:44 +020024#include <asm/arch/sata.h>
Tom Rini79b079f2014-04-03 07:52:56 -040025#include <environment.h>
Kishon Vijay Abraham Ia17188c2015-02-23 18:40:19 +053026#include <dwc3-uboot.h>
27#include <dwc3-omap-uboot.h>
28#include <ti-usb-phy-uboot.h>
Lokesh Vutla687054a2013-02-12 21:29:08 +000029
30#include "mux_data.h"
Lokesh Vutla25afe552016-03-08 09:18:05 +053031#include "../common/board_detect.h"
32
33#define board_is_dra74x_evm() board_ti_is("5777xCPU")
34#define board_is_dra74x_revh_or_later() board_is_dra74x_evm() && \
35 (strncmp("H", board_ti_get_rev(), 1) <= 0)
Lokesh Vutla687054a2013-02-12 21:29:08 +000036
Mugunthan V Nb1e26e32013-07-08 16:04:41 +053037#ifdef CONFIG_DRIVER_TI_CPSW
38#include <cpsw.h>
39#endif
40
Lokesh Vutla687054a2013-02-12 21:29:08 +000041DECLARE_GLOBAL_DATA_PTR;
42
Lokesh Vutla7b922522014-08-04 19:42:24 +053043/* GPIO 7_11 */
44#define GPIO_DDR_VTT_EN 203
45
Lokesh Vutla25afe552016-03-08 09:18:05 +053046#define SYSINFO_BOARD_NAME_MAX_LEN 37
47
Lokesh Vutla687054a2013-02-12 21:29:08 +000048const struct omap_sysinfo sysinfo = {
Lokesh Vutla25afe552016-03-08 09:18:05 +053049 "Board: UNKNOWN(DRA7 EVM) REV UNKNOWN\n"
Lokesh Vutla687054a2013-02-12 21:29:08 +000050};
51
52/**
53 * @brief board_init
54 *
55 * @return 0
56 */
57int board_init(void)
58{
59 gpmc_init();
60 gd->bd->bi_boot_params = (0x80000000 + 0x100); /* boot param addr */
61
62 return 0;
63}
64
Roger Quadros21914ee2013-11-11 16:56:44 +020065int board_late_init(void)
66{
Lokesh Vutla4ec3f6e2014-07-14 19:57:58 +053067#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
Lokesh Vutla25afe552016-03-08 09:18:05 +053068 char *name = "unknown";
69
70 if (is_dra72x())
71 name = "dra72x";
Lokesh Vutla4ec3f6e2014-07-14 19:57:58 +053072 else
Lokesh Vutla25afe552016-03-08 09:18:05 +053073 name = "dra7xx";
74
75 set_board_info_env(name);
Dileep Kattaf12467d2015-03-25 04:04:51 +053076
Paul Kocialkowski07815eb2015-08-27 19:37:12 +020077 omap_die_id_serial();
Lokesh Vutla4ec3f6e2014-07-14 19:57:58 +053078#endif
Roger Quadros21914ee2013-11-11 16:56:44 +020079 return 0;
80}
81
Lokesh Vutla25afe552016-03-08 09:18:05 +053082#ifdef CONFIG_SPL_BUILD
83void do_board_detect(void)
84{
85 int rc;
86
87 rc = ti_i2c_eeprom_dra7_get(CONFIG_EEPROM_BUS_ADDRESS,
88 CONFIG_EEPROM_CHIP_ADDRESS);
89 if (rc)
90 printf("ti_i2c_eeprom_init failed %d\n", rc);
91}
92
93#else
94
95void do_board_detect(void)
96{
97 char *bname = NULL;
98 int rc;
99
100 rc = ti_i2c_eeprom_dra7_get(CONFIG_EEPROM_BUS_ADDRESS,
101 CONFIG_EEPROM_CHIP_ADDRESS);
102 if (rc)
103 printf("ti_i2c_eeprom_init failed %d\n", rc);
104
105 if (board_is_dra74x_evm()) {
106 bname = "DRA74x EVM";
107 /* If EEPROM is not populated */
108 } else {
109 if (is_dra72x())
110 bname = "DRA72x EVM";
111 else
112 bname = "DRA74x EVM";
113 }
114
115 if (bname)
116 snprintf(sysinfo.board_string, SYSINFO_BOARD_NAME_MAX_LEN,
117 "Board: %s REV %s\n", bname, board_ti_get_rev());
118}
119#endif /* CONFIG_SPL_BUILD */
120
Lokesh Vutla687054a2013-02-12 21:29:08 +0000121void set_muxconf_regs_essential(void)
122{
123 do_set_mux32((*ctrl)->control_padconf_core_base,
Lokesh Vutla706dd342015-06-04 16:42:38 +0530124 early_padconf, ARRAY_SIZE(early_padconf));
Lokesh Vutla687054a2013-02-12 21:29:08 +0000125}
126
Lokesh Vutla706dd342015-06-04 16:42:38 +0530127#ifdef CONFIG_IODELAY_RECALIBRATION
128void recalibrate_iodelay(void)
129{
Nishanth Menon03589232015-08-13 09:50:59 -0500130 struct pad_conf_entry const *pads;
131 struct iodelay_cfg_entry const *iodelay;
132 int npads, niodelays;
133
134 switch (omap_revision()) {
135 case DRA722_ES1_0:
136 pads = core_padconf_array_essential;
137 npads = ARRAY_SIZE(core_padconf_array_essential);
138 iodelay = iodelay_cfg_array;
139 niodelays = ARRAY_SIZE(iodelay_cfg_array);
140 break;
141 case DRA752_ES1_0:
142 case DRA752_ES1_1:
143 pads = dra74x_core_padconf_array;
144 npads = ARRAY_SIZE(dra74x_core_padconf_array);
145 iodelay = dra742_es1_1_iodelay_cfg_array;
146 niodelays = ARRAY_SIZE(dra742_es1_1_iodelay_cfg_array);
147 break;
148 default:
149 case DRA752_ES2_0:
150 pads = dra74x_core_padconf_array;
151 npads = ARRAY_SIZE(dra74x_core_padconf_array);
152 iodelay = dra742_es2_0_iodelay_cfg_array;
153 niodelays = ARRAY_SIZE(dra742_es2_0_iodelay_cfg_array);
Nishanth Menon76cff2b2015-08-13 09:51:00 -0500154 /* Setup port1 and port2 for rgmii with 'no-id' mode */
155 clrset_spare_register(1, 0, RGMII2_ID_MODE_N_MASK |
156 RGMII1_ID_MODE_N_MASK);
Nishanth Menon03589232015-08-13 09:50:59 -0500157 break;
Nishanth Menon27d170a2015-06-04 16:42:39 +0530158 }
Nishanth Menon03589232015-08-13 09:50:59 -0500159 __recalibrate_iodelay(pads, npads, iodelay, niodelays);
Lokesh Vutla706dd342015-06-04 16:42:38 +0530160}
161#endif
162
Lokesh Vutla687054a2013-02-12 21:29:08 +0000163#if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_GENERIC_MMC)
164int board_mmc_init(bd_t *bis)
165{
166 omap_mmc_init(0, 0, 0, -1, -1);
167 omap_mmc_init(1, 0, 0, -1, -1);
168 return 0;
169}
170#endif
Mugunthan V Nb1e26e32013-07-08 16:04:41 +0530171
Kishon Vijay Abraham Ia17188c2015-02-23 18:40:19 +0530172#ifdef CONFIG_USB_DWC3
173static struct dwc3_device usb_otg_ss1 = {
174 .maximum_speed = USB_SPEED_SUPER,
175 .base = DRA7_USB_OTG_SS1_BASE,
176 .tx_fifo_resize = false,
177 .index = 0,
178};
179
180static struct dwc3_omap_device usb_otg_ss1_glue = {
181 .base = (void *)DRA7_USB_OTG_SS1_GLUE_BASE,
182 .utmi_mode = DWC3_OMAP_UTMI_MODE_SW,
Kishon Vijay Abraham Ia17188c2015-02-23 18:40:19 +0530183 .index = 0,
184};
185
186static struct ti_usb_phy_device usb_phy1_device = {
187 .pll_ctrl_base = (void *)DRA7_USB3_PHY1_PLL_CTRL,
188 .usb2_phy_power = (void *)DRA7_USB2_PHY1_POWER,
189 .usb3_phy_power = (void *)DRA7_USB3_PHY1_POWER,
190 .index = 0,
191};
192
193static struct dwc3_device usb_otg_ss2 = {
194 .maximum_speed = USB_SPEED_SUPER,
195 .base = DRA7_USB_OTG_SS2_BASE,
196 .tx_fifo_resize = false,
197 .index = 1,
198};
199
200static struct dwc3_omap_device usb_otg_ss2_glue = {
201 .base = (void *)DRA7_USB_OTG_SS2_GLUE_BASE,
202 .utmi_mode = DWC3_OMAP_UTMI_MODE_SW,
Kishon Vijay Abraham Ia17188c2015-02-23 18:40:19 +0530203 .index = 1,
204};
205
206static struct ti_usb_phy_device usb_phy2_device = {
207 .usb2_phy_power = (void *)DRA7_USB2_PHY2_POWER,
208 .index = 1,
209};
210
211int board_usb_init(int index, enum usb_init_type init)
212{
Kishon Vijay Abraham I6f1af1e2015-08-19 16:16:27 +0530213 enable_usb_clocks(index);
Kishon Vijay Abraham Ia17188c2015-02-23 18:40:19 +0530214 switch (index) {
215 case 0:
216 if (init == USB_INIT_DEVICE) {
217 usb_otg_ss1.dr_mode = USB_DR_MODE_PERIPHERAL;
218 usb_otg_ss1_glue.vbus_id_status = OMAP_DWC3_VBUS_VALID;
219 } else {
220 usb_otg_ss1.dr_mode = USB_DR_MODE_HOST;
221 usb_otg_ss1_glue.vbus_id_status = OMAP_DWC3_ID_GROUND;
222 }
223
224 ti_usb_phy_uboot_init(&usb_phy1_device);
225 dwc3_omap_uboot_init(&usb_otg_ss1_glue);
226 dwc3_uboot_init(&usb_otg_ss1);
227 break;
228 case 1:
229 if (init == USB_INIT_DEVICE) {
230 usb_otg_ss2.dr_mode = USB_DR_MODE_PERIPHERAL;
231 usb_otg_ss2_glue.vbus_id_status = OMAP_DWC3_VBUS_VALID;
232 } else {
233 usb_otg_ss2.dr_mode = USB_DR_MODE_HOST;
234 usb_otg_ss2_glue.vbus_id_status = OMAP_DWC3_ID_GROUND;
235 }
236
237 ti_usb_phy_uboot_init(&usb_phy2_device);
238 dwc3_omap_uboot_init(&usb_otg_ss2_glue);
239 dwc3_uboot_init(&usb_otg_ss2);
240 break;
241 default:
242 printf("Invalid Controller Index\n");
243 }
244
245 return 0;
246}
247
248int board_usb_cleanup(int index, enum usb_init_type init)
249{
250 switch (index) {
251 case 0:
252 case 1:
253 ti_usb_phy_uboot_exit(index);
254 dwc3_uboot_exit(index);
255 dwc3_omap_uboot_exit(index);
256 break;
257 default:
258 printf("Invalid Controller Index\n");
259 }
Kishon Vijay Abraham I6f1af1e2015-08-19 16:16:27 +0530260 disable_usb_clocks(index);
Kishon Vijay Abraham Ia17188c2015-02-23 18:40:19 +0530261 return 0;
262}
263
Kishon Vijay Abraham I2d48aa62015-02-23 18:40:23 +0530264int usb_gadget_handle_interrupts(int index)
Kishon Vijay Abraham Ia17188c2015-02-23 18:40:19 +0530265{
266 u32 status;
267
Kishon Vijay Abraham I2d48aa62015-02-23 18:40:23 +0530268 status = dwc3_omap_uboot_interrupt_status(index);
Kishon Vijay Abraham Ia17188c2015-02-23 18:40:19 +0530269 if (status)
Kishon Vijay Abraham I2d48aa62015-02-23 18:40:23 +0530270 dwc3_uboot_handle_interrupt(index);
Kishon Vijay Abraham Ia17188c2015-02-23 18:40:19 +0530271
272 return 0;
273}
274#endif
275
Tom Rini79b079f2014-04-03 07:52:56 -0400276#if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_OS_BOOT)
277int spl_start_uboot(void)
278{
279 /* break into full u-boot on 'c' */
280 if (serial_tstc() && serial_getc() == 'c')
281 return 1;
282
283#ifdef CONFIG_SPL_ENV_SUPPORT
284 env_init();
285 env_relocate_spec();
286 if (getenv_yesno("boot_os") != 1)
287 return 1;
288#endif
289
290 return 0;
291}
292#endif
293
Mugunthan V Nb1e26e32013-07-08 16:04:41 +0530294#ifdef CONFIG_DRIVER_TI_CPSW
Mugunthan V N4c8014b2014-05-22 14:37:12 +0530295extern u32 *const omap_si_rev;
296
Mugunthan V Nb1e26e32013-07-08 16:04:41 +0530297static void cpsw_control(int enabled)
298{
299 /* VTP can be added here */
300
301 return;
302}
303
304static struct cpsw_slave_data cpsw_slaves[] = {
305 {
306 .slave_reg_ofs = 0x208,
307 .sliver_reg_ofs = 0xd80,
Mugunthan V N9c653aa2014-02-18 07:31:52 -0500308 .phy_addr = 2,
Mugunthan V Nb1e26e32013-07-08 16:04:41 +0530309 },
310 {
311 .slave_reg_ofs = 0x308,
312 .sliver_reg_ofs = 0xdc0,
Mugunthan V N9c653aa2014-02-18 07:31:52 -0500313 .phy_addr = 3,
Mugunthan V Nb1e26e32013-07-08 16:04:41 +0530314 },
315};
316
317static struct cpsw_platform_data cpsw_data = {
318 .mdio_base = CPSW_MDIO_BASE,
319 .cpsw_base = CPSW_BASE,
320 .mdio_div = 0xff,
321 .channels = 8,
322 .cpdma_reg_ofs = 0x800,
Mugunthan V N4c8014b2014-05-22 14:37:12 +0530323 .slaves = 2,
Mugunthan V Nb1e26e32013-07-08 16:04:41 +0530324 .slave_data = cpsw_slaves,
325 .ale_reg_ofs = 0xd00,
326 .ale_entries = 1024,
327 .host_port_reg_ofs = 0x108,
328 .hw_stats_reg_ofs = 0x900,
329 .bd_ram_ofs = 0x2000,
330 .mac_control = (1 << 5),
331 .control = cpsw_control,
332 .host_port_num = 0,
333 .version = CPSW_CTRL_VERSION_2,
334};
335
336int board_eth_init(bd_t *bis)
337{
338 int ret;
339 uint8_t mac_addr[6];
340 uint32_t mac_hi, mac_lo;
341 uint32_t ctrl_val;
Mugunthan V Nb1e26e32013-07-08 16:04:41 +0530342
343 /* try reading mac address from efuse */
344 mac_lo = readl((*ctrl)->control_core_mac_id_0_lo);
345 mac_hi = readl((*ctrl)->control_core_mac_id_0_hi);
Mugunthan V Ne0a1d592014-01-07 19:57:38 +0530346 mac_addr[0] = (mac_hi & 0xFF0000) >> 16;
Mugunthan V Nb1e26e32013-07-08 16:04:41 +0530347 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
Mugunthan V Ne0a1d592014-01-07 19:57:38 +0530348 mac_addr[2] = mac_hi & 0xFF;
349 mac_addr[3] = (mac_lo & 0xFF0000) >> 16;
Mugunthan V Nb1e26e32013-07-08 16:04:41 +0530350 mac_addr[4] = (mac_lo & 0xFF00) >> 8;
Mugunthan V Ne0a1d592014-01-07 19:57:38 +0530351 mac_addr[5] = mac_lo & 0xFF;
Mugunthan V Nb1e26e32013-07-08 16:04:41 +0530352
353 if (!getenv("ethaddr")) {
354 printf("<ethaddr> not set. Validating first E-fuse MAC\n");
355
Joe Hershberger0adb5b72015-04-08 01:41:04 -0500356 if (is_valid_ethaddr(mac_addr))
Mugunthan V Nb1e26e32013-07-08 16:04:41 +0530357 eth_setenv_enetaddr("ethaddr", mac_addr);
358 }
Mugunthan V N8feb37b2014-02-18 07:31:56 -0500359
360 mac_lo = readl((*ctrl)->control_core_mac_id_1_lo);
361 mac_hi = readl((*ctrl)->control_core_mac_id_1_hi);
362 mac_addr[0] = (mac_hi & 0xFF0000) >> 16;
363 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
364 mac_addr[2] = mac_hi & 0xFF;
365 mac_addr[3] = (mac_lo & 0xFF0000) >> 16;
366 mac_addr[4] = (mac_lo & 0xFF00) >> 8;
367 mac_addr[5] = mac_lo & 0xFF;
368
369 if (!getenv("eth1addr")) {
Joe Hershberger0adb5b72015-04-08 01:41:04 -0500370 if (is_valid_ethaddr(mac_addr))
Mugunthan V N8feb37b2014-02-18 07:31:56 -0500371 eth_setenv_enetaddr("eth1addr", mac_addr);
372 }
373
Mugunthan V Nb1e26e32013-07-08 16:04:41 +0530374 ctrl_val = readl((*ctrl)->control_core_control_io1) & (~0x33);
375 ctrl_val |= 0x22;
376 writel(ctrl_val, (*ctrl)->control_core_control_io1);
377
Mugunthan V N4c8014b2014-05-22 14:37:12 +0530378 if (*omap_si_rev == DRA722_ES1_0)
379 cpsw_data.active_slave = 1;
380
Mugunthan V Nb1e26e32013-07-08 16:04:41 +0530381 ret = cpsw_register(&cpsw_data);
382 if (ret < 0)
383 printf("Error %d registering CPSW switch\n", ret);
384
385 return ret;
386}
387#endif
Lokesh Vutla7b922522014-08-04 19:42:24 +0530388
389#ifdef CONFIG_BOARD_EARLY_INIT_F
390/* VTT regulator enable */
391static inline void vtt_regulator_enable(void)
392{
393 if (omap_hw_init_context() == OMAP_INIT_CONTEXT_UBOOT_AFTER_SPL)
394 return;
395
396 /* Do not enable VTT for DRA722 */
397 if (omap_revision() == DRA722_ES1_0)
398 return;
399
400 /*
401 * EVM Rev G and later use gpio7_11 for DDR3 termination.
402 * This is safe enough to do on older revs.
403 */
404 gpio_request(GPIO_DDR_VTT_EN, "ddr_vtt_en");
405 gpio_direction_output(GPIO_DDR_VTT_EN, 1);
406}
407
408int board_early_init_f(void)
409{
410 vtt_regulator_enable();
411 return 0;
412}
413#endif