blob: 9941afa605dcb2c7749b688c9999577d133e09f9 [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 Vutla7b922522014-08-04 19:42:24 +053016#include <asm/gpio.h>
Kishon Vijay Abraham Ia17188c2015-02-23 18:40:19 +053017#include <usb.h>
18#include <linux/usb/gadget.h>
Lokesh Vutla7b922522014-08-04 19:42:24 +053019#include <asm/arch/gpio.h>
Lokesh Vutla706dd342015-06-04 16:42:38 +053020#include <asm/arch/dra7xx_iodelay.h>
Lokesh Vutla687054a2013-02-12 21:29:08 +000021#include <asm/arch/sys_proto.h>
22#include <asm/arch/mmc_host_def.h>
Roger Quadros21914ee2013-11-11 16:56:44 +020023#include <asm/arch/sata.h>
Tom Rini79b079f2014-04-03 07:52:56 -040024#include <environment.h>
Kishon Vijay Abraham Ia17188c2015-02-23 18:40:19 +053025#include <dwc3-uboot.h>
26#include <dwc3-omap-uboot.h>
27#include <ti-usb-phy-uboot.h>
Lokesh Vutla687054a2013-02-12 21:29:08 +000028
29#include "mux_data.h"
30
Mugunthan V Nb1e26e32013-07-08 16:04:41 +053031#ifdef CONFIG_DRIVER_TI_CPSW
32#include <cpsw.h>
33#endif
34
Lokesh Vutla687054a2013-02-12 21:29:08 +000035DECLARE_GLOBAL_DATA_PTR;
36
Lokesh Vutla7b922522014-08-04 19:42:24 +053037/* GPIO 7_11 */
38#define GPIO_DDR_VTT_EN 203
39
Lokesh Vutla687054a2013-02-12 21:29:08 +000040const struct omap_sysinfo sysinfo = {
41 "Board: DRA7xx\n"
42};
43
Mugunthan V Nb1e26e32013-07-08 16:04:41 +053044/*
45 * Adjust I/O delays on the Tx control and data lines of each MAC port. This
46 * is a workaround in order to work properly with the DP83865 PHYs on the EVM.
47 * In 3COM RGMII mode this PHY applies it's own internal clock delay, so we
48 * essentially need to counteract the DRA7xx internal delay, and we do this
49 * by delaying the control and data lines. If not using this PHY, you probably
50 * don't need to do this stuff!
51 */
52static void dra7xx_adj_io_delay(const struct io_delay *io_dly)
53{
54 int i = 0;
55 u32 reg_val;
56 u32 delta;
57 u32 coarse;
58 u32 fine;
59
60 writel(CFG_IO_DELAY_UNLOCK_KEY, CFG_IO_DELAY_LOCK);
61
62 while(io_dly[i].addr) {
63 writel(CFG_IO_DELAY_ACCESS_PATTERN & ~CFG_IO_DELAY_LOCK_MASK,
64 io_dly[i].addr);
65 delta = io_dly[i].dly;
66 reg_val = readl(io_dly[i].addr) & 0x3ff;
67 coarse = ((reg_val >> 5) & 0x1F) + ((delta >> 5) & 0x1F);
68 coarse = (coarse > 0x1F) ? (0x1F) : (coarse);
69 fine = (reg_val & 0x1F) + (delta & 0x1F);
70 fine = (fine > 0x1F) ? (0x1F) : (fine);
71 reg_val = CFG_IO_DELAY_ACCESS_PATTERN |
72 CFG_IO_DELAY_LOCK_MASK |
73 ((coarse << 5) | (fine));
74 writel(reg_val, io_dly[i].addr);
75 i++;
76 }
77
78 writel(CFG_IO_DELAY_LOCK_KEY, CFG_IO_DELAY_LOCK);
79}
80
Lokesh Vutla687054a2013-02-12 21:29:08 +000081/**
82 * @brief board_init
83 *
84 * @return 0
85 */
86int board_init(void)
87{
88 gpmc_init();
89 gd->bd->bi_boot_params = (0x80000000 + 0x100); /* boot param addr */
90
91 return 0;
92}
93
Roger Quadros21914ee2013-11-11 16:56:44 +020094int board_late_init(void)
95{
Lokesh Vutla4ec3f6e2014-07-14 19:57:58 +053096#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
Dileep Kattaf12467d2015-03-25 04:04:51 +053097 u32 id[4];
98
Lokesh Vutla4ec3f6e2014-07-14 19:57:58 +053099 if (omap_revision() == DRA722_ES1_0)
100 setenv("board_name", "dra72x");
101 else
102 setenv("board_name", "dra7xx");
Dileep Kattaf12467d2015-03-25 04:04:51 +0530103
104 id[0] = readl((*ctrl)->control_std_fuse_die_id_0);
105 id[1] = readl((*ctrl)->control_std_fuse_die_id_1);
106 usb_set_serial_num_from_die_id(id);
Lokesh Vutla4ec3f6e2014-07-14 19:57:58 +0530107#endif
Roger Quadros21914ee2013-11-11 16:56:44 +0200108 return 0;
109}
110
Lokesh Vutla687054a2013-02-12 21:29:08 +0000111void set_muxconf_regs_essential(void)
112{
113 do_set_mux32((*ctrl)->control_padconf_core_base,
Lokesh Vutla706dd342015-06-04 16:42:38 +0530114 early_padconf, ARRAY_SIZE(early_padconf));
Lokesh Vutla687054a2013-02-12 21:29:08 +0000115}
116
Lokesh Vutla706dd342015-06-04 16:42:38 +0530117#ifdef CONFIG_IODELAY_RECALIBRATION
118void recalibrate_iodelay(void)
119{
Nishanth Menon27d170a2015-06-04 16:42:39 +0530120 if (is_dra72x()) {
121 __recalibrate_iodelay(core_padconf_array_essential,
122 ARRAY_SIZE(core_padconf_array_essential),
123 iodelay_cfg_array,
124 ARRAY_SIZE(iodelay_cfg_array));
125 } else {
126 __recalibrate_iodelay(dra74x_core_padconf_array,
127 ARRAY_SIZE(dra74x_core_padconf_array),
128 dra742_iodelay_cfg_array,
129 ARRAY_SIZE(dra742_iodelay_cfg_array));
130 }
Lokesh Vutla706dd342015-06-04 16:42:38 +0530131}
132#endif
133
Lokesh Vutla687054a2013-02-12 21:29:08 +0000134#if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_GENERIC_MMC)
135int board_mmc_init(bd_t *bis)
136{
137 omap_mmc_init(0, 0, 0, -1, -1);
138 omap_mmc_init(1, 0, 0, -1, -1);
139 return 0;
140}
141#endif
Mugunthan V Nb1e26e32013-07-08 16:04:41 +0530142
Kishon Vijay Abraham Ia17188c2015-02-23 18:40:19 +0530143#ifdef CONFIG_USB_DWC3
144static struct dwc3_device usb_otg_ss1 = {
145 .maximum_speed = USB_SPEED_SUPER,
146 .base = DRA7_USB_OTG_SS1_BASE,
147 .tx_fifo_resize = false,
148 .index = 0,
149};
150
151static struct dwc3_omap_device usb_otg_ss1_glue = {
152 .base = (void *)DRA7_USB_OTG_SS1_GLUE_BASE,
153 .utmi_mode = DWC3_OMAP_UTMI_MODE_SW,
154 .vbus_id_status = OMAP_DWC3_VBUS_VALID,
155 .index = 0,
156};
157
158static struct ti_usb_phy_device usb_phy1_device = {
159 .pll_ctrl_base = (void *)DRA7_USB3_PHY1_PLL_CTRL,
160 .usb2_phy_power = (void *)DRA7_USB2_PHY1_POWER,
161 .usb3_phy_power = (void *)DRA7_USB3_PHY1_POWER,
162 .index = 0,
163};
164
165static struct dwc3_device usb_otg_ss2 = {
166 .maximum_speed = USB_SPEED_SUPER,
167 .base = DRA7_USB_OTG_SS2_BASE,
168 .tx_fifo_resize = false,
169 .index = 1,
170};
171
172static struct dwc3_omap_device usb_otg_ss2_glue = {
173 .base = (void *)DRA7_USB_OTG_SS2_GLUE_BASE,
174 .utmi_mode = DWC3_OMAP_UTMI_MODE_SW,
175 .vbus_id_status = OMAP_DWC3_VBUS_VALID,
176 .index = 1,
177};
178
179static struct ti_usb_phy_device usb_phy2_device = {
180 .usb2_phy_power = (void *)DRA7_USB2_PHY2_POWER,
181 .index = 1,
182};
183
184int board_usb_init(int index, enum usb_init_type init)
185{
186 switch (index) {
187 case 0:
188 if (init == USB_INIT_DEVICE) {
189 usb_otg_ss1.dr_mode = USB_DR_MODE_PERIPHERAL;
190 usb_otg_ss1_glue.vbus_id_status = OMAP_DWC3_VBUS_VALID;
191 } else {
192 usb_otg_ss1.dr_mode = USB_DR_MODE_HOST;
193 usb_otg_ss1_glue.vbus_id_status = OMAP_DWC3_ID_GROUND;
194 }
195
196 ti_usb_phy_uboot_init(&usb_phy1_device);
197 dwc3_omap_uboot_init(&usb_otg_ss1_glue);
198 dwc3_uboot_init(&usb_otg_ss1);
199 break;
200 case 1:
201 if (init == USB_INIT_DEVICE) {
202 usb_otg_ss2.dr_mode = USB_DR_MODE_PERIPHERAL;
203 usb_otg_ss2_glue.vbus_id_status = OMAP_DWC3_VBUS_VALID;
204 } else {
205 usb_otg_ss2.dr_mode = USB_DR_MODE_HOST;
206 usb_otg_ss2_glue.vbus_id_status = OMAP_DWC3_ID_GROUND;
207 }
208
209 ti_usb_phy_uboot_init(&usb_phy2_device);
210 dwc3_omap_uboot_init(&usb_otg_ss2_glue);
211 dwc3_uboot_init(&usb_otg_ss2);
212 break;
213 default:
214 printf("Invalid Controller Index\n");
215 }
216
217 return 0;
218}
219
220int board_usb_cleanup(int index, enum usb_init_type init)
221{
222 switch (index) {
223 case 0:
224 case 1:
225 ti_usb_phy_uboot_exit(index);
226 dwc3_uboot_exit(index);
227 dwc3_omap_uboot_exit(index);
228 break;
229 default:
230 printf("Invalid Controller Index\n");
231 }
232 return 0;
233}
234
Kishon Vijay Abraham I2d48aa62015-02-23 18:40:23 +0530235int usb_gadget_handle_interrupts(int index)
Kishon Vijay Abraham Ia17188c2015-02-23 18:40:19 +0530236{
237 u32 status;
238
Kishon Vijay Abraham I2d48aa62015-02-23 18:40:23 +0530239 status = dwc3_omap_uboot_interrupt_status(index);
Kishon Vijay Abraham Ia17188c2015-02-23 18:40:19 +0530240 if (status)
Kishon Vijay Abraham I2d48aa62015-02-23 18:40:23 +0530241 dwc3_uboot_handle_interrupt(index);
Kishon Vijay Abraham Ia17188c2015-02-23 18:40:19 +0530242
243 return 0;
244}
245#endif
246
Tom Rini79b079f2014-04-03 07:52:56 -0400247#if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_OS_BOOT)
248int spl_start_uboot(void)
249{
250 /* break into full u-boot on 'c' */
251 if (serial_tstc() && serial_getc() == 'c')
252 return 1;
253
254#ifdef CONFIG_SPL_ENV_SUPPORT
255 env_init();
256 env_relocate_spec();
257 if (getenv_yesno("boot_os") != 1)
258 return 1;
259#endif
260
261 return 0;
262}
263#endif
264
Mugunthan V Nb1e26e32013-07-08 16:04:41 +0530265#ifdef CONFIG_DRIVER_TI_CPSW
266
267/* Delay value to add to calibrated value */
268#define RGMII0_TXCTL_DLY_VAL ((0x3 << 5) + 0x8)
269#define RGMII0_TXD0_DLY_VAL ((0x3 << 5) + 0x8)
270#define RGMII0_TXD1_DLY_VAL ((0x3 << 5) + 0x2)
271#define RGMII0_TXD2_DLY_VAL ((0x4 << 5) + 0x0)
272#define RGMII0_TXD3_DLY_VAL ((0x4 << 5) + 0x0)
273#define VIN2A_D13_DLY_VAL ((0x3 << 5) + 0x8)
274#define VIN2A_D17_DLY_VAL ((0x3 << 5) + 0x8)
275#define VIN2A_D16_DLY_VAL ((0x3 << 5) + 0x2)
276#define VIN2A_D15_DLY_VAL ((0x4 << 5) + 0x0)
277#define VIN2A_D14_DLY_VAL ((0x4 << 5) + 0x0)
278
Mugunthan V N4c8014b2014-05-22 14:37:12 +0530279extern u32 *const omap_si_rev;
280
Mugunthan V Nb1e26e32013-07-08 16:04:41 +0530281static void cpsw_control(int enabled)
282{
283 /* VTP can be added here */
284
285 return;
286}
287
288static struct cpsw_slave_data cpsw_slaves[] = {
289 {
290 .slave_reg_ofs = 0x208,
291 .sliver_reg_ofs = 0xd80,
Mugunthan V N9c653aa2014-02-18 07:31:52 -0500292 .phy_addr = 2,
Mugunthan V Nb1e26e32013-07-08 16:04:41 +0530293 },
294 {
295 .slave_reg_ofs = 0x308,
296 .sliver_reg_ofs = 0xdc0,
Mugunthan V N9c653aa2014-02-18 07:31:52 -0500297 .phy_addr = 3,
Mugunthan V Nb1e26e32013-07-08 16:04:41 +0530298 },
299};
300
301static struct cpsw_platform_data cpsw_data = {
302 .mdio_base = CPSW_MDIO_BASE,
303 .cpsw_base = CPSW_BASE,
304 .mdio_div = 0xff,
305 .channels = 8,
306 .cpdma_reg_ofs = 0x800,
Mugunthan V N4c8014b2014-05-22 14:37:12 +0530307 .slaves = 2,
Mugunthan V Nb1e26e32013-07-08 16:04:41 +0530308 .slave_data = cpsw_slaves,
309 .ale_reg_ofs = 0xd00,
310 .ale_entries = 1024,
311 .host_port_reg_ofs = 0x108,
312 .hw_stats_reg_ofs = 0x900,
313 .bd_ram_ofs = 0x2000,
314 .mac_control = (1 << 5),
315 .control = cpsw_control,
316 .host_port_num = 0,
317 .version = CPSW_CTRL_VERSION_2,
318};
319
320int board_eth_init(bd_t *bis)
321{
322 int ret;
323 uint8_t mac_addr[6];
324 uint32_t mac_hi, mac_lo;
325 uint32_t ctrl_val;
326 const struct io_delay io_dly[] = {
327 {CFG_RGMII0_TXCTL, RGMII0_TXCTL_DLY_VAL},
328 {CFG_RGMII0_TXD0, RGMII0_TXD0_DLY_VAL},
329 {CFG_RGMII0_TXD1, RGMII0_TXD1_DLY_VAL},
330 {CFG_RGMII0_TXD2, RGMII0_TXD2_DLY_VAL},
331 {CFG_RGMII0_TXD3, RGMII0_TXD3_DLY_VAL},
332 {CFG_VIN2A_D13, VIN2A_D13_DLY_VAL},
333 {CFG_VIN2A_D17, VIN2A_D17_DLY_VAL},
334 {CFG_VIN2A_D16, VIN2A_D16_DLY_VAL},
335 {CFG_VIN2A_D15, VIN2A_D15_DLY_VAL},
336 {CFG_VIN2A_D14, VIN2A_D14_DLY_VAL},
337 {0}
338 };
339
340 /* Adjust IO delay for RGMII tx path */
341 dra7xx_adj_io_delay(io_dly);
342
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