blob: 06adaac70adc51e0ec3ad8b72c22d2780203e723 [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{
120 __recalibrate_iodelay(core_padconf_array_essential,
121 ARRAY_SIZE(core_padconf_array_essential),
122 iodelay_cfg_array, ARRAY_SIZE(iodelay_cfg_array));
123}
124#endif
125
Lokesh Vutla687054a2013-02-12 21:29:08 +0000126#if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_GENERIC_MMC)
127int board_mmc_init(bd_t *bis)
128{
129 omap_mmc_init(0, 0, 0, -1, -1);
130 omap_mmc_init(1, 0, 0, -1, -1);
131 return 0;
132}
133#endif
Mugunthan V Nb1e26e32013-07-08 16:04:41 +0530134
Kishon Vijay Abraham Ia17188c2015-02-23 18:40:19 +0530135#ifdef CONFIG_USB_DWC3
136static struct dwc3_device usb_otg_ss1 = {
137 .maximum_speed = USB_SPEED_SUPER,
138 .base = DRA7_USB_OTG_SS1_BASE,
139 .tx_fifo_resize = false,
140 .index = 0,
141};
142
143static struct dwc3_omap_device usb_otg_ss1_glue = {
144 .base = (void *)DRA7_USB_OTG_SS1_GLUE_BASE,
145 .utmi_mode = DWC3_OMAP_UTMI_MODE_SW,
146 .vbus_id_status = OMAP_DWC3_VBUS_VALID,
147 .index = 0,
148};
149
150static struct ti_usb_phy_device usb_phy1_device = {
151 .pll_ctrl_base = (void *)DRA7_USB3_PHY1_PLL_CTRL,
152 .usb2_phy_power = (void *)DRA7_USB2_PHY1_POWER,
153 .usb3_phy_power = (void *)DRA7_USB3_PHY1_POWER,
154 .index = 0,
155};
156
157static struct dwc3_device usb_otg_ss2 = {
158 .maximum_speed = USB_SPEED_SUPER,
159 .base = DRA7_USB_OTG_SS2_BASE,
160 .tx_fifo_resize = false,
161 .index = 1,
162};
163
164static struct dwc3_omap_device usb_otg_ss2_glue = {
165 .base = (void *)DRA7_USB_OTG_SS2_GLUE_BASE,
166 .utmi_mode = DWC3_OMAP_UTMI_MODE_SW,
167 .vbus_id_status = OMAP_DWC3_VBUS_VALID,
168 .index = 1,
169};
170
171static struct ti_usb_phy_device usb_phy2_device = {
172 .usb2_phy_power = (void *)DRA7_USB2_PHY2_POWER,
173 .index = 1,
174};
175
176int board_usb_init(int index, enum usb_init_type init)
177{
178 switch (index) {
179 case 0:
180 if (init == USB_INIT_DEVICE) {
181 usb_otg_ss1.dr_mode = USB_DR_MODE_PERIPHERAL;
182 usb_otg_ss1_glue.vbus_id_status = OMAP_DWC3_VBUS_VALID;
183 } else {
184 usb_otg_ss1.dr_mode = USB_DR_MODE_HOST;
185 usb_otg_ss1_glue.vbus_id_status = OMAP_DWC3_ID_GROUND;
186 }
187
188 ti_usb_phy_uboot_init(&usb_phy1_device);
189 dwc3_omap_uboot_init(&usb_otg_ss1_glue);
190 dwc3_uboot_init(&usb_otg_ss1);
191 break;
192 case 1:
193 if (init == USB_INIT_DEVICE) {
194 usb_otg_ss2.dr_mode = USB_DR_MODE_PERIPHERAL;
195 usb_otg_ss2_glue.vbus_id_status = OMAP_DWC3_VBUS_VALID;
196 } else {
197 usb_otg_ss2.dr_mode = USB_DR_MODE_HOST;
198 usb_otg_ss2_glue.vbus_id_status = OMAP_DWC3_ID_GROUND;
199 }
200
201 ti_usb_phy_uboot_init(&usb_phy2_device);
202 dwc3_omap_uboot_init(&usb_otg_ss2_glue);
203 dwc3_uboot_init(&usb_otg_ss2);
204 break;
205 default:
206 printf("Invalid Controller Index\n");
207 }
208
209 return 0;
210}
211
212int board_usb_cleanup(int index, enum usb_init_type init)
213{
214 switch (index) {
215 case 0:
216 case 1:
217 ti_usb_phy_uboot_exit(index);
218 dwc3_uboot_exit(index);
219 dwc3_omap_uboot_exit(index);
220 break;
221 default:
222 printf("Invalid Controller Index\n");
223 }
224 return 0;
225}
226
Kishon Vijay Abraham I2d48aa62015-02-23 18:40:23 +0530227int usb_gadget_handle_interrupts(int index)
Kishon Vijay Abraham Ia17188c2015-02-23 18:40:19 +0530228{
229 u32 status;
230
Kishon Vijay Abraham I2d48aa62015-02-23 18:40:23 +0530231 status = dwc3_omap_uboot_interrupt_status(index);
Kishon Vijay Abraham Ia17188c2015-02-23 18:40:19 +0530232 if (status)
Kishon Vijay Abraham I2d48aa62015-02-23 18:40:23 +0530233 dwc3_uboot_handle_interrupt(index);
Kishon Vijay Abraham Ia17188c2015-02-23 18:40:19 +0530234
235 return 0;
236}
237#endif
238
Tom Rini79b079f2014-04-03 07:52:56 -0400239#if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_OS_BOOT)
240int spl_start_uboot(void)
241{
242 /* break into full u-boot on 'c' */
243 if (serial_tstc() && serial_getc() == 'c')
244 return 1;
245
246#ifdef CONFIG_SPL_ENV_SUPPORT
247 env_init();
248 env_relocate_spec();
249 if (getenv_yesno("boot_os") != 1)
250 return 1;
251#endif
252
253 return 0;
254}
255#endif
256
Mugunthan V Nb1e26e32013-07-08 16:04:41 +0530257#ifdef CONFIG_DRIVER_TI_CPSW
258
259/* Delay value to add to calibrated value */
260#define RGMII0_TXCTL_DLY_VAL ((0x3 << 5) + 0x8)
261#define RGMII0_TXD0_DLY_VAL ((0x3 << 5) + 0x8)
262#define RGMII0_TXD1_DLY_VAL ((0x3 << 5) + 0x2)
263#define RGMII0_TXD2_DLY_VAL ((0x4 << 5) + 0x0)
264#define RGMII0_TXD3_DLY_VAL ((0x4 << 5) + 0x0)
265#define VIN2A_D13_DLY_VAL ((0x3 << 5) + 0x8)
266#define VIN2A_D17_DLY_VAL ((0x3 << 5) + 0x8)
267#define VIN2A_D16_DLY_VAL ((0x3 << 5) + 0x2)
268#define VIN2A_D15_DLY_VAL ((0x4 << 5) + 0x0)
269#define VIN2A_D14_DLY_VAL ((0x4 << 5) + 0x0)
270
Mugunthan V N4c8014b2014-05-22 14:37:12 +0530271extern u32 *const omap_si_rev;
272
Mugunthan V Nb1e26e32013-07-08 16:04:41 +0530273static void cpsw_control(int enabled)
274{
275 /* VTP can be added here */
276
277 return;
278}
279
280static struct cpsw_slave_data cpsw_slaves[] = {
281 {
282 .slave_reg_ofs = 0x208,
283 .sliver_reg_ofs = 0xd80,
Mugunthan V N9c653aa2014-02-18 07:31:52 -0500284 .phy_addr = 2,
Mugunthan V Nb1e26e32013-07-08 16:04:41 +0530285 },
286 {
287 .slave_reg_ofs = 0x308,
288 .sliver_reg_ofs = 0xdc0,
Mugunthan V N9c653aa2014-02-18 07:31:52 -0500289 .phy_addr = 3,
Mugunthan V Nb1e26e32013-07-08 16:04:41 +0530290 },
291};
292
293static struct cpsw_platform_data cpsw_data = {
294 .mdio_base = CPSW_MDIO_BASE,
295 .cpsw_base = CPSW_BASE,
296 .mdio_div = 0xff,
297 .channels = 8,
298 .cpdma_reg_ofs = 0x800,
Mugunthan V N4c8014b2014-05-22 14:37:12 +0530299 .slaves = 2,
Mugunthan V Nb1e26e32013-07-08 16:04:41 +0530300 .slave_data = cpsw_slaves,
301 .ale_reg_ofs = 0xd00,
302 .ale_entries = 1024,
303 .host_port_reg_ofs = 0x108,
304 .hw_stats_reg_ofs = 0x900,
305 .bd_ram_ofs = 0x2000,
306 .mac_control = (1 << 5),
307 .control = cpsw_control,
308 .host_port_num = 0,
309 .version = CPSW_CTRL_VERSION_2,
310};
311
312int board_eth_init(bd_t *bis)
313{
314 int ret;
315 uint8_t mac_addr[6];
316 uint32_t mac_hi, mac_lo;
317 uint32_t ctrl_val;
318 const struct io_delay io_dly[] = {
319 {CFG_RGMII0_TXCTL, RGMII0_TXCTL_DLY_VAL},
320 {CFG_RGMII0_TXD0, RGMII0_TXD0_DLY_VAL},
321 {CFG_RGMII0_TXD1, RGMII0_TXD1_DLY_VAL},
322 {CFG_RGMII0_TXD2, RGMII0_TXD2_DLY_VAL},
323 {CFG_RGMII0_TXD3, RGMII0_TXD3_DLY_VAL},
324 {CFG_VIN2A_D13, VIN2A_D13_DLY_VAL},
325 {CFG_VIN2A_D17, VIN2A_D17_DLY_VAL},
326 {CFG_VIN2A_D16, VIN2A_D16_DLY_VAL},
327 {CFG_VIN2A_D15, VIN2A_D15_DLY_VAL},
328 {CFG_VIN2A_D14, VIN2A_D14_DLY_VAL},
329 {0}
330 };
331
332 /* Adjust IO delay for RGMII tx path */
333 dra7xx_adj_io_delay(io_dly);
334
335 /* try reading mac address from efuse */
336 mac_lo = readl((*ctrl)->control_core_mac_id_0_lo);
337 mac_hi = readl((*ctrl)->control_core_mac_id_0_hi);
Mugunthan V Ne0a1d592014-01-07 19:57:38 +0530338 mac_addr[0] = (mac_hi & 0xFF0000) >> 16;
Mugunthan V Nb1e26e32013-07-08 16:04:41 +0530339 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
Mugunthan V Ne0a1d592014-01-07 19:57:38 +0530340 mac_addr[2] = mac_hi & 0xFF;
341 mac_addr[3] = (mac_lo & 0xFF0000) >> 16;
Mugunthan V Nb1e26e32013-07-08 16:04:41 +0530342 mac_addr[4] = (mac_lo & 0xFF00) >> 8;
Mugunthan V Ne0a1d592014-01-07 19:57:38 +0530343 mac_addr[5] = mac_lo & 0xFF;
Mugunthan V Nb1e26e32013-07-08 16:04:41 +0530344
345 if (!getenv("ethaddr")) {
346 printf("<ethaddr> not set. Validating first E-fuse MAC\n");
347
Joe Hershberger0adb5b72015-04-08 01:41:04 -0500348 if (is_valid_ethaddr(mac_addr))
Mugunthan V Nb1e26e32013-07-08 16:04:41 +0530349 eth_setenv_enetaddr("ethaddr", mac_addr);
350 }
Mugunthan V N8feb37b2014-02-18 07:31:56 -0500351
352 mac_lo = readl((*ctrl)->control_core_mac_id_1_lo);
353 mac_hi = readl((*ctrl)->control_core_mac_id_1_hi);
354 mac_addr[0] = (mac_hi & 0xFF0000) >> 16;
355 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
356 mac_addr[2] = mac_hi & 0xFF;
357 mac_addr[3] = (mac_lo & 0xFF0000) >> 16;
358 mac_addr[4] = (mac_lo & 0xFF00) >> 8;
359 mac_addr[5] = mac_lo & 0xFF;
360
361 if (!getenv("eth1addr")) {
Joe Hershberger0adb5b72015-04-08 01:41:04 -0500362 if (is_valid_ethaddr(mac_addr))
Mugunthan V N8feb37b2014-02-18 07:31:56 -0500363 eth_setenv_enetaddr("eth1addr", mac_addr);
364 }
365
Mugunthan V Nb1e26e32013-07-08 16:04:41 +0530366 ctrl_val = readl((*ctrl)->control_core_control_io1) & (~0x33);
367 ctrl_val |= 0x22;
368 writel(ctrl_val, (*ctrl)->control_core_control_io1);
369
Mugunthan V N4c8014b2014-05-22 14:37:12 +0530370 if (*omap_si_rev == DRA722_ES1_0)
371 cpsw_data.active_slave = 1;
372
Mugunthan V Nb1e26e32013-07-08 16:04:41 +0530373 ret = cpsw_register(&cpsw_data);
374 if (ret < 0)
375 printf("Error %d registering CPSW switch\n", ret);
376
377 return ret;
378}
379#endif
Lokesh Vutla7b922522014-08-04 19:42:24 +0530380
381#ifdef CONFIG_BOARD_EARLY_INIT_F
382/* VTT regulator enable */
383static inline void vtt_regulator_enable(void)
384{
385 if (omap_hw_init_context() == OMAP_INIT_CONTEXT_UBOOT_AFTER_SPL)
386 return;
387
388 /* Do not enable VTT for DRA722 */
389 if (omap_revision() == DRA722_ES1_0)
390 return;
391
392 /*
393 * EVM Rev G and later use gpio7_11 for DDR3 termination.
394 * This is safe enough to do on older revs.
395 */
396 gpio_request(GPIO_DDR_VTT_EN, "ddr_vtt_en");
397 gpio_direction_output(GPIO_DDR_VTT_EN, 1);
398}
399
400int board_early_init_f(void)
401{
402 vtt_regulator_enable();
403 return 0;
404}
405#endif