blob: 1b051509a658b75cd3d7cb77bdeed803a2cbab54 [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 Vutla687054a2013-02-12 21:29:08 +000020#include <asm/arch/sys_proto.h>
21#include <asm/arch/mmc_host_def.h>
Roger Quadros21914ee2013-11-11 16:56:44 +020022#include <asm/arch/sata.h>
Tom Rini79b079f2014-04-03 07:52:56 -040023#include <environment.h>
Kishon Vijay Abraham Ia17188c2015-02-23 18:40:19 +053024#include <dwc3-uboot.h>
25#include <dwc3-omap-uboot.h>
26#include <ti-usb-phy-uboot.h>
Lokesh Vutla687054a2013-02-12 21:29:08 +000027
28#include "mux_data.h"
29
Mugunthan V Nb1e26e32013-07-08 16:04:41 +053030#ifdef CONFIG_DRIVER_TI_CPSW
31#include <cpsw.h>
32#endif
33
Lokesh Vutla687054a2013-02-12 21:29:08 +000034DECLARE_GLOBAL_DATA_PTR;
35
Lokesh Vutla7b922522014-08-04 19:42:24 +053036/* GPIO 7_11 */
37#define GPIO_DDR_VTT_EN 203
38
Lokesh Vutla687054a2013-02-12 21:29:08 +000039const struct omap_sysinfo sysinfo = {
40 "Board: DRA7xx\n"
41};
42
Mugunthan V Nb1e26e32013-07-08 16:04:41 +053043/*
44 * Adjust I/O delays on the Tx control and data lines of each MAC port. This
45 * is a workaround in order to work properly with the DP83865 PHYs on the EVM.
46 * In 3COM RGMII mode this PHY applies it's own internal clock delay, so we
47 * essentially need to counteract the DRA7xx internal delay, and we do this
48 * by delaying the control and data lines. If not using this PHY, you probably
49 * don't need to do this stuff!
50 */
51static void dra7xx_adj_io_delay(const struct io_delay *io_dly)
52{
53 int i = 0;
54 u32 reg_val;
55 u32 delta;
56 u32 coarse;
57 u32 fine;
58
59 writel(CFG_IO_DELAY_UNLOCK_KEY, CFG_IO_DELAY_LOCK);
60
61 while(io_dly[i].addr) {
62 writel(CFG_IO_DELAY_ACCESS_PATTERN & ~CFG_IO_DELAY_LOCK_MASK,
63 io_dly[i].addr);
64 delta = io_dly[i].dly;
65 reg_val = readl(io_dly[i].addr) & 0x3ff;
66 coarse = ((reg_val >> 5) & 0x1F) + ((delta >> 5) & 0x1F);
67 coarse = (coarse > 0x1F) ? (0x1F) : (coarse);
68 fine = (reg_val & 0x1F) + (delta & 0x1F);
69 fine = (fine > 0x1F) ? (0x1F) : (fine);
70 reg_val = CFG_IO_DELAY_ACCESS_PATTERN |
71 CFG_IO_DELAY_LOCK_MASK |
72 ((coarse << 5) | (fine));
73 writel(reg_val, io_dly[i].addr);
74 i++;
75 }
76
77 writel(CFG_IO_DELAY_LOCK_KEY, CFG_IO_DELAY_LOCK);
78}
79
Lokesh Vutla687054a2013-02-12 21:29:08 +000080/**
81 * @brief board_init
82 *
83 * @return 0
84 */
85int board_init(void)
86{
87 gpmc_init();
88 gd->bd->bi_boot_params = (0x80000000 + 0x100); /* boot param addr */
89
90 return 0;
91}
92
Roger Quadros21914ee2013-11-11 16:56:44 +020093int board_late_init(void)
94{
Lokesh Vutla4ec3f6e2014-07-14 19:57:58 +053095#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
Dileep Kattaf12467d2015-03-25 04:04:51 +053096 u32 id[4];
97
Lokesh Vutla4ec3f6e2014-07-14 19:57:58 +053098 if (omap_revision() == DRA722_ES1_0)
99 setenv("board_name", "dra72x");
100 else
101 setenv("board_name", "dra7xx");
Dileep Kattaf12467d2015-03-25 04:04:51 +0530102
103 id[0] = readl((*ctrl)->control_std_fuse_die_id_0);
104 id[1] = readl((*ctrl)->control_std_fuse_die_id_1);
105 usb_set_serial_num_from_die_id(id);
Lokesh Vutla4ec3f6e2014-07-14 19:57:58 +0530106#endif
Roger Quadros21914ee2013-11-11 16:56:44 +0200107 return 0;
108}
109
Lokesh Vutla687054a2013-02-12 21:29:08 +0000110void set_muxconf_regs_essential(void)
111{
112 do_set_mux32((*ctrl)->control_padconf_core_base,
113 core_padconf_array_essential,
114 sizeof(core_padconf_array_essential) /
115 sizeof(struct pad_conf_entry));
116}
117
118#if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_GENERIC_MMC)
119int board_mmc_init(bd_t *bis)
120{
121 omap_mmc_init(0, 0, 0, -1, -1);
122 omap_mmc_init(1, 0, 0, -1, -1);
123 return 0;
124}
125#endif
Mugunthan V Nb1e26e32013-07-08 16:04:41 +0530126
Kishon Vijay Abraham Ia17188c2015-02-23 18:40:19 +0530127#ifdef CONFIG_USB_DWC3
128static struct dwc3_device usb_otg_ss1 = {
129 .maximum_speed = USB_SPEED_SUPER,
130 .base = DRA7_USB_OTG_SS1_BASE,
131 .tx_fifo_resize = false,
132 .index = 0,
133};
134
135static struct dwc3_omap_device usb_otg_ss1_glue = {
136 .base = (void *)DRA7_USB_OTG_SS1_GLUE_BASE,
137 .utmi_mode = DWC3_OMAP_UTMI_MODE_SW,
138 .vbus_id_status = OMAP_DWC3_VBUS_VALID,
139 .index = 0,
140};
141
142static struct ti_usb_phy_device usb_phy1_device = {
143 .pll_ctrl_base = (void *)DRA7_USB3_PHY1_PLL_CTRL,
144 .usb2_phy_power = (void *)DRA7_USB2_PHY1_POWER,
145 .usb3_phy_power = (void *)DRA7_USB3_PHY1_POWER,
146 .index = 0,
147};
148
149static struct dwc3_device usb_otg_ss2 = {
150 .maximum_speed = USB_SPEED_SUPER,
151 .base = DRA7_USB_OTG_SS2_BASE,
152 .tx_fifo_resize = false,
153 .index = 1,
154};
155
156static struct dwc3_omap_device usb_otg_ss2_glue = {
157 .base = (void *)DRA7_USB_OTG_SS2_GLUE_BASE,
158 .utmi_mode = DWC3_OMAP_UTMI_MODE_SW,
159 .vbus_id_status = OMAP_DWC3_VBUS_VALID,
160 .index = 1,
161};
162
163static struct ti_usb_phy_device usb_phy2_device = {
164 .usb2_phy_power = (void *)DRA7_USB2_PHY2_POWER,
165 .index = 1,
166};
167
168int board_usb_init(int index, enum usb_init_type init)
169{
170 switch (index) {
171 case 0:
172 if (init == USB_INIT_DEVICE) {
173 usb_otg_ss1.dr_mode = USB_DR_MODE_PERIPHERAL;
174 usb_otg_ss1_glue.vbus_id_status = OMAP_DWC3_VBUS_VALID;
175 } else {
176 usb_otg_ss1.dr_mode = USB_DR_MODE_HOST;
177 usb_otg_ss1_glue.vbus_id_status = OMAP_DWC3_ID_GROUND;
178 }
179
180 ti_usb_phy_uboot_init(&usb_phy1_device);
181 dwc3_omap_uboot_init(&usb_otg_ss1_glue);
182 dwc3_uboot_init(&usb_otg_ss1);
183 break;
184 case 1:
185 if (init == USB_INIT_DEVICE) {
186 usb_otg_ss2.dr_mode = USB_DR_MODE_PERIPHERAL;
187 usb_otg_ss2_glue.vbus_id_status = OMAP_DWC3_VBUS_VALID;
188 } else {
189 usb_otg_ss2.dr_mode = USB_DR_MODE_HOST;
190 usb_otg_ss2_glue.vbus_id_status = OMAP_DWC3_ID_GROUND;
191 }
192
193 ti_usb_phy_uboot_init(&usb_phy2_device);
194 dwc3_omap_uboot_init(&usb_otg_ss2_glue);
195 dwc3_uboot_init(&usb_otg_ss2);
196 break;
197 default:
198 printf("Invalid Controller Index\n");
199 }
200
201 return 0;
202}
203
204int board_usb_cleanup(int index, enum usb_init_type init)
205{
206 switch (index) {
207 case 0:
208 case 1:
209 ti_usb_phy_uboot_exit(index);
210 dwc3_uboot_exit(index);
211 dwc3_omap_uboot_exit(index);
212 break;
213 default:
214 printf("Invalid Controller Index\n");
215 }
216 return 0;
217}
218
Kishon Vijay Abraham I2d48aa62015-02-23 18:40:23 +0530219int usb_gadget_handle_interrupts(int index)
Kishon Vijay Abraham Ia17188c2015-02-23 18:40:19 +0530220{
221 u32 status;
222
Kishon Vijay Abraham I2d48aa62015-02-23 18:40:23 +0530223 status = dwc3_omap_uboot_interrupt_status(index);
Kishon Vijay Abraham Ia17188c2015-02-23 18:40:19 +0530224 if (status)
Kishon Vijay Abraham I2d48aa62015-02-23 18:40:23 +0530225 dwc3_uboot_handle_interrupt(index);
Kishon Vijay Abraham Ia17188c2015-02-23 18:40:19 +0530226
227 return 0;
228}
229#endif
230
Tom Rini79b079f2014-04-03 07:52:56 -0400231#if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_OS_BOOT)
232int spl_start_uboot(void)
233{
234 /* break into full u-boot on 'c' */
235 if (serial_tstc() && serial_getc() == 'c')
236 return 1;
237
238#ifdef CONFIG_SPL_ENV_SUPPORT
239 env_init();
240 env_relocate_spec();
241 if (getenv_yesno("boot_os") != 1)
242 return 1;
243#endif
244
245 return 0;
246}
247#endif
248
Mugunthan V Nb1e26e32013-07-08 16:04:41 +0530249#ifdef CONFIG_DRIVER_TI_CPSW
250
251/* Delay value to add to calibrated value */
252#define RGMII0_TXCTL_DLY_VAL ((0x3 << 5) + 0x8)
253#define RGMII0_TXD0_DLY_VAL ((0x3 << 5) + 0x8)
254#define RGMII0_TXD1_DLY_VAL ((0x3 << 5) + 0x2)
255#define RGMII0_TXD2_DLY_VAL ((0x4 << 5) + 0x0)
256#define RGMII0_TXD3_DLY_VAL ((0x4 << 5) + 0x0)
257#define VIN2A_D13_DLY_VAL ((0x3 << 5) + 0x8)
258#define VIN2A_D17_DLY_VAL ((0x3 << 5) + 0x8)
259#define VIN2A_D16_DLY_VAL ((0x3 << 5) + 0x2)
260#define VIN2A_D15_DLY_VAL ((0x4 << 5) + 0x0)
261#define VIN2A_D14_DLY_VAL ((0x4 << 5) + 0x0)
262
Mugunthan V N4c8014b2014-05-22 14:37:12 +0530263extern u32 *const omap_si_rev;
264
Mugunthan V Nb1e26e32013-07-08 16:04:41 +0530265static void cpsw_control(int enabled)
266{
267 /* VTP can be added here */
268
269 return;
270}
271
272static struct cpsw_slave_data cpsw_slaves[] = {
273 {
274 .slave_reg_ofs = 0x208,
275 .sliver_reg_ofs = 0xd80,
Mugunthan V N9c653aa2014-02-18 07:31:52 -0500276 .phy_addr = 2,
Mugunthan V Nb1e26e32013-07-08 16:04:41 +0530277 },
278 {
279 .slave_reg_ofs = 0x308,
280 .sliver_reg_ofs = 0xdc0,
Mugunthan V N9c653aa2014-02-18 07:31:52 -0500281 .phy_addr = 3,
Mugunthan V Nb1e26e32013-07-08 16:04:41 +0530282 },
283};
284
285static struct cpsw_platform_data cpsw_data = {
286 .mdio_base = CPSW_MDIO_BASE,
287 .cpsw_base = CPSW_BASE,
288 .mdio_div = 0xff,
289 .channels = 8,
290 .cpdma_reg_ofs = 0x800,
Mugunthan V N4c8014b2014-05-22 14:37:12 +0530291 .slaves = 2,
Mugunthan V Nb1e26e32013-07-08 16:04:41 +0530292 .slave_data = cpsw_slaves,
293 .ale_reg_ofs = 0xd00,
294 .ale_entries = 1024,
295 .host_port_reg_ofs = 0x108,
296 .hw_stats_reg_ofs = 0x900,
297 .bd_ram_ofs = 0x2000,
298 .mac_control = (1 << 5),
299 .control = cpsw_control,
300 .host_port_num = 0,
301 .version = CPSW_CTRL_VERSION_2,
302};
303
304int board_eth_init(bd_t *bis)
305{
306 int ret;
307 uint8_t mac_addr[6];
308 uint32_t mac_hi, mac_lo;
309 uint32_t ctrl_val;
310 const struct io_delay io_dly[] = {
311 {CFG_RGMII0_TXCTL, RGMII0_TXCTL_DLY_VAL},
312 {CFG_RGMII0_TXD0, RGMII0_TXD0_DLY_VAL},
313 {CFG_RGMII0_TXD1, RGMII0_TXD1_DLY_VAL},
314 {CFG_RGMII0_TXD2, RGMII0_TXD2_DLY_VAL},
315 {CFG_RGMII0_TXD3, RGMII0_TXD3_DLY_VAL},
316 {CFG_VIN2A_D13, VIN2A_D13_DLY_VAL},
317 {CFG_VIN2A_D17, VIN2A_D17_DLY_VAL},
318 {CFG_VIN2A_D16, VIN2A_D16_DLY_VAL},
319 {CFG_VIN2A_D15, VIN2A_D15_DLY_VAL},
320 {CFG_VIN2A_D14, VIN2A_D14_DLY_VAL},
321 {0}
322 };
323
324 /* Adjust IO delay for RGMII tx path */
325 dra7xx_adj_io_delay(io_dly);
326
327 /* try reading mac address from efuse */
328 mac_lo = readl((*ctrl)->control_core_mac_id_0_lo);
329 mac_hi = readl((*ctrl)->control_core_mac_id_0_hi);
Mugunthan V Ne0a1d592014-01-07 19:57:38 +0530330 mac_addr[0] = (mac_hi & 0xFF0000) >> 16;
Mugunthan V Nb1e26e32013-07-08 16:04:41 +0530331 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
Mugunthan V Ne0a1d592014-01-07 19:57:38 +0530332 mac_addr[2] = mac_hi & 0xFF;
333 mac_addr[3] = (mac_lo & 0xFF0000) >> 16;
Mugunthan V Nb1e26e32013-07-08 16:04:41 +0530334 mac_addr[4] = (mac_lo & 0xFF00) >> 8;
Mugunthan V Ne0a1d592014-01-07 19:57:38 +0530335 mac_addr[5] = mac_lo & 0xFF;
Mugunthan V Nb1e26e32013-07-08 16:04:41 +0530336
337 if (!getenv("ethaddr")) {
338 printf("<ethaddr> not set. Validating first E-fuse MAC\n");
339
Joe Hershberger0adb5b72015-04-08 01:41:04 -0500340 if (is_valid_ethaddr(mac_addr))
Mugunthan V Nb1e26e32013-07-08 16:04:41 +0530341 eth_setenv_enetaddr("ethaddr", mac_addr);
342 }
Mugunthan V N8feb37b2014-02-18 07:31:56 -0500343
344 mac_lo = readl((*ctrl)->control_core_mac_id_1_lo);
345 mac_hi = readl((*ctrl)->control_core_mac_id_1_hi);
346 mac_addr[0] = (mac_hi & 0xFF0000) >> 16;
347 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
348 mac_addr[2] = mac_hi & 0xFF;
349 mac_addr[3] = (mac_lo & 0xFF0000) >> 16;
350 mac_addr[4] = (mac_lo & 0xFF00) >> 8;
351 mac_addr[5] = mac_lo & 0xFF;
352
353 if (!getenv("eth1addr")) {
Joe Hershberger0adb5b72015-04-08 01:41:04 -0500354 if (is_valid_ethaddr(mac_addr))
Mugunthan V N8feb37b2014-02-18 07:31:56 -0500355 eth_setenv_enetaddr("eth1addr", mac_addr);
356 }
357
Mugunthan V Nb1e26e32013-07-08 16:04:41 +0530358 ctrl_val = readl((*ctrl)->control_core_control_io1) & (~0x33);
359 ctrl_val |= 0x22;
360 writel(ctrl_val, (*ctrl)->control_core_control_io1);
361
Mugunthan V N4c8014b2014-05-22 14:37:12 +0530362 if (*omap_si_rev == DRA722_ES1_0)
363 cpsw_data.active_slave = 1;
364
Mugunthan V Nb1e26e32013-07-08 16:04:41 +0530365 ret = cpsw_register(&cpsw_data);
366 if (ret < 0)
367 printf("Error %d registering CPSW switch\n", ret);
368
369 return ret;
370}
371#endif
Lokesh Vutla7b922522014-08-04 19:42:24 +0530372
373#ifdef CONFIG_BOARD_EARLY_INIT_F
374/* VTT regulator enable */
375static inline void vtt_regulator_enable(void)
376{
377 if (omap_hw_init_context() == OMAP_INIT_CONTEXT_UBOOT_AFTER_SPL)
378 return;
379
380 /* Do not enable VTT for DRA722 */
381 if (omap_revision() == DRA722_ES1_0)
382 return;
383
384 /*
385 * EVM Rev G and later use gpio7_11 for DDR3 termination.
386 * This is safe enough to do on older revs.
387 */
388 gpio_request(GPIO_DDR_VTT_EN, "ddr_vtt_en");
389 gpio_direction_output(GPIO_DDR_VTT_EN, 1);
390}
391
392int board_early_init_f(void)
393{
394 vtt_regulator_enable();
395 return 0;
396}
397#endif