blob: 15e249d605ecfdf7635a8903d76e3b206ac6407f [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 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02008 * SPDX-License-Identifier: GPL-2.0+
Peter Korsgaard85ec2db2012-10-18 01:21:09 +00009 */
10
11#include <common.h>
12#include <errno.h>
13#include <spl.h>
14#include <asm/arch/cpu.h>
15#include <asm/arch/hardware.h>
16#include <asm/arch/omap.h>
17#include <asm/arch/ddr_defs.h>
18#include <asm/arch/clock.h>
19#include <asm/arch/gpio.h>
20#include <asm/arch/mmc_host_def.h>
21#include <asm/arch/sys_proto.h>
22#include <asm/io.h>
23#include <asm/emif.h>
24#include <asm/gpio.h>
25#include <i2c.h>
26#include <miiphy.h>
27#include <cpsw.h>
28#include "board.h"
29
30DECLARE_GLOBAL_DATA_PTR;
31
32static struct wd_timer *wdtimer = (struct wd_timer *)WDT_BASE;
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000033
34/* MII mode defines */
35#define MII_MODE_ENABLE 0x0
Yegor Yefremove44314a2012-11-26 03:30:42 +000036#define RGMII_MODE_ENABLE 0x3A
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000037
38/* GPIO that controls power to DDR on EVM-SK */
39#define GPIO_DDR_VTT_EN 7
40
41static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
42
43static struct am335x_baseboard_id __attribute__((section (".data"))) header;
44
45static inline int board_is_bone(void)
46{
47 return !strncmp(header.name, "A335BONE", HDR_NAME_LEN);
48}
49
50static inline int board_is_bone_lt(void)
51{
52 return !strncmp(header.name, "A335BNLT", HDR_NAME_LEN);
53}
54
55static inline int board_is_evm_sk(void)
56{
57 return !strncmp("A335X_SK", header.name, HDR_NAME_LEN);
58}
59
Matthias Fuchs63ffc5a2012-11-02 03:35:59 +000060static inline int board_is_idk(void)
61{
62 return !strncmp(header.config, "SKU#02", 6);
63}
64
Tom Rini35eafab2013-02-26 15:43:22 -050065static int __maybe_unused board_is_gp_evm(void)
Tom Rini183943d2013-02-12 14:59:23 -050066{
67 return !strncmp("A33515BB", header.name, 8);
68}
69
Jeff Lance7c03a222013-01-14 05:32:20 +000070int board_is_evm_15_or_later(void)
71{
72 return (!strncmp("A33515BB", header.name, 8) &&
73 strncmp("1.5", header.version, 3) <= 0);
74}
75
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000076/*
77 * Read header information from EEPROM into global structure.
78 */
79static int read_eeprom(void)
80{
81 /* Check if baseboard eeprom is available */
82 if (i2c_probe(CONFIG_SYS_I2C_EEPROM_ADDR)) {
83 puts("Could not probe the EEPROM; something fundamentally "
84 "wrong on the I2C bus.\n");
85 return -ENODEV;
86 }
87
88 /* read the eeprom using i2c */
89 if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0, 2, (uchar *)&header,
90 sizeof(header))) {
91 puts("Could not read the EEPROM; something fundamentally"
92 " wrong on the I2C bus.\n");
93 return -EIO;
94 }
95
96 if (header.magic != 0xEE3355AA) {
97 /*
98 * read the eeprom using i2c again,
99 * but use only a 1 byte address
100 */
101 if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0, 1,
102 (uchar *)&header, sizeof(header))) {
103 puts("Could not read the EEPROM; something "
104 "fundamentally wrong on the I2C bus.\n");
105 return -EIO;
106 }
107
108 if (header.magic != 0xEE3355AA) {
109 printf("Incorrect magic number (0x%x) in EEPROM\n",
110 header.magic);
111 return -EINVAL;
112 }
113 }
114
115 return 0;
116}
117
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000118#ifdef CONFIG_SPL_BUILD
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000119static const struct ddr_data ddr2_data = {
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000120 .datardsratio0 = ((MT47H128M16RT25E_RD_DQS<<30) |
121 (MT47H128M16RT25E_RD_DQS<<20) |
122 (MT47H128M16RT25E_RD_DQS<<10) |
123 (MT47H128M16RT25E_RD_DQS<<0)),
124 .datawdsratio0 = ((MT47H128M16RT25E_WR_DQS<<30) |
125 (MT47H128M16RT25E_WR_DQS<<20) |
126 (MT47H128M16RT25E_WR_DQS<<10) |
127 (MT47H128M16RT25E_WR_DQS<<0)),
128 .datawiratio0 = ((MT47H128M16RT25E_PHY_WRLVL<<30) |
129 (MT47H128M16RT25E_PHY_WRLVL<<20) |
130 (MT47H128M16RT25E_PHY_WRLVL<<10) |
131 (MT47H128M16RT25E_PHY_WRLVL<<0)),
132 .datagiratio0 = ((MT47H128M16RT25E_PHY_GATELVL<<30) |
133 (MT47H128M16RT25E_PHY_GATELVL<<20) |
134 (MT47H128M16RT25E_PHY_GATELVL<<10) |
135 (MT47H128M16RT25E_PHY_GATELVL<<0)),
136 .datafwsratio0 = ((MT47H128M16RT25E_PHY_FIFO_WE<<30) |
137 (MT47H128M16RT25E_PHY_FIFO_WE<<20) |
138 (MT47H128M16RT25E_PHY_FIFO_WE<<10) |
139 (MT47H128M16RT25E_PHY_FIFO_WE<<0)),
140 .datawrsratio0 = ((MT47H128M16RT25E_PHY_WR_DATA<<30) |
141 (MT47H128M16RT25E_PHY_WR_DATA<<20) |
142 (MT47H128M16RT25E_PHY_WR_DATA<<10) |
143 (MT47H128M16RT25E_PHY_WR_DATA<<0)),
144 .datauserank0delay = MT47H128M16RT25E_PHY_RANK0_DELAY,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000145 .datadldiff0 = PHY_DLL_LOCK_DIFF,
146};
147
148static const struct cmd_control ddr2_cmd_ctrl_data = {
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000149 .cmd0csratio = MT47H128M16RT25E_RATIO,
150 .cmd0dldiff = MT47H128M16RT25E_DLL_LOCK_DIFF,
151 .cmd0iclkout = MT47H128M16RT25E_INVERT_CLKOUT,
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000152
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000153 .cmd1csratio = MT47H128M16RT25E_RATIO,
154 .cmd1dldiff = MT47H128M16RT25E_DLL_LOCK_DIFF,
155 .cmd1iclkout = MT47H128M16RT25E_INVERT_CLKOUT,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000156
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000157 .cmd2csratio = MT47H128M16RT25E_RATIO,
158 .cmd2dldiff = MT47H128M16RT25E_DLL_LOCK_DIFF,
159 .cmd2iclkout = MT47H128M16RT25E_INVERT_CLKOUT,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000160};
161
162static const struct emif_regs ddr2_emif_reg_data = {
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000163 .sdram_config = MT47H128M16RT25E_EMIF_SDCFG,
164 .ref_ctrl = MT47H128M16RT25E_EMIF_SDREF,
165 .sdram_tim1 = MT47H128M16RT25E_EMIF_TIM1,
166 .sdram_tim2 = MT47H128M16RT25E_EMIF_TIM2,
167 .sdram_tim3 = MT47H128M16RT25E_EMIF_TIM3,
168 .emif_ddr_phy_ctlr_1 = MT47H128M16RT25E_EMIF_READ_LATENCY,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000169};
170
171static const struct ddr_data ddr3_data = {
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000172 .datardsratio0 = MT41J128MJT125_RD_DQS,
173 .datawdsratio0 = MT41J128MJT125_WR_DQS,
174 .datafwsratio0 = MT41J128MJT125_PHY_FIFO_WE,
175 .datawrsratio0 = MT41J128MJT125_PHY_WR_DATA,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000176 .datadldiff0 = PHY_DLL_LOCK_DIFF,
177};
178
Tom Rini385bc752013-03-21 04:30:02 +0000179static const struct ddr_data ddr3_beagleblack_data = {
180 .datardsratio0 = MT41K256M16HA125E_RD_DQS,
181 .datawdsratio0 = MT41K256M16HA125E_WR_DQS,
182 .datafwsratio0 = MT41K256M16HA125E_PHY_FIFO_WE,
183 .datawrsratio0 = MT41K256M16HA125E_PHY_WR_DATA,
184 .datadldiff0 = PHY_DLL_LOCK_DIFF,
185};
186
Jeff Lance7c03a222013-01-14 05:32:20 +0000187static const struct ddr_data ddr3_evm_data = {
188 .datardsratio0 = MT41J512M8RH125_RD_DQS,
189 .datawdsratio0 = MT41J512M8RH125_WR_DQS,
190 .datafwsratio0 = MT41J512M8RH125_PHY_FIFO_WE,
191 .datawrsratio0 = MT41J512M8RH125_PHY_WR_DATA,
192 .datadldiff0 = PHY_DLL_LOCK_DIFF,
193};
194
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000195static const struct cmd_control ddr3_cmd_ctrl_data = {
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000196 .cmd0csratio = MT41J128MJT125_RATIO,
197 .cmd0dldiff = MT41J128MJT125_DLL_LOCK_DIFF,
198 .cmd0iclkout = MT41J128MJT125_INVERT_CLKOUT,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000199
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000200 .cmd1csratio = MT41J128MJT125_RATIO,
201 .cmd1dldiff = MT41J128MJT125_DLL_LOCK_DIFF,
202 .cmd1iclkout = MT41J128MJT125_INVERT_CLKOUT,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000203
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000204 .cmd2csratio = MT41J128MJT125_RATIO,
205 .cmd2dldiff = MT41J128MJT125_DLL_LOCK_DIFF,
206 .cmd2iclkout = MT41J128MJT125_INVERT_CLKOUT,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000207};
208
Tom Rini385bc752013-03-21 04:30:02 +0000209static const struct cmd_control ddr3_beagleblack_cmd_ctrl_data = {
210 .cmd0csratio = MT41K256M16HA125E_RATIO,
211 .cmd0dldiff = MT41K256M16HA125E_DLL_LOCK_DIFF,
212 .cmd0iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
213
214 .cmd1csratio = MT41K256M16HA125E_RATIO,
215 .cmd1dldiff = MT41K256M16HA125E_DLL_LOCK_DIFF,
216 .cmd1iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
217
218 .cmd2csratio = MT41K256M16HA125E_RATIO,
219 .cmd2dldiff = MT41K256M16HA125E_DLL_LOCK_DIFF,
220 .cmd2iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
221};
222
Jeff Lance7c03a222013-01-14 05:32:20 +0000223static const struct cmd_control ddr3_evm_cmd_ctrl_data = {
224 .cmd0csratio = MT41J512M8RH125_RATIO,
225 .cmd0dldiff = MT41J512M8RH125_DLL_LOCK_DIFF,
226 .cmd0iclkout = MT41J512M8RH125_INVERT_CLKOUT,
227
228 .cmd1csratio = MT41J512M8RH125_RATIO,
229 .cmd1dldiff = MT41J512M8RH125_DLL_LOCK_DIFF,
230 .cmd1iclkout = MT41J512M8RH125_INVERT_CLKOUT,
231
232 .cmd2csratio = MT41J512M8RH125_RATIO,
233 .cmd2dldiff = MT41J512M8RH125_DLL_LOCK_DIFF,
234 .cmd2iclkout = MT41J512M8RH125_INVERT_CLKOUT,
235};
236
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000237static struct emif_regs ddr3_emif_reg_data = {
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000238 .sdram_config = MT41J128MJT125_EMIF_SDCFG,
239 .ref_ctrl = MT41J128MJT125_EMIF_SDREF,
240 .sdram_tim1 = MT41J128MJT125_EMIF_TIM1,
241 .sdram_tim2 = MT41J128MJT125_EMIF_TIM2,
242 .sdram_tim3 = MT41J128MJT125_EMIF_TIM3,
243 .zq_config = MT41J128MJT125_ZQ_CFG,
Vaibhav Hiremathc30d57b2013-03-14 21:11:16 +0000244 .emif_ddr_phy_ctlr_1 = MT41J128MJT125_EMIF_READ_LATENCY |
245 PHY_EN_DYN_PWRDN,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000246};
Jeff Lance7c03a222013-01-14 05:32:20 +0000247
Tom Rini385bc752013-03-21 04:30:02 +0000248static struct emif_regs ddr3_beagleblack_emif_reg_data = {
249 .sdram_config = MT41K256M16HA125E_EMIF_SDCFG,
250 .ref_ctrl = MT41K256M16HA125E_EMIF_SDREF,
251 .sdram_tim1 = MT41K256M16HA125E_EMIF_TIM1,
252 .sdram_tim2 = MT41K256M16HA125E_EMIF_TIM2,
253 .sdram_tim3 = MT41K256M16HA125E_EMIF_TIM3,
254 .zq_config = MT41K256M16HA125E_ZQ_CFG,
255 .emif_ddr_phy_ctlr_1 = MT41K256M16HA125E_EMIF_READ_LATENCY,
256};
257
Jeff Lance7c03a222013-01-14 05:32:20 +0000258static struct emif_regs ddr3_evm_emif_reg_data = {
259 .sdram_config = MT41J512M8RH125_EMIF_SDCFG,
260 .ref_ctrl = MT41J512M8RH125_EMIF_SDREF,
261 .sdram_tim1 = MT41J512M8RH125_EMIF_TIM1,
262 .sdram_tim2 = MT41J512M8RH125_EMIF_TIM2,
263 .sdram_tim3 = MT41J512M8RH125_EMIF_TIM3,
264 .zq_config = MT41J512M8RH125_ZQ_CFG,
Vaibhav Hiremathc30d57b2013-03-14 21:11:16 +0000265 .emif_ddr_phy_ctlr_1 = MT41J512M8RH125_EMIF_READ_LATENCY |
266 PHY_EN_DYN_PWRDN,
Jeff Lance7c03a222013-01-14 05:32:20 +0000267};
Peter Korsgaardeb204db2013-05-13 08:36:30 +0000268
269#ifdef CONFIG_SPL_OS_BOOT
270int spl_start_uboot(void)
271{
272 /* break into full u-boot on 'c' */
273 return (serial_tstc() && serial_getc() == 'c');
274}
275#endif
276
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000277#endif
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000278
279/*
280 * early system init of muxing and clocks.
281 */
282void s_init(void)
283{
Tom Rini51df26c2013-05-31 12:31:59 -0400284 /*
285 * Save the boot parameters passed from romcode.
286 * We cannot delay the saving further than this,
287 * to prevent overwrites.
288 */
289#ifdef CONFIG_SPL_BUILD
290 save_omap_boot_params();
291#endif
292
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000293 /* WDT1 is already running when the bootloader gets control
294 * Disable it to avoid "random" resets
295 */
296 writel(0xAAAA, &wdtimer->wdtwspr);
297 while (readl(&wdtimer->wdtwwps) != 0x0)
298 ;
299 writel(0x5555, &wdtimer->wdtwspr);
300 while (readl(&wdtimer->wdtwwps) != 0x0)
301 ;
302
303#ifdef CONFIG_SPL_BUILD
304 /* Setup the PLLs and the clocks for the peripherals */
305 pll_init();
306
307 /* Enable RTC32K clock */
308 rtc32k_enable();
309
Andrew Bradford65c51ff2012-10-25 08:21:30 -0400310#ifdef CONFIG_SERIAL1
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000311 enable_uart0_pin_mux();
Andrew Bradford65c51ff2012-10-25 08:21:30 -0400312#endif /* CONFIG_SERIAL1 */
313#ifdef CONFIG_SERIAL2
314 enable_uart1_pin_mux();
315#endif /* CONFIG_SERIAL2 */
316#ifdef CONFIG_SERIAL3
317 enable_uart2_pin_mux();
318#endif /* CONFIG_SERIAL3 */
319#ifdef CONFIG_SERIAL4
320 enable_uart3_pin_mux();
321#endif /* CONFIG_SERIAL4 */
322#ifdef CONFIG_SERIAL5
323 enable_uart4_pin_mux();
324#endif /* CONFIG_SERIAL5 */
325#ifdef CONFIG_SERIAL6
326 enable_uart5_pin_mux();
327#endif /* CONFIG_SERIAL6 */
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000328
Heiko Schocher57004c52013-06-04 11:00:57 +0200329 uart_soft_reset();
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000330
331 gd = &gdata;
332
333 preloader_console_init();
334
335 /* Initalize the board header */
336 enable_i2c0_pin_mux();
337 i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
338 if (read_eeprom() < 0)
339 puts("Could not get board ID.\n");
340
341 enable_board_pin_mux(&header);
342 if (board_is_evm_sk()) {
343 /*
344 * EVM SK 1.2A and later use gpio0_7 to enable DDR3.
345 * This is safe enough to do on older revs.
346 */
347 gpio_request(GPIO_DDR_VTT_EN, "ddr_vtt_en");
348 gpio_direction_output(GPIO_DDR_VTT_EN, 1);
349 }
350
Tom Rini385bc752013-03-21 04:30:02 +0000351 if (board_is_evm_sk())
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000352 config_ddr(303, MT41J128MJT125_IOCTRL_VALUE, &ddr3_data,
Matt Porter65991ec2013-03-15 10:07:03 +0000353 &ddr3_cmd_ctrl_data, &ddr3_emif_reg_data, 0);
Tom Rini385bc752013-03-21 04:30:02 +0000354 else if (board_is_bone_lt())
Tom Rini8939ec32013-04-10 15:10:54 +0200355 config_ddr(400, MT41K256M16HA125E_IOCTRL_VALUE,
Tom Rini385bc752013-03-21 04:30:02 +0000356 &ddr3_beagleblack_data,
357 &ddr3_beagleblack_cmd_ctrl_data,
358 &ddr3_beagleblack_emif_reg_data, 0);
Jeff Lance7c03a222013-01-14 05:32:20 +0000359 else if (board_is_evm_15_or_later())
360 config_ddr(303, MT41J512M8RH125_IOCTRL_VALUE, &ddr3_evm_data,
Matt Porter65991ec2013-03-15 10:07:03 +0000361 &ddr3_evm_cmd_ctrl_data, &ddr3_evm_emif_reg_data, 0);
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000362 else
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000363 config_ddr(266, MT47H128M16RT25E_IOCTRL_VALUE, &ddr2_data,
Matt Porter65991ec2013-03-15 10:07:03 +0000364 &ddr2_cmd_ctrl_data, &ddr2_emif_reg_data, 0);
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000365#endif
366}
367
368/*
369 * Basic board specific setup. Pinmux has been handled already.
370 */
371int board_init(void)
372{
373 i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
374 if (read_eeprom() < 0)
375 puts("Could not get board ID.\n");
376
377 gd->bd->bi_boot_params = PHYS_DRAM_1 + 0x100;
378
Ilya Yanok3d9725e2012-11-06 13:06:31 +0000379 gpmc_init();
380
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000381 return 0;
382}
383
Tom Rini40271852012-10-24 07:28:17 +0000384#ifdef CONFIG_BOARD_LATE_INIT
385int board_late_init(void)
386{
387#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
388 char safe_string[HDR_NAME_LEN + 1];
389
390 /* Now set variables based on the header. */
391 strncpy(safe_string, (char *)header.name, sizeof(header.name));
392 safe_string[sizeof(header.name)] = 0;
393 setenv("board_name", safe_string);
394
395 strncpy(safe_string, (char *)header.version, sizeof(header.version));
396 safe_string[sizeof(header.version)] = 0;
397 setenv("board_rev", safe_string);
398#endif
399
400 return 0;
401}
402#endif
403
Ilya Yanok0760a0d2013-02-05 11:36:26 +0000404#if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) || \
405 (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD))
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000406static void cpsw_control(int enabled)
407{
408 /* VTP can be added here */
409
410 return;
411}
412
413static struct cpsw_slave_data cpsw_slaves[] = {
414 {
415 .slave_reg_ofs = 0x208,
416 .sliver_reg_ofs = 0xd80,
417 .phy_id = 0,
418 },
419 {
420 .slave_reg_ofs = 0x308,
421 .sliver_reg_ofs = 0xdc0,
422 .phy_id = 1,
423 },
424};
425
426static struct cpsw_platform_data cpsw_data = {
Matt Portere24646f2013-03-15 10:07:02 +0000427 .mdio_base = CPSW_MDIO_BASE,
428 .cpsw_base = CPSW_BASE,
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000429 .mdio_div = 0xff,
430 .channels = 8,
431 .cpdma_reg_ofs = 0x800,
432 .slaves = 1,
433 .slave_data = cpsw_slaves,
434 .ale_reg_ofs = 0xd00,
435 .ale_entries = 1024,
436 .host_port_reg_ofs = 0x108,
437 .hw_stats_reg_ofs = 0x900,
Mugunthan V Nff559872013-07-08 16:04:37 +0530438 .bd_ram_ofs = 0x2000,
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000439 .mac_control = (1 << 5),
440 .control = cpsw_control,
441 .host_port_num = 0,
442 .version = CPSW_CTRL_VERSION_2,
443};
Ilya Yanok44a2c072012-11-06 13:48:24 +0000444#endif
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000445
Ilya Yanok44a2c072012-11-06 13:48:24 +0000446#if defined(CONFIG_DRIVER_TI_CPSW) || \
447 (defined(CONFIG_USB_ETHER) && defined(CONFIG_MUSB_GADGET))
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000448int board_eth_init(bd_t *bis)
449{
Ilya Yanok44a2c072012-11-06 13:48:24 +0000450 int rv, n = 0;
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000451 uint8_t mac_addr[6];
452 uint32_t mac_hi, mac_lo;
453
Ilya Yanok0760a0d2013-02-05 11:36:26 +0000454 /* try reading mac address from efuse */
455 mac_lo = readl(&cdev->macid0l);
456 mac_hi = readl(&cdev->macid0h);
457 mac_addr[0] = mac_hi & 0xFF;
458 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
459 mac_addr[2] = (mac_hi & 0xFF0000) >> 16;
460 mac_addr[3] = (mac_hi & 0xFF000000) >> 24;
461 mac_addr[4] = mac_lo & 0xFF;
462 mac_addr[5] = (mac_lo & 0xFF00) >> 8;
463
464#if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) || \
465 (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD))
466 if (!getenv("ethaddr")) {
467 printf("<ethaddr> not set. Validating first E-fuse MAC\n");
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000468
469 if (is_valid_ether_addr(mac_addr))
470 eth_setenv_enetaddr("ethaddr", mac_addr);
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000471 }
472
Joel A Fernandesf7488542013-05-07 05:52:55 +0000473#ifdef CONFIG_DRIVER_TI_CPSW
Matthias Fuchs63ffc5a2012-11-02 03:35:59 +0000474 if (board_is_bone() || board_is_bone_lt() || board_is_idk()) {
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000475 writel(MII_MODE_ENABLE, &cdev->miisel);
476 cpsw_slaves[0].phy_if = cpsw_slaves[1].phy_if =
477 PHY_INTERFACE_MODE_MII;
478 } else {
479 writel(RGMII_MODE_ENABLE, &cdev->miisel);
480 cpsw_slaves[0].phy_if = cpsw_slaves[1].phy_if =
481 PHY_INTERFACE_MODE_RGMII;
482 }
483
Ilya Yanok44a2c072012-11-06 13:48:24 +0000484 rv = cpsw_register(&cpsw_data);
485 if (rv < 0)
486 printf("Error %d registering CPSW switch\n", rv);
487 else
488 n += rv;
Joel A Fernandesf7488542013-05-07 05:52:55 +0000489#endif
Tom Rini183943d2013-02-12 14:59:23 -0500490
491 /*
492 *
493 * CPSW RGMII Internal Delay Mode is not supported in all PVT
494 * operating points. So we must set the TX clock delay feature
495 * in the AR8051 PHY. Since we only support a single ethernet
496 * device in U-Boot, we only do this for the first instance.
497 */
498#define AR8051_PHY_DEBUG_ADDR_REG 0x1d
499#define AR8051_PHY_DEBUG_DATA_REG 0x1e
500#define AR8051_DEBUG_RGMII_CLK_DLY_REG 0x5
501#define AR8051_RGMII_TX_CLK_DLY 0x100
502
503 if (board_is_evm_sk() || board_is_gp_evm()) {
504 const char *devname;
505 devname = miiphy_get_current_dev();
506
507 miiphy_write(devname, 0x0, AR8051_PHY_DEBUG_ADDR_REG,
508 AR8051_DEBUG_RGMII_CLK_DLY_REG);
509 miiphy_write(devname, 0x0, AR8051_PHY_DEBUG_DATA_REG,
510 AR8051_RGMII_TX_CLK_DLY);
511 }
Ilya Yanok44a2c072012-11-06 13:48:24 +0000512#endif
Ilya Yanok0760a0d2013-02-05 11:36:26 +0000513#if defined(CONFIG_USB_ETHER) && \
514 (!defined(CONFIG_SPL_BUILD) || defined(CONFIG_SPL_USBETH_SUPPORT))
515 if (is_valid_ether_addr(mac_addr))
516 eth_setenv_enetaddr("usbnet_devaddr", mac_addr);
517
Ilya Yanok44a2c072012-11-06 13:48:24 +0000518 rv = usb_eth_initialize(bis);
519 if (rv < 0)
520 printf("Error %d registering USB_ETHER\n", rv);
521 else
522 n += rv;
523#endif
524 return n;
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000525}
526#endif