blob: 5592fc5defebd4faab3403b072e3e233dc572780 [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>
17#include <asm/arch/gpio.h>
Lokesh Vutla687054a2013-02-12 21:29:08 +000018#include <asm/arch/sys_proto.h>
19#include <asm/arch/mmc_host_def.h>
Roger Quadros21914ee2013-11-11 16:56:44 +020020#include <asm/arch/sata.h>
Tom Rini79b079f2014-04-03 07:52:56 -040021#include <environment.h>
Lokesh Vutla687054a2013-02-12 21:29:08 +000022
23#include "mux_data.h"
24
Mugunthan V Nb1e26e32013-07-08 16:04:41 +053025#ifdef CONFIG_DRIVER_TI_CPSW
26#include <cpsw.h>
27#endif
28
Lokesh Vutla687054a2013-02-12 21:29:08 +000029DECLARE_GLOBAL_DATA_PTR;
30
Lokesh Vutla7b922522014-08-04 19:42:24 +053031/* GPIO 7_11 */
32#define GPIO_DDR_VTT_EN 203
33
Lokesh Vutla687054a2013-02-12 21:29:08 +000034const struct omap_sysinfo sysinfo = {
35 "Board: DRA7xx\n"
36};
37
Mugunthan V Nb1e26e32013-07-08 16:04:41 +053038/*
39 * Adjust I/O delays on the Tx control and data lines of each MAC port. This
40 * is a workaround in order to work properly with the DP83865 PHYs on the EVM.
41 * In 3COM RGMII mode this PHY applies it's own internal clock delay, so we
42 * essentially need to counteract the DRA7xx internal delay, and we do this
43 * by delaying the control and data lines. If not using this PHY, you probably
44 * don't need to do this stuff!
45 */
46static void dra7xx_adj_io_delay(const struct io_delay *io_dly)
47{
48 int i = 0;
49 u32 reg_val;
50 u32 delta;
51 u32 coarse;
52 u32 fine;
53
54 writel(CFG_IO_DELAY_UNLOCK_KEY, CFG_IO_DELAY_LOCK);
55
56 while(io_dly[i].addr) {
57 writel(CFG_IO_DELAY_ACCESS_PATTERN & ~CFG_IO_DELAY_LOCK_MASK,
58 io_dly[i].addr);
59 delta = io_dly[i].dly;
60 reg_val = readl(io_dly[i].addr) & 0x3ff;
61 coarse = ((reg_val >> 5) & 0x1F) + ((delta >> 5) & 0x1F);
62 coarse = (coarse > 0x1F) ? (0x1F) : (coarse);
63 fine = (reg_val & 0x1F) + (delta & 0x1F);
64 fine = (fine > 0x1F) ? (0x1F) : (fine);
65 reg_val = CFG_IO_DELAY_ACCESS_PATTERN |
66 CFG_IO_DELAY_LOCK_MASK |
67 ((coarse << 5) | (fine));
68 writel(reg_val, io_dly[i].addr);
69 i++;
70 }
71
72 writel(CFG_IO_DELAY_LOCK_KEY, CFG_IO_DELAY_LOCK);
73}
74
Lokesh Vutla687054a2013-02-12 21:29:08 +000075/**
76 * @brief board_init
77 *
78 * @return 0
79 */
80int board_init(void)
81{
82 gpmc_init();
83 gd->bd->bi_boot_params = (0x80000000 + 0x100); /* boot param addr */
84
85 return 0;
86}
87
Roger Quadros21914ee2013-11-11 16:56:44 +020088int board_late_init(void)
89{
Lokesh Vutla4ec3f6e2014-07-14 19:57:58 +053090#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
91 if (omap_revision() == DRA722_ES1_0)
92 setenv("board_name", "dra72x");
93 else
94 setenv("board_name", "dra7xx");
95#endif
Dan Murphye9024ef2014-02-03 06:59:02 -060096 init_sata(0);
Roger Quadros21914ee2013-11-11 16:56:44 +020097 return 0;
98}
99
Lokesh Vutla687054a2013-02-12 21:29:08 +0000100/**
101 * @brief misc_init_r - Configure EVM board specific configurations
102 * such as power configurations, ethernet initialization as phase2 of
103 * boot sequence
104 *
105 * @return 0
106 */
107int misc_init_r(void)
108{
109 return 0;
110}
111
112static void do_set_mux32(u32 base,
113 struct pad_conf_entry const *array, int size)
114{
115 int i;
116 struct pad_conf_entry *pad = (struct pad_conf_entry *)array;
117
118 for (i = 0; i < size; i++, pad++)
119 writel(pad->val, base + pad->offset);
120}
121
122void set_muxconf_regs_essential(void)
123{
124 do_set_mux32((*ctrl)->control_padconf_core_base,
125 core_padconf_array_essential,
126 sizeof(core_padconf_array_essential) /
127 sizeof(struct pad_conf_entry));
128}
129
130#if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_GENERIC_MMC)
131int board_mmc_init(bd_t *bis)
132{
133 omap_mmc_init(0, 0, 0, -1, -1);
134 omap_mmc_init(1, 0, 0, -1, -1);
135 return 0;
136}
137#endif
Mugunthan V Nb1e26e32013-07-08 16:04:41 +0530138
Tom Rini79b079f2014-04-03 07:52:56 -0400139#if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_OS_BOOT)
140int spl_start_uboot(void)
141{
142 /* break into full u-boot on 'c' */
143 if (serial_tstc() && serial_getc() == 'c')
144 return 1;
145
146#ifdef CONFIG_SPL_ENV_SUPPORT
147 env_init();
148 env_relocate_spec();
149 if (getenv_yesno("boot_os") != 1)
150 return 1;
151#endif
152
153 return 0;
154}
155#endif
156
Mugunthan V Nb1e26e32013-07-08 16:04:41 +0530157#ifdef CONFIG_DRIVER_TI_CPSW
158
159/* Delay value to add to calibrated value */
160#define RGMII0_TXCTL_DLY_VAL ((0x3 << 5) + 0x8)
161#define RGMII0_TXD0_DLY_VAL ((0x3 << 5) + 0x8)
162#define RGMII0_TXD1_DLY_VAL ((0x3 << 5) + 0x2)
163#define RGMII0_TXD2_DLY_VAL ((0x4 << 5) + 0x0)
164#define RGMII0_TXD3_DLY_VAL ((0x4 << 5) + 0x0)
165#define VIN2A_D13_DLY_VAL ((0x3 << 5) + 0x8)
166#define VIN2A_D17_DLY_VAL ((0x3 << 5) + 0x8)
167#define VIN2A_D16_DLY_VAL ((0x3 << 5) + 0x2)
168#define VIN2A_D15_DLY_VAL ((0x4 << 5) + 0x0)
169#define VIN2A_D14_DLY_VAL ((0x4 << 5) + 0x0)
170
Mugunthan V N4c8014b2014-05-22 14:37:12 +0530171extern u32 *const omap_si_rev;
172
Mugunthan V Nb1e26e32013-07-08 16:04:41 +0530173static void cpsw_control(int enabled)
174{
175 /* VTP can be added here */
176
177 return;
178}
179
180static struct cpsw_slave_data cpsw_slaves[] = {
181 {
182 .slave_reg_ofs = 0x208,
183 .sliver_reg_ofs = 0xd80,
Mugunthan V N9c653aa2014-02-18 07:31:52 -0500184 .phy_addr = 2,
Mugunthan V Nb1e26e32013-07-08 16:04:41 +0530185 },
186 {
187 .slave_reg_ofs = 0x308,
188 .sliver_reg_ofs = 0xdc0,
Mugunthan V N9c653aa2014-02-18 07:31:52 -0500189 .phy_addr = 3,
Mugunthan V Nb1e26e32013-07-08 16:04:41 +0530190 },
191};
192
193static struct cpsw_platform_data cpsw_data = {
194 .mdio_base = CPSW_MDIO_BASE,
195 .cpsw_base = CPSW_BASE,
196 .mdio_div = 0xff,
197 .channels = 8,
198 .cpdma_reg_ofs = 0x800,
Mugunthan V N4c8014b2014-05-22 14:37:12 +0530199 .slaves = 2,
Mugunthan V Nb1e26e32013-07-08 16:04:41 +0530200 .slave_data = cpsw_slaves,
201 .ale_reg_ofs = 0xd00,
202 .ale_entries = 1024,
203 .host_port_reg_ofs = 0x108,
204 .hw_stats_reg_ofs = 0x900,
205 .bd_ram_ofs = 0x2000,
206 .mac_control = (1 << 5),
207 .control = cpsw_control,
208 .host_port_num = 0,
209 .version = CPSW_CTRL_VERSION_2,
210};
211
212int board_eth_init(bd_t *bis)
213{
214 int ret;
215 uint8_t mac_addr[6];
216 uint32_t mac_hi, mac_lo;
217 uint32_t ctrl_val;
218 const struct io_delay io_dly[] = {
219 {CFG_RGMII0_TXCTL, RGMII0_TXCTL_DLY_VAL},
220 {CFG_RGMII0_TXD0, RGMII0_TXD0_DLY_VAL},
221 {CFG_RGMII0_TXD1, RGMII0_TXD1_DLY_VAL},
222 {CFG_RGMII0_TXD2, RGMII0_TXD2_DLY_VAL},
223 {CFG_RGMII0_TXD3, RGMII0_TXD3_DLY_VAL},
224 {CFG_VIN2A_D13, VIN2A_D13_DLY_VAL},
225 {CFG_VIN2A_D17, VIN2A_D17_DLY_VAL},
226 {CFG_VIN2A_D16, VIN2A_D16_DLY_VAL},
227 {CFG_VIN2A_D15, VIN2A_D15_DLY_VAL},
228 {CFG_VIN2A_D14, VIN2A_D14_DLY_VAL},
229 {0}
230 };
231
232 /* Adjust IO delay for RGMII tx path */
233 dra7xx_adj_io_delay(io_dly);
234
235 /* try reading mac address from efuse */
236 mac_lo = readl((*ctrl)->control_core_mac_id_0_lo);
237 mac_hi = readl((*ctrl)->control_core_mac_id_0_hi);
Mugunthan V Ne0a1d592014-01-07 19:57:38 +0530238 mac_addr[0] = (mac_hi & 0xFF0000) >> 16;
Mugunthan V Nb1e26e32013-07-08 16:04:41 +0530239 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
Mugunthan V Ne0a1d592014-01-07 19:57:38 +0530240 mac_addr[2] = mac_hi & 0xFF;
241 mac_addr[3] = (mac_lo & 0xFF0000) >> 16;
Mugunthan V Nb1e26e32013-07-08 16:04:41 +0530242 mac_addr[4] = (mac_lo & 0xFF00) >> 8;
Mugunthan V Ne0a1d592014-01-07 19:57:38 +0530243 mac_addr[5] = mac_lo & 0xFF;
Mugunthan V Nb1e26e32013-07-08 16:04:41 +0530244
245 if (!getenv("ethaddr")) {
246 printf("<ethaddr> not set. Validating first E-fuse MAC\n");
247
248 if (is_valid_ether_addr(mac_addr))
249 eth_setenv_enetaddr("ethaddr", mac_addr);
250 }
Mugunthan V N8feb37b2014-02-18 07:31:56 -0500251
252 mac_lo = readl((*ctrl)->control_core_mac_id_1_lo);
253 mac_hi = readl((*ctrl)->control_core_mac_id_1_hi);
254 mac_addr[0] = (mac_hi & 0xFF0000) >> 16;
255 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
256 mac_addr[2] = mac_hi & 0xFF;
257 mac_addr[3] = (mac_lo & 0xFF0000) >> 16;
258 mac_addr[4] = (mac_lo & 0xFF00) >> 8;
259 mac_addr[5] = mac_lo & 0xFF;
260
261 if (!getenv("eth1addr")) {
262 if (is_valid_ether_addr(mac_addr))
263 eth_setenv_enetaddr("eth1addr", mac_addr);
264 }
265
Mugunthan V Nb1e26e32013-07-08 16:04:41 +0530266 ctrl_val = readl((*ctrl)->control_core_control_io1) & (~0x33);
267 ctrl_val |= 0x22;
268 writel(ctrl_val, (*ctrl)->control_core_control_io1);
269
Mugunthan V N4c8014b2014-05-22 14:37:12 +0530270 if (*omap_si_rev == DRA722_ES1_0)
271 cpsw_data.active_slave = 1;
272
Mugunthan V Nb1e26e32013-07-08 16:04:41 +0530273 ret = cpsw_register(&cpsw_data);
274 if (ret < 0)
275 printf("Error %d registering CPSW switch\n", ret);
276
277 return ret;
278}
279#endif
Lokesh Vutla7b922522014-08-04 19:42:24 +0530280
281#ifdef CONFIG_BOARD_EARLY_INIT_F
282/* VTT regulator enable */
283static inline void vtt_regulator_enable(void)
284{
285 if (omap_hw_init_context() == OMAP_INIT_CONTEXT_UBOOT_AFTER_SPL)
286 return;
287
288 /* Do not enable VTT for DRA722 */
289 if (omap_revision() == DRA722_ES1_0)
290 return;
291
292 /*
293 * EVM Rev G and later use gpio7_11 for DDR3 termination.
294 * This is safe enough to do on older revs.
295 */
296 gpio_request(GPIO_DDR_VTT_EN, "ddr_vtt_en");
297 gpio_direction_output(GPIO_DDR_VTT_EN, 1);
298}
299
300int board_early_init_f(void)
301{
302 vtt_regulator_enable();
303 return 0;
304}
305#endif