blob: 638cc4d68b2ad5238443c6c180f378e66278b826 [file] [log] [blame]
Peter Korsgaard85ec2db2012-10-18 01:21:09 +00001/*
2 * board.c
3 *
4 * Board functions for TI AM335X based boards
5 *
6 * Copyright (C) 2011, Texas Instruments, Incorporated - http://www.ti.com/
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR /PURPOSE. See the
16 * GNU General Public License for more details.
17 */
18
19#include <common.h>
20#include <errno.h>
21#include <spl.h>
22#include <asm/arch/cpu.h>
23#include <asm/arch/hardware.h>
24#include <asm/arch/omap.h>
25#include <asm/arch/ddr_defs.h>
26#include <asm/arch/clock.h>
27#include <asm/arch/gpio.h>
28#include <asm/arch/mmc_host_def.h>
29#include <asm/arch/sys_proto.h>
30#include <asm/io.h>
31#include <asm/emif.h>
32#include <asm/gpio.h>
33#include <i2c.h>
34#include <miiphy.h>
35#include <cpsw.h>
36#include "board.h"
37
38DECLARE_GLOBAL_DATA_PTR;
39
40static struct wd_timer *wdtimer = (struct wd_timer *)WDT_BASE;
41#ifdef CONFIG_SPL_BUILD
42static struct uart_sys *uart_base = (struct uart_sys *)DEFAULT_UART_BASE;
43#endif
44
45/* MII mode defines */
46#define MII_MODE_ENABLE 0x0
Yegor Yefremove44314a2012-11-26 03:30:42 +000047#define RGMII_MODE_ENABLE 0x3A
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000048
49/* GPIO that controls power to DDR on EVM-SK */
50#define GPIO_DDR_VTT_EN 7
51
52static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
53
54static struct am335x_baseboard_id __attribute__((section (".data"))) header;
55
56static inline int board_is_bone(void)
57{
58 return !strncmp(header.name, "A335BONE", HDR_NAME_LEN);
59}
60
61static inline int board_is_bone_lt(void)
62{
63 return !strncmp(header.name, "A335BNLT", HDR_NAME_LEN);
64}
65
66static inline int board_is_evm_sk(void)
67{
68 return !strncmp("A335X_SK", header.name, HDR_NAME_LEN);
69}
70
Matthias Fuchs63ffc5a2012-11-02 03:35:59 +000071static inline int board_is_idk(void)
72{
73 return !strncmp(header.config, "SKU#02", 6);
74}
75
Tom Rini35eafab2013-02-26 15:43:22 -050076static int __maybe_unused board_is_gp_evm(void)
Tom Rini183943d2013-02-12 14:59:23 -050077{
78 return !strncmp("A33515BB", header.name, 8);
79}
80
Jeff Lance7c03a222013-01-14 05:32:20 +000081int board_is_evm_15_or_later(void)
82{
83 return (!strncmp("A33515BB", header.name, 8) &&
84 strncmp("1.5", header.version, 3) <= 0);
85}
86
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000087/*
88 * Read header information from EEPROM into global structure.
89 */
90static int read_eeprom(void)
91{
92 /* Check if baseboard eeprom is available */
93 if (i2c_probe(CONFIG_SYS_I2C_EEPROM_ADDR)) {
94 puts("Could not probe the EEPROM; something fundamentally "
95 "wrong on the I2C bus.\n");
96 return -ENODEV;
97 }
98
99 /* read the eeprom using i2c */
100 if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0, 2, (uchar *)&header,
101 sizeof(header))) {
102 puts("Could not read the EEPROM; something fundamentally"
103 " wrong on the I2C bus.\n");
104 return -EIO;
105 }
106
107 if (header.magic != 0xEE3355AA) {
108 /*
109 * read the eeprom using i2c again,
110 * but use only a 1 byte address
111 */
112 if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0, 1,
113 (uchar *)&header, sizeof(header))) {
114 puts("Could not read the EEPROM; something "
115 "fundamentally wrong on the I2C bus.\n");
116 return -EIO;
117 }
118
119 if (header.magic != 0xEE3355AA) {
120 printf("Incorrect magic number (0x%x) in EEPROM\n",
121 header.magic);
122 return -EINVAL;
123 }
124 }
125
126 return 0;
127}
128
129/* UART Defines */
130#ifdef CONFIG_SPL_BUILD
131#define UART_RESET (0x1 << 1)
132#define UART_CLK_RUNNING_MASK 0x1
133#define UART_SMART_IDLE_EN (0x1 << 0x3)
134
135static void rtc32k_enable(void)
136{
Matt Portere24646f2013-03-15 10:07:02 +0000137 struct rtc_regs *rtc = (struct rtc_regs *)RTC_BASE;
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000138
139 /*
140 * Unlock the RTC's registers. For more details please see the
141 * RTC_SS section of the TRM. In order to unlock we need to
142 * write these specific values (keys) in this order.
143 */
144 writel(0x83e70b13, &rtc->kick0r);
145 writel(0x95a4f1e0, &rtc->kick1r);
146
147 /* Enable the RTC 32K OSC by setting bits 3 and 6. */
148 writel((1 << 3) | (1 << 6), &rtc->osc);
149}
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000150
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000151static const struct ddr_data ddr2_data = {
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000152 .datardsratio0 = ((MT47H128M16RT25E_RD_DQS<<30) |
153 (MT47H128M16RT25E_RD_DQS<<20) |
154 (MT47H128M16RT25E_RD_DQS<<10) |
155 (MT47H128M16RT25E_RD_DQS<<0)),
156 .datawdsratio0 = ((MT47H128M16RT25E_WR_DQS<<30) |
157 (MT47H128M16RT25E_WR_DQS<<20) |
158 (MT47H128M16RT25E_WR_DQS<<10) |
159 (MT47H128M16RT25E_WR_DQS<<0)),
160 .datawiratio0 = ((MT47H128M16RT25E_PHY_WRLVL<<30) |
161 (MT47H128M16RT25E_PHY_WRLVL<<20) |
162 (MT47H128M16RT25E_PHY_WRLVL<<10) |
163 (MT47H128M16RT25E_PHY_WRLVL<<0)),
164 .datagiratio0 = ((MT47H128M16RT25E_PHY_GATELVL<<30) |
165 (MT47H128M16RT25E_PHY_GATELVL<<20) |
166 (MT47H128M16RT25E_PHY_GATELVL<<10) |
167 (MT47H128M16RT25E_PHY_GATELVL<<0)),
168 .datafwsratio0 = ((MT47H128M16RT25E_PHY_FIFO_WE<<30) |
169 (MT47H128M16RT25E_PHY_FIFO_WE<<20) |
170 (MT47H128M16RT25E_PHY_FIFO_WE<<10) |
171 (MT47H128M16RT25E_PHY_FIFO_WE<<0)),
172 .datawrsratio0 = ((MT47H128M16RT25E_PHY_WR_DATA<<30) |
173 (MT47H128M16RT25E_PHY_WR_DATA<<20) |
174 (MT47H128M16RT25E_PHY_WR_DATA<<10) |
175 (MT47H128M16RT25E_PHY_WR_DATA<<0)),
176 .datauserank0delay = MT47H128M16RT25E_PHY_RANK0_DELAY,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000177 .datadldiff0 = PHY_DLL_LOCK_DIFF,
178};
179
180static const struct cmd_control ddr2_cmd_ctrl_data = {
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000181 .cmd0csratio = MT47H128M16RT25E_RATIO,
182 .cmd0dldiff = MT47H128M16RT25E_DLL_LOCK_DIFF,
183 .cmd0iclkout = MT47H128M16RT25E_INVERT_CLKOUT,
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000184
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000185 .cmd1csratio = MT47H128M16RT25E_RATIO,
186 .cmd1dldiff = MT47H128M16RT25E_DLL_LOCK_DIFF,
187 .cmd1iclkout = MT47H128M16RT25E_INVERT_CLKOUT,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000188
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000189 .cmd2csratio = MT47H128M16RT25E_RATIO,
190 .cmd2dldiff = MT47H128M16RT25E_DLL_LOCK_DIFF,
191 .cmd2iclkout = MT47H128M16RT25E_INVERT_CLKOUT,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000192};
193
194static const struct emif_regs ddr2_emif_reg_data = {
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000195 .sdram_config = MT47H128M16RT25E_EMIF_SDCFG,
196 .ref_ctrl = MT47H128M16RT25E_EMIF_SDREF,
197 .sdram_tim1 = MT47H128M16RT25E_EMIF_TIM1,
198 .sdram_tim2 = MT47H128M16RT25E_EMIF_TIM2,
199 .sdram_tim3 = MT47H128M16RT25E_EMIF_TIM3,
200 .emif_ddr_phy_ctlr_1 = MT47H128M16RT25E_EMIF_READ_LATENCY,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000201};
202
203static const struct ddr_data ddr3_data = {
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000204 .datardsratio0 = MT41J128MJT125_RD_DQS,
205 .datawdsratio0 = MT41J128MJT125_WR_DQS,
206 .datafwsratio0 = MT41J128MJT125_PHY_FIFO_WE,
207 .datawrsratio0 = MT41J128MJT125_PHY_WR_DATA,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000208 .datadldiff0 = PHY_DLL_LOCK_DIFF,
209};
210
Tom Rini385bc752013-03-21 04:30:02 +0000211static const struct ddr_data ddr3_beagleblack_data = {
212 .datardsratio0 = MT41K256M16HA125E_RD_DQS,
213 .datawdsratio0 = MT41K256M16HA125E_WR_DQS,
214 .datafwsratio0 = MT41K256M16HA125E_PHY_FIFO_WE,
215 .datawrsratio0 = MT41K256M16HA125E_PHY_WR_DATA,
216 .datadldiff0 = PHY_DLL_LOCK_DIFF,
217};
218
Jeff Lance7c03a222013-01-14 05:32:20 +0000219static const struct ddr_data ddr3_evm_data = {
220 .datardsratio0 = MT41J512M8RH125_RD_DQS,
221 .datawdsratio0 = MT41J512M8RH125_WR_DQS,
222 .datafwsratio0 = MT41J512M8RH125_PHY_FIFO_WE,
223 .datawrsratio0 = MT41J512M8RH125_PHY_WR_DATA,
224 .datadldiff0 = PHY_DLL_LOCK_DIFF,
225};
226
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000227static const struct cmd_control ddr3_cmd_ctrl_data = {
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000228 .cmd0csratio = MT41J128MJT125_RATIO,
229 .cmd0dldiff = MT41J128MJT125_DLL_LOCK_DIFF,
230 .cmd0iclkout = MT41J128MJT125_INVERT_CLKOUT,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000231
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000232 .cmd1csratio = MT41J128MJT125_RATIO,
233 .cmd1dldiff = MT41J128MJT125_DLL_LOCK_DIFF,
234 .cmd1iclkout = MT41J128MJT125_INVERT_CLKOUT,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000235
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000236 .cmd2csratio = MT41J128MJT125_RATIO,
237 .cmd2dldiff = MT41J128MJT125_DLL_LOCK_DIFF,
238 .cmd2iclkout = MT41J128MJT125_INVERT_CLKOUT,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000239};
240
Tom Rini385bc752013-03-21 04:30:02 +0000241static const struct cmd_control ddr3_beagleblack_cmd_ctrl_data = {
242 .cmd0csratio = MT41K256M16HA125E_RATIO,
243 .cmd0dldiff = MT41K256M16HA125E_DLL_LOCK_DIFF,
244 .cmd0iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
245
246 .cmd1csratio = MT41K256M16HA125E_RATIO,
247 .cmd1dldiff = MT41K256M16HA125E_DLL_LOCK_DIFF,
248 .cmd1iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
249
250 .cmd2csratio = MT41K256M16HA125E_RATIO,
251 .cmd2dldiff = MT41K256M16HA125E_DLL_LOCK_DIFF,
252 .cmd2iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
253};
254
Jeff Lance7c03a222013-01-14 05:32:20 +0000255static const struct cmd_control ddr3_evm_cmd_ctrl_data = {
256 .cmd0csratio = MT41J512M8RH125_RATIO,
257 .cmd0dldiff = MT41J512M8RH125_DLL_LOCK_DIFF,
258 .cmd0iclkout = MT41J512M8RH125_INVERT_CLKOUT,
259
260 .cmd1csratio = MT41J512M8RH125_RATIO,
261 .cmd1dldiff = MT41J512M8RH125_DLL_LOCK_DIFF,
262 .cmd1iclkout = MT41J512M8RH125_INVERT_CLKOUT,
263
264 .cmd2csratio = MT41J512M8RH125_RATIO,
265 .cmd2dldiff = MT41J512M8RH125_DLL_LOCK_DIFF,
266 .cmd2iclkout = MT41J512M8RH125_INVERT_CLKOUT,
267};
268
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000269static struct emif_regs ddr3_emif_reg_data = {
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000270 .sdram_config = MT41J128MJT125_EMIF_SDCFG,
271 .ref_ctrl = MT41J128MJT125_EMIF_SDREF,
272 .sdram_tim1 = MT41J128MJT125_EMIF_TIM1,
273 .sdram_tim2 = MT41J128MJT125_EMIF_TIM2,
274 .sdram_tim3 = MT41J128MJT125_EMIF_TIM3,
275 .zq_config = MT41J128MJT125_ZQ_CFG,
Vaibhav Hiremathc30d57b2013-03-14 21:11:16 +0000276 .emif_ddr_phy_ctlr_1 = MT41J128MJT125_EMIF_READ_LATENCY |
277 PHY_EN_DYN_PWRDN,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000278};
Jeff Lance7c03a222013-01-14 05:32:20 +0000279
Tom Rini385bc752013-03-21 04:30:02 +0000280static struct emif_regs ddr3_beagleblack_emif_reg_data = {
281 .sdram_config = MT41K256M16HA125E_EMIF_SDCFG,
282 .ref_ctrl = MT41K256M16HA125E_EMIF_SDREF,
283 .sdram_tim1 = MT41K256M16HA125E_EMIF_TIM1,
284 .sdram_tim2 = MT41K256M16HA125E_EMIF_TIM2,
285 .sdram_tim3 = MT41K256M16HA125E_EMIF_TIM3,
286 .zq_config = MT41K256M16HA125E_ZQ_CFG,
287 .emif_ddr_phy_ctlr_1 = MT41K256M16HA125E_EMIF_READ_LATENCY,
288};
289
Jeff Lance7c03a222013-01-14 05:32:20 +0000290static struct emif_regs ddr3_evm_emif_reg_data = {
291 .sdram_config = MT41J512M8RH125_EMIF_SDCFG,
292 .ref_ctrl = MT41J512M8RH125_EMIF_SDREF,
293 .sdram_tim1 = MT41J512M8RH125_EMIF_TIM1,
294 .sdram_tim2 = MT41J512M8RH125_EMIF_TIM2,
295 .sdram_tim3 = MT41J512M8RH125_EMIF_TIM3,
296 .zq_config = MT41J512M8RH125_ZQ_CFG,
Vaibhav Hiremathc30d57b2013-03-14 21:11:16 +0000297 .emif_ddr_phy_ctlr_1 = MT41J512M8RH125_EMIF_READ_LATENCY |
298 PHY_EN_DYN_PWRDN,
Jeff Lance7c03a222013-01-14 05:32:20 +0000299};
Peter Korsgaardeb204db2013-05-13 08:36:30 +0000300
301#ifdef CONFIG_SPL_OS_BOOT
302int spl_start_uboot(void)
303{
304 /* break into full u-boot on 'c' */
305 return (serial_tstc() && serial_getc() == 'c');
306}
307#endif
308
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000309#endif
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000310
311/*
312 * early system init of muxing and clocks.
313 */
314void s_init(void)
315{
Tom Rini51df26c2013-05-31 12:31:59 -0400316 /*
317 * Save the boot parameters passed from romcode.
318 * We cannot delay the saving further than this,
319 * to prevent overwrites.
320 */
321#ifdef CONFIG_SPL_BUILD
322 save_omap_boot_params();
323#endif
324
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000325 /* WDT1 is already running when the bootloader gets control
326 * Disable it to avoid "random" resets
327 */
328 writel(0xAAAA, &wdtimer->wdtwspr);
329 while (readl(&wdtimer->wdtwwps) != 0x0)
330 ;
331 writel(0x5555, &wdtimer->wdtwspr);
332 while (readl(&wdtimer->wdtwwps) != 0x0)
333 ;
334
335#ifdef CONFIG_SPL_BUILD
336 /* Setup the PLLs and the clocks for the peripherals */
337 pll_init();
338
339 /* Enable RTC32K clock */
340 rtc32k_enable();
341
342 /* UART softreset */
343 u32 regVal;
344
Andrew Bradford65c51ff2012-10-25 08:21:30 -0400345#ifdef CONFIG_SERIAL1
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000346 enable_uart0_pin_mux();
Andrew Bradford65c51ff2012-10-25 08:21:30 -0400347#endif /* CONFIG_SERIAL1 */
348#ifdef CONFIG_SERIAL2
349 enable_uart1_pin_mux();
350#endif /* CONFIG_SERIAL2 */
351#ifdef CONFIG_SERIAL3
352 enable_uart2_pin_mux();
353#endif /* CONFIG_SERIAL3 */
354#ifdef CONFIG_SERIAL4
355 enable_uart3_pin_mux();
356#endif /* CONFIG_SERIAL4 */
357#ifdef CONFIG_SERIAL5
358 enable_uart4_pin_mux();
359#endif /* CONFIG_SERIAL5 */
360#ifdef CONFIG_SERIAL6
361 enable_uart5_pin_mux();
362#endif /* CONFIG_SERIAL6 */
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000363
364 regVal = readl(&uart_base->uartsyscfg);
365 regVal |= UART_RESET;
366 writel(regVal, &uart_base->uartsyscfg);
367 while ((readl(&uart_base->uartsyssts) &
368 UART_CLK_RUNNING_MASK) != UART_CLK_RUNNING_MASK)
369 ;
370
371 /* Disable smart idle */
372 regVal = readl(&uart_base->uartsyscfg);
373 regVal |= UART_SMART_IDLE_EN;
374 writel(regVal, &uart_base->uartsyscfg);
375
376 gd = &gdata;
377
378 preloader_console_init();
379
380 /* Initalize the board header */
381 enable_i2c0_pin_mux();
382 i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
383 if (read_eeprom() < 0)
384 puts("Could not get board ID.\n");
385
386 enable_board_pin_mux(&header);
387 if (board_is_evm_sk()) {
388 /*
389 * EVM SK 1.2A and later use gpio0_7 to enable DDR3.
390 * This is safe enough to do on older revs.
391 */
392 gpio_request(GPIO_DDR_VTT_EN, "ddr_vtt_en");
393 gpio_direction_output(GPIO_DDR_VTT_EN, 1);
394 }
395
Tom Rini385bc752013-03-21 04:30:02 +0000396 if (board_is_evm_sk())
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000397 config_ddr(303, MT41J128MJT125_IOCTRL_VALUE, &ddr3_data,
Matt Porter65991ec2013-03-15 10:07:03 +0000398 &ddr3_cmd_ctrl_data, &ddr3_emif_reg_data, 0);
Tom Rini385bc752013-03-21 04:30:02 +0000399 else if (board_is_bone_lt())
Tom Rini8939ec32013-04-10 15:10:54 +0200400 config_ddr(400, MT41K256M16HA125E_IOCTRL_VALUE,
Tom Rini385bc752013-03-21 04:30:02 +0000401 &ddr3_beagleblack_data,
402 &ddr3_beagleblack_cmd_ctrl_data,
403 &ddr3_beagleblack_emif_reg_data, 0);
Jeff Lance7c03a222013-01-14 05:32:20 +0000404 else if (board_is_evm_15_or_later())
405 config_ddr(303, MT41J512M8RH125_IOCTRL_VALUE, &ddr3_evm_data,
Matt Porter65991ec2013-03-15 10:07:03 +0000406 &ddr3_evm_cmd_ctrl_data, &ddr3_evm_emif_reg_data, 0);
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000407 else
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000408 config_ddr(266, MT47H128M16RT25E_IOCTRL_VALUE, &ddr2_data,
Matt Porter65991ec2013-03-15 10:07:03 +0000409 &ddr2_cmd_ctrl_data, &ddr2_emif_reg_data, 0);
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000410#endif
411}
412
413/*
414 * Basic board specific setup. Pinmux has been handled already.
415 */
416int board_init(void)
417{
418 i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
419 if (read_eeprom() < 0)
420 puts("Could not get board ID.\n");
421
422 gd->bd->bi_boot_params = PHYS_DRAM_1 + 0x100;
423
Ilya Yanok3d9725e2012-11-06 13:06:31 +0000424 gpmc_init();
425
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000426 return 0;
427}
428
Tom Rini40271852012-10-24 07:28:17 +0000429#ifdef CONFIG_BOARD_LATE_INIT
430int board_late_init(void)
431{
432#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
433 char safe_string[HDR_NAME_LEN + 1];
434
435 /* Now set variables based on the header. */
436 strncpy(safe_string, (char *)header.name, sizeof(header.name));
437 safe_string[sizeof(header.name)] = 0;
438 setenv("board_name", safe_string);
439
440 strncpy(safe_string, (char *)header.version, sizeof(header.version));
441 safe_string[sizeof(header.version)] = 0;
442 setenv("board_rev", safe_string);
443#endif
444
445 return 0;
446}
447#endif
448
Ilya Yanok0760a0d2013-02-05 11:36:26 +0000449#if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) || \
450 (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD))
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000451static void cpsw_control(int enabled)
452{
453 /* VTP can be added here */
454
455 return;
456}
457
458static struct cpsw_slave_data cpsw_slaves[] = {
459 {
460 .slave_reg_ofs = 0x208,
461 .sliver_reg_ofs = 0xd80,
462 .phy_id = 0,
463 },
464 {
465 .slave_reg_ofs = 0x308,
466 .sliver_reg_ofs = 0xdc0,
467 .phy_id = 1,
468 },
469};
470
471static struct cpsw_platform_data cpsw_data = {
Matt Portere24646f2013-03-15 10:07:02 +0000472 .mdio_base = CPSW_MDIO_BASE,
473 .cpsw_base = CPSW_BASE,
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000474 .mdio_div = 0xff,
475 .channels = 8,
476 .cpdma_reg_ofs = 0x800,
477 .slaves = 1,
478 .slave_data = cpsw_slaves,
479 .ale_reg_ofs = 0xd00,
480 .ale_entries = 1024,
481 .host_port_reg_ofs = 0x108,
482 .hw_stats_reg_ofs = 0x900,
483 .mac_control = (1 << 5),
484 .control = cpsw_control,
485 .host_port_num = 0,
486 .version = CPSW_CTRL_VERSION_2,
487};
Ilya Yanok44a2c072012-11-06 13:48:24 +0000488#endif
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000489
Ilya Yanok44a2c072012-11-06 13:48:24 +0000490#if defined(CONFIG_DRIVER_TI_CPSW) || \
491 (defined(CONFIG_USB_ETHER) && defined(CONFIG_MUSB_GADGET))
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000492int board_eth_init(bd_t *bis)
493{
Ilya Yanok44a2c072012-11-06 13:48:24 +0000494 int rv, n = 0;
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000495 uint8_t mac_addr[6];
496 uint32_t mac_hi, mac_lo;
497
Ilya Yanok0760a0d2013-02-05 11:36:26 +0000498 /* try reading mac address from efuse */
499 mac_lo = readl(&cdev->macid0l);
500 mac_hi = readl(&cdev->macid0h);
501 mac_addr[0] = mac_hi & 0xFF;
502 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
503 mac_addr[2] = (mac_hi & 0xFF0000) >> 16;
504 mac_addr[3] = (mac_hi & 0xFF000000) >> 24;
505 mac_addr[4] = mac_lo & 0xFF;
506 mac_addr[5] = (mac_lo & 0xFF00) >> 8;
507
508#if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) || \
509 (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD))
510 if (!getenv("ethaddr")) {
511 printf("<ethaddr> not set. Validating first E-fuse MAC\n");
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000512
513 if (is_valid_ether_addr(mac_addr))
514 eth_setenv_enetaddr("ethaddr", mac_addr);
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000515 }
516
Joel A Fernandesf7488542013-05-07 05:52:55 +0000517#ifdef CONFIG_DRIVER_TI_CPSW
Matthias Fuchs63ffc5a2012-11-02 03:35:59 +0000518 if (board_is_bone() || board_is_bone_lt() || board_is_idk()) {
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000519 writel(MII_MODE_ENABLE, &cdev->miisel);
520 cpsw_slaves[0].phy_if = cpsw_slaves[1].phy_if =
521 PHY_INTERFACE_MODE_MII;
522 } else {
523 writel(RGMII_MODE_ENABLE, &cdev->miisel);
524 cpsw_slaves[0].phy_if = cpsw_slaves[1].phy_if =
525 PHY_INTERFACE_MODE_RGMII;
526 }
527
Ilya Yanok44a2c072012-11-06 13:48:24 +0000528 rv = cpsw_register(&cpsw_data);
529 if (rv < 0)
530 printf("Error %d registering CPSW switch\n", rv);
531 else
532 n += rv;
Joel A Fernandesf7488542013-05-07 05:52:55 +0000533#endif
Tom Rini183943d2013-02-12 14:59:23 -0500534
535 /*
536 *
537 * CPSW RGMII Internal Delay Mode is not supported in all PVT
538 * operating points. So we must set the TX clock delay feature
539 * in the AR8051 PHY. Since we only support a single ethernet
540 * device in U-Boot, we only do this for the first instance.
541 */
542#define AR8051_PHY_DEBUG_ADDR_REG 0x1d
543#define AR8051_PHY_DEBUG_DATA_REG 0x1e
544#define AR8051_DEBUG_RGMII_CLK_DLY_REG 0x5
545#define AR8051_RGMII_TX_CLK_DLY 0x100
546
547 if (board_is_evm_sk() || board_is_gp_evm()) {
548 const char *devname;
549 devname = miiphy_get_current_dev();
550
551 miiphy_write(devname, 0x0, AR8051_PHY_DEBUG_ADDR_REG,
552 AR8051_DEBUG_RGMII_CLK_DLY_REG);
553 miiphy_write(devname, 0x0, AR8051_PHY_DEBUG_DATA_REG,
554 AR8051_RGMII_TX_CLK_DLY);
555 }
Ilya Yanok44a2c072012-11-06 13:48:24 +0000556#endif
Ilya Yanok0760a0d2013-02-05 11:36:26 +0000557#if defined(CONFIG_USB_ETHER) && \
558 (!defined(CONFIG_SPL_BUILD) || defined(CONFIG_SPL_USBETH_SUPPORT))
559 if (is_valid_ether_addr(mac_addr))
560 eth_setenv_enetaddr("usbnet_devaddr", mac_addr);
561
Ilya Yanok44a2c072012-11-06 13:48:24 +0000562 rv = usb_eth_initialize(bis);
563 if (rv < 0)
564 printf("Error %d registering USB_ETHER\n", rv);
565 else
566 n += rv;
567#endif
568 return n;
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000569}
570#endif