blob: cc0442612ffe237fbde2255c330a31d80205ba37 [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>
Steve Kipiszbe9b6f82013-07-18 15:13:03 -040022#include <asm/arch/mem.h>
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000023#include <asm/io.h>
24#include <asm/emif.h>
25#include <asm/gpio.h>
26#include <i2c.h>
27#include <miiphy.h>
28#include <cpsw.h>
29#include "board.h"
30
31DECLARE_GLOBAL_DATA_PTR;
32
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000033/* GPIO that controls power to DDR on EVM-SK */
34#define GPIO_DDR_VTT_EN 7
35
36static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
37
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000038/*
39 * Read header information from EEPROM into global structure.
40 */
Tom Rini4021fd92013-07-18 15:13:01 -040041static int read_eeprom(struct am335x_baseboard_id *header)
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000042{
43 /* Check if baseboard eeprom is available */
44 if (i2c_probe(CONFIG_SYS_I2C_EEPROM_ADDR)) {
45 puts("Could not probe the EEPROM; something fundamentally "
46 "wrong on the I2C bus.\n");
47 return -ENODEV;
48 }
49
50 /* read the eeprom using i2c */
Tom Rini4021fd92013-07-18 15:13:01 -040051 if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0, 2, (uchar *)header,
52 sizeof(struct am335x_baseboard_id))) {
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000053 puts("Could not read the EEPROM; something fundamentally"
54 " wrong on the I2C bus.\n");
55 return -EIO;
56 }
57
Tom Rini4021fd92013-07-18 15:13:01 -040058 if (header->magic != 0xEE3355AA) {
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000059 /*
60 * read the eeprom using i2c again,
61 * but use only a 1 byte address
62 */
Tom Rini4021fd92013-07-18 15:13:01 -040063 if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0, 1, (uchar *)header,
64 sizeof(struct am335x_baseboard_id))) {
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000065 puts("Could not read the EEPROM; something "
66 "fundamentally wrong on the I2C bus.\n");
67 return -EIO;
68 }
69
Tom Rini4021fd92013-07-18 15:13:01 -040070 if (header->magic != 0xEE3355AA) {
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000071 printf("Incorrect magic number (0x%x) in EEPROM\n",
Tom Rini4021fd92013-07-18 15:13:01 -040072 header->magic);
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000073 return -EINVAL;
74 }
75 }
76
77 return 0;
78}
79
Steve Kipiszc1399b42013-07-18 15:13:04 -040080#if defined(CONFIG_SPL_BUILD) || defined(CONFIG_NOR_BOOT)
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +000081static const struct ddr_data ddr2_data = {
Peter Korsgaard3adb8272012-10-18 01:21:13 +000082 .datardsratio0 = ((MT47H128M16RT25E_RD_DQS<<30) |
83 (MT47H128M16RT25E_RD_DQS<<20) |
84 (MT47H128M16RT25E_RD_DQS<<10) |
85 (MT47H128M16RT25E_RD_DQS<<0)),
86 .datawdsratio0 = ((MT47H128M16RT25E_WR_DQS<<30) |
87 (MT47H128M16RT25E_WR_DQS<<20) |
88 (MT47H128M16RT25E_WR_DQS<<10) |
89 (MT47H128M16RT25E_WR_DQS<<0)),
90 .datawiratio0 = ((MT47H128M16RT25E_PHY_WRLVL<<30) |
91 (MT47H128M16RT25E_PHY_WRLVL<<20) |
92 (MT47H128M16RT25E_PHY_WRLVL<<10) |
93 (MT47H128M16RT25E_PHY_WRLVL<<0)),
94 .datagiratio0 = ((MT47H128M16RT25E_PHY_GATELVL<<30) |
95 (MT47H128M16RT25E_PHY_GATELVL<<20) |
96 (MT47H128M16RT25E_PHY_GATELVL<<10) |
97 (MT47H128M16RT25E_PHY_GATELVL<<0)),
98 .datafwsratio0 = ((MT47H128M16RT25E_PHY_FIFO_WE<<30) |
99 (MT47H128M16RT25E_PHY_FIFO_WE<<20) |
100 (MT47H128M16RT25E_PHY_FIFO_WE<<10) |
101 (MT47H128M16RT25E_PHY_FIFO_WE<<0)),
102 .datawrsratio0 = ((MT47H128M16RT25E_PHY_WR_DATA<<30) |
103 (MT47H128M16RT25E_PHY_WR_DATA<<20) |
104 (MT47H128M16RT25E_PHY_WR_DATA<<10) |
105 (MT47H128M16RT25E_PHY_WR_DATA<<0)),
106 .datauserank0delay = MT47H128M16RT25E_PHY_RANK0_DELAY,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000107 .datadldiff0 = PHY_DLL_LOCK_DIFF,
108};
109
110static const struct cmd_control ddr2_cmd_ctrl_data = {
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000111 .cmd0csratio = MT47H128M16RT25E_RATIO,
112 .cmd0dldiff = MT47H128M16RT25E_DLL_LOCK_DIFF,
113 .cmd0iclkout = MT47H128M16RT25E_INVERT_CLKOUT,
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000114
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000115 .cmd1csratio = MT47H128M16RT25E_RATIO,
116 .cmd1dldiff = MT47H128M16RT25E_DLL_LOCK_DIFF,
117 .cmd1iclkout = MT47H128M16RT25E_INVERT_CLKOUT,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000118
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000119 .cmd2csratio = MT47H128M16RT25E_RATIO,
120 .cmd2dldiff = MT47H128M16RT25E_DLL_LOCK_DIFF,
121 .cmd2iclkout = MT47H128M16RT25E_INVERT_CLKOUT,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000122};
123
124static const struct emif_regs ddr2_emif_reg_data = {
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000125 .sdram_config = MT47H128M16RT25E_EMIF_SDCFG,
126 .ref_ctrl = MT47H128M16RT25E_EMIF_SDREF,
127 .sdram_tim1 = MT47H128M16RT25E_EMIF_TIM1,
128 .sdram_tim2 = MT47H128M16RT25E_EMIF_TIM2,
129 .sdram_tim3 = MT47H128M16RT25E_EMIF_TIM3,
130 .emif_ddr_phy_ctlr_1 = MT47H128M16RT25E_EMIF_READ_LATENCY,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000131};
132
133static const struct ddr_data ddr3_data = {
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000134 .datardsratio0 = MT41J128MJT125_RD_DQS,
135 .datawdsratio0 = MT41J128MJT125_WR_DQS,
136 .datafwsratio0 = MT41J128MJT125_PHY_FIFO_WE,
137 .datawrsratio0 = MT41J128MJT125_PHY_WR_DATA,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000138 .datadldiff0 = PHY_DLL_LOCK_DIFF,
139};
140
Tom Rini385bc752013-03-21 04:30:02 +0000141static const struct ddr_data ddr3_beagleblack_data = {
142 .datardsratio0 = MT41K256M16HA125E_RD_DQS,
143 .datawdsratio0 = MT41K256M16HA125E_WR_DQS,
144 .datafwsratio0 = MT41K256M16HA125E_PHY_FIFO_WE,
145 .datawrsratio0 = MT41K256M16HA125E_PHY_WR_DATA,
146 .datadldiff0 = PHY_DLL_LOCK_DIFF,
147};
148
Jeff Lance7c03a222013-01-14 05:32:20 +0000149static const struct ddr_data ddr3_evm_data = {
150 .datardsratio0 = MT41J512M8RH125_RD_DQS,
151 .datawdsratio0 = MT41J512M8RH125_WR_DQS,
152 .datafwsratio0 = MT41J512M8RH125_PHY_FIFO_WE,
153 .datawrsratio0 = MT41J512M8RH125_PHY_WR_DATA,
154 .datadldiff0 = PHY_DLL_LOCK_DIFF,
155};
156
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000157static const struct cmd_control ddr3_cmd_ctrl_data = {
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000158 .cmd0csratio = MT41J128MJT125_RATIO,
159 .cmd0dldiff = MT41J128MJT125_DLL_LOCK_DIFF,
160 .cmd0iclkout = MT41J128MJT125_INVERT_CLKOUT,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000161
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000162 .cmd1csratio = MT41J128MJT125_RATIO,
163 .cmd1dldiff = MT41J128MJT125_DLL_LOCK_DIFF,
164 .cmd1iclkout = MT41J128MJT125_INVERT_CLKOUT,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000165
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000166 .cmd2csratio = MT41J128MJT125_RATIO,
167 .cmd2dldiff = MT41J128MJT125_DLL_LOCK_DIFF,
168 .cmd2iclkout = MT41J128MJT125_INVERT_CLKOUT,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000169};
170
Tom Rini385bc752013-03-21 04:30:02 +0000171static const struct cmd_control ddr3_beagleblack_cmd_ctrl_data = {
172 .cmd0csratio = MT41K256M16HA125E_RATIO,
173 .cmd0dldiff = MT41K256M16HA125E_DLL_LOCK_DIFF,
174 .cmd0iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
175
176 .cmd1csratio = MT41K256M16HA125E_RATIO,
177 .cmd1dldiff = MT41K256M16HA125E_DLL_LOCK_DIFF,
178 .cmd1iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
179
180 .cmd2csratio = MT41K256M16HA125E_RATIO,
181 .cmd2dldiff = MT41K256M16HA125E_DLL_LOCK_DIFF,
182 .cmd2iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
183};
184
Jeff Lance7c03a222013-01-14 05:32:20 +0000185static const struct cmd_control ddr3_evm_cmd_ctrl_data = {
186 .cmd0csratio = MT41J512M8RH125_RATIO,
187 .cmd0dldiff = MT41J512M8RH125_DLL_LOCK_DIFF,
188 .cmd0iclkout = MT41J512M8RH125_INVERT_CLKOUT,
189
190 .cmd1csratio = MT41J512M8RH125_RATIO,
191 .cmd1dldiff = MT41J512M8RH125_DLL_LOCK_DIFF,
192 .cmd1iclkout = MT41J512M8RH125_INVERT_CLKOUT,
193
194 .cmd2csratio = MT41J512M8RH125_RATIO,
195 .cmd2dldiff = MT41J512M8RH125_DLL_LOCK_DIFF,
196 .cmd2iclkout = MT41J512M8RH125_INVERT_CLKOUT,
197};
198
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000199static struct emif_regs ddr3_emif_reg_data = {
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000200 .sdram_config = MT41J128MJT125_EMIF_SDCFG,
201 .ref_ctrl = MT41J128MJT125_EMIF_SDREF,
202 .sdram_tim1 = MT41J128MJT125_EMIF_TIM1,
203 .sdram_tim2 = MT41J128MJT125_EMIF_TIM2,
204 .sdram_tim3 = MT41J128MJT125_EMIF_TIM3,
205 .zq_config = MT41J128MJT125_ZQ_CFG,
Vaibhav Hiremathc30d57b2013-03-14 21:11:16 +0000206 .emif_ddr_phy_ctlr_1 = MT41J128MJT125_EMIF_READ_LATENCY |
207 PHY_EN_DYN_PWRDN,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000208};
Jeff Lance7c03a222013-01-14 05:32:20 +0000209
Tom Rini385bc752013-03-21 04:30:02 +0000210static struct emif_regs ddr3_beagleblack_emif_reg_data = {
211 .sdram_config = MT41K256M16HA125E_EMIF_SDCFG,
212 .ref_ctrl = MT41K256M16HA125E_EMIF_SDREF,
213 .sdram_tim1 = MT41K256M16HA125E_EMIF_TIM1,
214 .sdram_tim2 = MT41K256M16HA125E_EMIF_TIM2,
215 .sdram_tim3 = MT41K256M16HA125E_EMIF_TIM3,
216 .zq_config = MT41K256M16HA125E_ZQ_CFG,
217 .emif_ddr_phy_ctlr_1 = MT41K256M16HA125E_EMIF_READ_LATENCY,
218};
219
Jeff Lance7c03a222013-01-14 05:32:20 +0000220static struct emif_regs ddr3_evm_emif_reg_data = {
221 .sdram_config = MT41J512M8RH125_EMIF_SDCFG,
222 .ref_ctrl = MT41J512M8RH125_EMIF_SDREF,
223 .sdram_tim1 = MT41J512M8RH125_EMIF_TIM1,
224 .sdram_tim2 = MT41J512M8RH125_EMIF_TIM2,
225 .sdram_tim3 = MT41J512M8RH125_EMIF_TIM3,
226 .zq_config = MT41J512M8RH125_ZQ_CFG,
Vaibhav Hiremathc30d57b2013-03-14 21:11:16 +0000227 .emif_ddr_phy_ctlr_1 = MT41J512M8RH125_EMIF_READ_LATENCY |
228 PHY_EN_DYN_PWRDN,
Jeff Lance7c03a222013-01-14 05:32:20 +0000229};
Peter Korsgaardeb204db2013-05-13 08:36:30 +0000230
231#ifdef CONFIG_SPL_OS_BOOT
232int spl_start_uboot(void)
233{
234 /* break into full u-boot on 'c' */
235 return (serial_tstc() && serial_getc() == 'c');
236}
237#endif
238
Lokesh Vutla89a83bf2013-07-30 10:48:52 +0530239#define OSC (V_OSCK/1000000)
240const struct dpll_params dpll_ddr = {
241 266, OSC-1, 1, -1, -1, -1, -1};
242const struct dpll_params dpll_ddr_evm_sk = {
243 303, OSC-1, 1, -1, -1, -1, -1};
244const struct dpll_params dpll_ddr_bone_black = {
245 400, OSC-1, 1, -1, -1, -1, -1};
246
247const struct dpll_params *get_dpll_ddr_params(void)
248{
249 struct am335x_baseboard_id header;
250
251 enable_i2c0_pin_mux();
252 i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
253 if (read_eeprom(&header) < 0)
254 puts("Could not get board ID.\n");
255
256 if (board_is_evm_sk(&header))
257 return &dpll_ddr_evm_sk;
258 else if (board_is_bone_lt(&header))
259 return &dpll_ddr_bone_black;
260 else if (board_is_evm_15_or_later(&header))
261 return &dpll_ddr_evm_sk;
262 else
263 return &dpll_ddr;
264}
265
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530266void set_uart_mux_conf(void)
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000267{
Andrew Bradford65c51ff2012-10-25 08:21:30 -0400268#ifdef CONFIG_SERIAL1
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000269 enable_uart0_pin_mux();
Andrew Bradford65c51ff2012-10-25 08:21:30 -0400270#endif /* CONFIG_SERIAL1 */
271#ifdef CONFIG_SERIAL2
272 enable_uart1_pin_mux();
273#endif /* CONFIG_SERIAL2 */
274#ifdef CONFIG_SERIAL3
275 enable_uart2_pin_mux();
276#endif /* CONFIG_SERIAL3 */
277#ifdef CONFIG_SERIAL4
278 enable_uart3_pin_mux();
279#endif /* CONFIG_SERIAL4 */
280#ifdef CONFIG_SERIAL5
281 enable_uart4_pin_mux();
282#endif /* CONFIG_SERIAL5 */
283#ifdef CONFIG_SERIAL6
284 enable_uart5_pin_mux();
285#endif /* CONFIG_SERIAL6 */
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530286}
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000287
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530288void set_mux_conf_regs(void)
289{
290 __maybe_unused struct am335x_baseboard_id header;
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000291
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530292 if (read_eeprom(&header) < 0)
293 puts("Could not get board ID.\n");
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000294
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530295 enable_board_pin_mux(&header);
296}
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000297
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530298void sdram_init(void)
299{
300 __maybe_unused struct am335x_baseboard_id header;
Lokesh Vutlab1b6fba2013-07-30 10:48:53 +0530301
Tom Rini4021fd92013-07-18 15:13:01 -0400302 if (read_eeprom(&header) < 0)
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000303 puts("Could not get board ID.\n");
304
Tom Rini4021fd92013-07-18 15:13:01 -0400305 if (board_is_evm_sk(&header)) {
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000306 /*
307 * EVM SK 1.2A and later use gpio0_7 to enable DDR3.
308 * This is safe enough to do on older revs.
309 */
310 gpio_request(GPIO_DDR_VTT_EN, "ddr_vtt_en");
311 gpio_direction_output(GPIO_DDR_VTT_EN, 1);
312 }
313
Tom Rini4021fd92013-07-18 15:13:01 -0400314 if (board_is_evm_sk(&header))
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000315 config_ddr(303, MT41J128MJT125_IOCTRL_VALUE, &ddr3_data,
Matt Porter65991ec2013-03-15 10:07:03 +0000316 &ddr3_cmd_ctrl_data, &ddr3_emif_reg_data, 0);
Tom Rini4021fd92013-07-18 15:13:01 -0400317 else if (board_is_bone_lt(&header))
Tom Rini8939ec32013-04-10 15:10:54 +0200318 config_ddr(400, MT41K256M16HA125E_IOCTRL_VALUE,
Tom Rini385bc752013-03-21 04:30:02 +0000319 &ddr3_beagleblack_data,
320 &ddr3_beagleblack_cmd_ctrl_data,
321 &ddr3_beagleblack_emif_reg_data, 0);
Tom Rini4021fd92013-07-18 15:13:01 -0400322 else if (board_is_evm_15_or_later(&header))
Jeff Lance7c03a222013-01-14 05:32:20 +0000323 config_ddr(303, MT41J512M8RH125_IOCTRL_VALUE, &ddr3_evm_data,
Matt Porter65991ec2013-03-15 10:07:03 +0000324 &ddr3_evm_cmd_ctrl_data, &ddr3_evm_emif_reg_data, 0);
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000325 else
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000326 config_ddr(266, MT47H128M16RT25E_IOCTRL_VALUE, &ddr2_data,
Matt Porter65991ec2013-03-15 10:07:03 +0000327 &ddr2_cmd_ctrl_data, &ddr2_emif_reg_data, 0);
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000328}
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530329#endif
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000330
331/*
332 * Basic board specific setup. Pinmux has been handled already.
333 */
334int board_init(void)
335{
Steve Kipiszbe9b6f82013-07-18 15:13:03 -0400336#ifdef CONFIG_NOR
337 const u32 gpmc_nor[GPMC_MAX_REG] = { STNOR_GPMC_CONFIG1,
338 STNOR_GPMC_CONFIG2, STNOR_GPMC_CONFIG3, STNOR_GPMC_CONFIG4,
339 STNOR_GPMC_CONFIG5, STNOR_GPMC_CONFIG6, STNOR_GPMC_CONFIG7 };
340#endif
341
Tom Rinif3b6a1d2013-08-09 11:22:13 -0400342 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000343
Ilya Yanok3d9725e2012-11-06 13:06:31 +0000344 gpmc_init();
345
Steve Kipiszbe9b6f82013-07-18 15:13:03 -0400346#ifdef CONFIG_NOR
347 /* Reconfigure CS0 for NOR instead of NAND. */
348 enable_gpmc_cs_config(gpmc_nor, &gpmc_cfg->cs[0],
349 CONFIG_SYS_FLASH_BASE, GPMC_SIZE_16M);
350#endif
351
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000352 return 0;
353}
354
Tom Rini40271852012-10-24 07:28:17 +0000355#ifdef CONFIG_BOARD_LATE_INIT
356int board_late_init(void)
357{
358#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
359 char safe_string[HDR_NAME_LEN + 1];
Tom Rini4021fd92013-07-18 15:13:01 -0400360 struct am335x_baseboard_id header;
361
362 if (read_eeprom(&header) < 0)
363 puts("Could not get board ID.\n");
Tom Rini40271852012-10-24 07:28:17 +0000364
365 /* Now set variables based on the header. */
366 strncpy(safe_string, (char *)header.name, sizeof(header.name));
367 safe_string[sizeof(header.name)] = 0;
368 setenv("board_name", safe_string);
369
370 strncpy(safe_string, (char *)header.version, sizeof(header.version));
371 safe_string[sizeof(header.version)] = 0;
372 setenv("board_rev", safe_string);
373#endif
374
375 return 0;
376}
377#endif
378
Ilya Yanok0760a0d2013-02-05 11:36:26 +0000379#if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) || \
380 (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD))
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000381static void cpsw_control(int enabled)
382{
383 /* VTP can be added here */
384
385 return;
386}
387
388static struct cpsw_slave_data cpsw_slaves[] = {
389 {
390 .slave_reg_ofs = 0x208,
391 .sliver_reg_ofs = 0xd80,
392 .phy_id = 0,
393 },
394 {
395 .slave_reg_ofs = 0x308,
396 .sliver_reg_ofs = 0xdc0,
397 .phy_id = 1,
398 },
399};
400
401static struct cpsw_platform_data cpsw_data = {
Matt Portere24646f2013-03-15 10:07:02 +0000402 .mdio_base = CPSW_MDIO_BASE,
403 .cpsw_base = CPSW_BASE,
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000404 .mdio_div = 0xff,
405 .channels = 8,
406 .cpdma_reg_ofs = 0x800,
407 .slaves = 1,
408 .slave_data = cpsw_slaves,
409 .ale_reg_ofs = 0xd00,
410 .ale_entries = 1024,
411 .host_port_reg_ofs = 0x108,
412 .hw_stats_reg_ofs = 0x900,
Mugunthan V Nff559872013-07-08 16:04:37 +0530413 .bd_ram_ofs = 0x2000,
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000414 .mac_control = (1 << 5),
415 .control = cpsw_control,
416 .host_port_num = 0,
417 .version = CPSW_CTRL_VERSION_2,
418};
Ilya Yanok44a2c072012-11-06 13:48:24 +0000419#endif
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000420
Ilya Yanok44a2c072012-11-06 13:48:24 +0000421#if defined(CONFIG_DRIVER_TI_CPSW) || \
422 (defined(CONFIG_USB_ETHER) && defined(CONFIG_MUSB_GADGET))
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000423int board_eth_init(bd_t *bis)
424{
Ilya Yanok44a2c072012-11-06 13:48:24 +0000425 int rv, n = 0;
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000426 uint8_t mac_addr[6];
427 uint32_t mac_hi, mac_lo;
Tom Rini4021fd92013-07-18 15:13:01 -0400428 __maybe_unused struct am335x_baseboard_id header;
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000429
Ilya Yanok0760a0d2013-02-05 11:36:26 +0000430 /* try reading mac address from efuse */
431 mac_lo = readl(&cdev->macid0l);
432 mac_hi = readl(&cdev->macid0h);
433 mac_addr[0] = mac_hi & 0xFF;
434 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
435 mac_addr[2] = (mac_hi & 0xFF0000) >> 16;
436 mac_addr[3] = (mac_hi & 0xFF000000) >> 24;
437 mac_addr[4] = mac_lo & 0xFF;
438 mac_addr[5] = (mac_lo & 0xFF00) >> 8;
439
440#if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) || \
441 (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD))
442 if (!getenv("ethaddr")) {
443 printf("<ethaddr> not set. Validating first E-fuse MAC\n");
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000444
445 if (is_valid_ether_addr(mac_addr))
446 eth_setenv_enetaddr("ethaddr", mac_addr);
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000447 }
448
Joel A Fernandesf7488542013-05-07 05:52:55 +0000449#ifdef CONFIG_DRIVER_TI_CPSW
Tom Rini4021fd92013-07-18 15:13:01 -0400450 if (read_eeprom(&header) < 0)
451 puts("Could not get board ID.\n");
452
453 if (board_is_bone(&header) || board_is_bone_lt(&header) ||
454 board_is_idk(&header)) {
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000455 writel(MII_MODE_ENABLE, &cdev->miisel);
456 cpsw_slaves[0].phy_if = cpsw_slaves[1].phy_if =
457 PHY_INTERFACE_MODE_MII;
458 } else {
Heiko Schocherc4fea292013-08-19 16:38:56 +0200459 writel((RGMII_MODE_ENABLE | RGMII_INT_DELAY), &cdev->miisel);
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000460 cpsw_slaves[0].phy_if = cpsw_slaves[1].phy_if =
461 PHY_INTERFACE_MODE_RGMII;
462 }
463
Ilya Yanok44a2c072012-11-06 13:48:24 +0000464 rv = cpsw_register(&cpsw_data);
465 if (rv < 0)
466 printf("Error %d registering CPSW switch\n", rv);
467 else
468 n += rv;
Joel A Fernandesf7488542013-05-07 05:52:55 +0000469#endif
Tom Rini183943d2013-02-12 14:59:23 -0500470
471 /*
472 *
473 * CPSW RGMII Internal Delay Mode is not supported in all PVT
474 * operating points. So we must set the TX clock delay feature
475 * in the AR8051 PHY. Since we only support a single ethernet
476 * device in U-Boot, we only do this for the first instance.
477 */
478#define AR8051_PHY_DEBUG_ADDR_REG 0x1d
479#define AR8051_PHY_DEBUG_DATA_REG 0x1e
480#define AR8051_DEBUG_RGMII_CLK_DLY_REG 0x5
481#define AR8051_RGMII_TX_CLK_DLY 0x100
482
Tom Rini4021fd92013-07-18 15:13:01 -0400483 if (board_is_evm_sk(&header) || board_is_gp_evm(&header)) {
Tom Rini183943d2013-02-12 14:59:23 -0500484 const char *devname;
485 devname = miiphy_get_current_dev();
486
487 miiphy_write(devname, 0x0, AR8051_PHY_DEBUG_ADDR_REG,
488 AR8051_DEBUG_RGMII_CLK_DLY_REG);
489 miiphy_write(devname, 0x0, AR8051_PHY_DEBUG_DATA_REG,
490 AR8051_RGMII_TX_CLK_DLY);
491 }
Ilya Yanok44a2c072012-11-06 13:48:24 +0000492#endif
Ilya Yanok0760a0d2013-02-05 11:36:26 +0000493#if defined(CONFIG_USB_ETHER) && \
494 (!defined(CONFIG_SPL_BUILD) || defined(CONFIG_SPL_USBETH_SUPPORT))
495 if (is_valid_ether_addr(mac_addr))
496 eth_setenv_enetaddr("usbnet_devaddr", mac_addr);
497
Ilya Yanok44a2c072012-11-06 13:48:24 +0000498 rv = usb_eth_initialize(bis);
499 if (rv < 0)
500 printf("Error %d registering USB_ETHER\n", rv);
501 else
502 n += rv;
503#endif
504 return n;
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000505}
506#endif