blob: 728afc2ba33bc3ee12b74c47f2100a300d7da14a [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
33static struct wd_timer *wdtimer = (struct wd_timer *)WDT_BASE;
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000034
35/* MII mode defines */
36#define MII_MODE_ENABLE 0x0
Yegor Yefremove44314a2012-11-26 03:30:42 +000037#define RGMII_MODE_ENABLE 0x3A
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000038
39/* GPIO that controls power to DDR on EVM-SK */
40#define GPIO_DDR_VTT_EN 7
41
42static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
43
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000044/*
45 * Read header information from EEPROM into global structure.
46 */
Tom Rini4021fd92013-07-18 15:13:01 -040047static int read_eeprom(struct am335x_baseboard_id *header)
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000048{
49 /* Check if baseboard eeprom is available */
50 if (i2c_probe(CONFIG_SYS_I2C_EEPROM_ADDR)) {
51 puts("Could not probe the EEPROM; something fundamentally "
52 "wrong on the I2C bus.\n");
53 return -ENODEV;
54 }
55
56 /* read the eeprom using i2c */
Tom Rini4021fd92013-07-18 15:13:01 -040057 if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0, 2, (uchar *)header,
58 sizeof(struct am335x_baseboard_id))) {
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000059 puts("Could not read the EEPROM; something fundamentally"
60 " wrong on the I2C bus.\n");
61 return -EIO;
62 }
63
Tom Rini4021fd92013-07-18 15:13:01 -040064 if (header->magic != 0xEE3355AA) {
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000065 /*
66 * read the eeprom using i2c again,
67 * but use only a 1 byte address
68 */
Tom Rini4021fd92013-07-18 15:13:01 -040069 if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0, 1, (uchar *)header,
70 sizeof(struct am335x_baseboard_id))) {
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000071 puts("Could not read the EEPROM; something "
72 "fundamentally wrong on the I2C bus.\n");
73 return -EIO;
74 }
75
Tom Rini4021fd92013-07-18 15:13:01 -040076 if (header->magic != 0xEE3355AA) {
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000077 printf("Incorrect magic number (0x%x) in EEPROM\n",
Tom Rini4021fd92013-07-18 15:13:01 -040078 header->magic);
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000079 return -EINVAL;
80 }
81 }
82
83 return 0;
84}
85
Steve Kipiszc1399b42013-07-18 15:13:04 -040086#if defined(CONFIG_SPL_BUILD) || defined(CONFIG_NOR_BOOT)
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +000087static const struct ddr_data ddr2_data = {
Peter Korsgaard3adb8272012-10-18 01:21:13 +000088 .datardsratio0 = ((MT47H128M16RT25E_RD_DQS<<30) |
89 (MT47H128M16RT25E_RD_DQS<<20) |
90 (MT47H128M16RT25E_RD_DQS<<10) |
91 (MT47H128M16RT25E_RD_DQS<<0)),
92 .datawdsratio0 = ((MT47H128M16RT25E_WR_DQS<<30) |
93 (MT47H128M16RT25E_WR_DQS<<20) |
94 (MT47H128M16RT25E_WR_DQS<<10) |
95 (MT47H128M16RT25E_WR_DQS<<0)),
96 .datawiratio0 = ((MT47H128M16RT25E_PHY_WRLVL<<30) |
97 (MT47H128M16RT25E_PHY_WRLVL<<20) |
98 (MT47H128M16RT25E_PHY_WRLVL<<10) |
99 (MT47H128M16RT25E_PHY_WRLVL<<0)),
100 .datagiratio0 = ((MT47H128M16RT25E_PHY_GATELVL<<30) |
101 (MT47H128M16RT25E_PHY_GATELVL<<20) |
102 (MT47H128M16RT25E_PHY_GATELVL<<10) |
103 (MT47H128M16RT25E_PHY_GATELVL<<0)),
104 .datafwsratio0 = ((MT47H128M16RT25E_PHY_FIFO_WE<<30) |
105 (MT47H128M16RT25E_PHY_FIFO_WE<<20) |
106 (MT47H128M16RT25E_PHY_FIFO_WE<<10) |
107 (MT47H128M16RT25E_PHY_FIFO_WE<<0)),
108 .datawrsratio0 = ((MT47H128M16RT25E_PHY_WR_DATA<<30) |
109 (MT47H128M16RT25E_PHY_WR_DATA<<20) |
110 (MT47H128M16RT25E_PHY_WR_DATA<<10) |
111 (MT47H128M16RT25E_PHY_WR_DATA<<0)),
112 .datauserank0delay = MT47H128M16RT25E_PHY_RANK0_DELAY,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000113 .datadldiff0 = PHY_DLL_LOCK_DIFF,
114};
115
116static const struct cmd_control ddr2_cmd_ctrl_data = {
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000117 .cmd0csratio = MT47H128M16RT25E_RATIO,
118 .cmd0dldiff = MT47H128M16RT25E_DLL_LOCK_DIFF,
119 .cmd0iclkout = MT47H128M16RT25E_INVERT_CLKOUT,
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000120
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000121 .cmd1csratio = MT47H128M16RT25E_RATIO,
122 .cmd1dldiff = MT47H128M16RT25E_DLL_LOCK_DIFF,
123 .cmd1iclkout = MT47H128M16RT25E_INVERT_CLKOUT,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000124
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000125 .cmd2csratio = MT47H128M16RT25E_RATIO,
126 .cmd2dldiff = MT47H128M16RT25E_DLL_LOCK_DIFF,
127 .cmd2iclkout = MT47H128M16RT25E_INVERT_CLKOUT,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000128};
129
130static const struct emif_regs ddr2_emif_reg_data = {
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000131 .sdram_config = MT47H128M16RT25E_EMIF_SDCFG,
132 .ref_ctrl = MT47H128M16RT25E_EMIF_SDREF,
133 .sdram_tim1 = MT47H128M16RT25E_EMIF_TIM1,
134 .sdram_tim2 = MT47H128M16RT25E_EMIF_TIM2,
135 .sdram_tim3 = MT47H128M16RT25E_EMIF_TIM3,
136 .emif_ddr_phy_ctlr_1 = MT47H128M16RT25E_EMIF_READ_LATENCY,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000137};
138
139static const struct ddr_data ddr3_data = {
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000140 .datardsratio0 = MT41J128MJT125_RD_DQS,
141 .datawdsratio0 = MT41J128MJT125_WR_DQS,
142 .datafwsratio0 = MT41J128MJT125_PHY_FIFO_WE,
143 .datawrsratio0 = MT41J128MJT125_PHY_WR_DATA,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000144 .datadldiff0 = PHY_DLL_LOCK_DIFF,
145};
146
Tom Rini385bc752013-03-21 04:30:02 +0000147static const struct ddr_data ddr3_beagleblack_data = {
148 .datardsratio0 = MT41K256M16HA125E_RD_DQS,
149 .datawdsratio0 = MT41K256M16HA125E_WR_DQS,
150 .datafwsratio0 = MT41K256M16HA125E_PHY_FIFO_WE,
151 .datawrsratio0 = MT41K256M16HA125E_PHY_WR_DATA,
152 .datadldiff0 = PHY_DLL_LOCK_DIFF,
153};
154
Jeff Lance7c03a222013-01-14 05:32:20 +0000155static const struct ddr_data ddr3_evm_data = {
156 .datardsratio0 = MT41J512M8RH125_RD_DQS,
157 .datawdsratio0 = MT41J512M8RH125_WR_DQS,
158 .datafwsratio0 = MT41J512M8RH125_PHY_FIFO_WE,
159 .datawrsratio0 = MT41J512M8RH125_PHY_WR_DATA,
160 .datadldiff0 = PHY_DLL_LOCK_DIFF,
161};
162
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000163static const struct cmd_control ddr3_cmd_ctrl_data = {
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000164 .cmd0csratio = MT41J128MJT125_RATIO,
165 .cmd0dldiff = MT41J128MJT125_DLL_LOCK_DIFF,
166 .cmd0iclkout = MT41J128MJT125_INVERT_CLKOUT,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000167
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000168 .cmd1csratio = MT41J128MJT125_RATIO,
169 .cmd1dldiff = MT41J128MJT125_DLL_LOCK_DIFF,
170 .cmd1iclkout = MT41J128MJT125_INVERT_CLKOUT,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000171
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000172 .cmd2csratio = MT41J128MJT125_RATIO,
173 .cmd2dldiff = MT41J128MJT125_DLL_LOCK_DIFF,
174 .cmd2iclkout = MT41J128MJT125_INVERT_CLKOUT,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000175};
176
Tom Rini385bc752013-03-21 04:30:02 +0000177static const struct cmd_control ddr3_beagleblack_cmd_ctrl_data = {
178 .cmd0csratio = MT41K256M16HA125E_RATIO,
179 .cmd0dldiff = MT41K256M16HA125E_DLL_LOCK_DIFF,
180 .cmd0iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
181
182 .cmd1csratio = MT41K256M16HA125E_RATIO,
183 .cmd1dldiff = MT41K256M16HA125E_DLL_LOCK_DIFF,
184 .cmd1iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
185
186 .cmd2csratio = MT41K256M16HA125E_RATIO,
187 .cmd2dldiff = MT41K256M16HA125E_DLL_LOCK_DIFF,
188 .cmd2iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
189};
190
Jeff Lance7c03a222013-01-14 05:32:20 +0000191static const struct cmd_control ddr3_evm_cmd_ctrl_data = {
192 .cmd0csratio = MT41J512M8RH125_RATIO,
193 .cmd0dldiff = MT41J512M8RH125_DLL_LOCK_DIFF,
194 .cmd0iclkout = MT41J512M8RH125_INVERT_CLKOUT,
195
196 .cmd1csratio = MT41J512M8RH125_RATIO,
197 .cmd1dldiff = MT41J512M8RH125_DLL_LOCK_DIFF,
198 .cmd1iclkout = MT41J512M8RH125_INVERT_CLKOUT,
199
200 .cmd2csratio = MT41J512M8RH125_RATIO,
201 .cmd2dldiff = MT41J512M8RH125_DLL_LOCK_DIFF,
202 .cmd2iclkout = MT41J512M8RH125_INVERT_CLKOUT,
203};
204
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000205static struct emif_regs ddr3_emif_reg_data = {
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000206 .sdram_config = MT41J128MJT125_EMIF_SDCFG,
207 .ref_ctrl = MT41J128MJT125_EMIF_SDREF,
208 .sdram_tim1 = MT41J128MJT125_EMIF_TIM1,
209 .sdram_tim2 = MT41J128MJT125_EMIF_TIM2,
210 .sdram_tim3 = MT41J128MJT125_EMIF_TIM3,
211 .zq_config = MT41J128MJT125_ZQ_CFG,
Vaibhav Hiremathc30d57b2013-03-14 21:11:16 +0000212 .emif_ddr_phy_ctlr_1 = MT41J128MJT125_EMIF_READ_LATENCY |
213 PHY_EN_DYN_PWRDN,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000214};
Jeff Lance7c03a222013-01-14 05:32:20 +0000215
Tom Rini385bc752013-03-21 04:30:02 +0000216static struct emif_regs ddr3_beagleblack_emif_reg_data = {
217 .sdram_config = MT41K256M16HA125E_EMIF_SDCFG,
218 .ref_ctrl = MT41K256M16HA125E_EMIF_SDREF,
219 .sdram_tim1 = MT41K256M16HA125E_EMIF_TIM1,
220 .sdram_tim2 = MT41K256M16HA125E_EMIF_TIM2,
221 .sdram_tim3 = MT41K256M16HA125E_EMIF_TIM3,
222 .zq_config = MT41K256M16HA125E_ZQ_CFG,
223 .emif_ddr_phy_ctlr_1 = MT41K256M16HA125E_EMIF_READ_LATENCY,
224};
225
Jeff Lance7c03a222013-01-14 05:32:20 +0000226static struct emif_regs ddr3_evm_emif_reg_data = {
227 .sdram_config = MT41J512M8RH125_EMIF_SDCFG,
228 .ref_ctrl = MT41J512M8RH125_EMIF_SDREF,
229 .sdram_tim1 = MT41J512M8RH125_EMIF_TIM1,
230 .sdram_tim2 = MT41J512M8RH125_EMIF_TIM2,
231 .sdram_tim3 = MT41J512M8RH125_EMIF_TIM3,
232 .zq_config = MT41J512M8RH125_ZQ_CFG,
Vaibhav Hiremathc30d57b2013-03-14 21:11:16 +0000233 .emif_ddr_phy_ctlr_1 = MT41J512M8RH125_EMIF_READ_LATENCY |
234 PHY_EN_DYN_PWRDN,
Jeff Lance7c03a222013-01-14 05:32:20 +0000235};
Peter Korsgaardeb204db2013-05-13 08:36:30 +0000236
237#ifdef CONFIG_SPL_OS_BOOT
238int spl_start_uboot(void)
239{
240 /* break into full u-boot on 'c' */
241 return (serial_tstc() && serial_getc() == 'c');
242}
243#endif
244
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000245#endif
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000246
247/*
248 * early system init of muxing and clocks.
249 */
250void s_init(void)
251{
Steve Kipiszc1399b42013-07-18 15:13:04 -0400252 __maybe_unused struct am335x_baseboard_id header;
Tom Rini4021fd92013-07-18 15:13:01 -0400253
Tom Rini51df26c2013-05-31 12:31:59 -0400254 /*
Steve Kipiszc1399b42013-07-18 15:13:04 -0400255 * The ROM will only have set up sufficient pinmux to allow for the
256 * first 4KiB NOR to be read, we must finish doing what we know of
257 * the NOR mux in this space in order to continue.
258 */
259#ifdef CONFIG_NOR_BOOT
260 asm("stmfd sp!, {r2 - r4}");
261 asm("movw r4, #0x8A4");
262 asm("movw r3, #0x44E1");
263 asm("orr r4, r4, r3, lsl #16");
264 asm("mov r2, #9");
265 asm("mov r3, #8");
266 asm("gpmc_mux: str r2, [r4], #4");
267 asm("subs r3, r3, #1");
268 asm("bne gpmc_mux");
269 asm("ldmfd sp!, {r2 - r4}");
270#endif
271
272#ifdef CONFIG_SPL_BUILD
273 /*
Tom Rini51df26c2013-05-31 12:31:59 -0400274 * Save the boot parameters passed from romcode.
275 * We cannot delay the saving further than this,
276 * to prevent overwrites.
277 */
Tom Rini51df26c2013-05-31 12:31:59 -0400278 save_omap_boot_params();
279#endif
280
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000281 /* WDT1 is already running when the bootloader gets control
282 * Disable it to avoid "random" resets
283 */
284 writel(0xAAAA, &wdtimer->wdtwspr);
285 while (readl(&wdtimer->wdtwwps) != 0x0)
286 ;
287 writel(0x5555, &wdtimer->wdtwspr);
288 while (readl(&wdtimer->wdtwwps) != 0x0)
289 ;
290
Steve Kipiszc1399b42013-07-18 15:13:04 -0400291#if defined(CONFIG_SPL_BUILD) || defined(CONFIG_NOR_BOOT)
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000292 /* Setup the PLLs and the clocks for the peripherals */
293 pll_init();
294
295 /* Enable RTC32K clock */
296 rtc32k_enable();
297
Andrew Bradford65c51ff2012-10-25 08:21:30 -0400298#ifdef CONFIG_SERIAL1
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000299 enable_uart0_pin_mux();
Andrew Bradford65c51ff2012-10-25 08:21:30 -0400300#endif /* CONFIG_SERIAL1 */
301#ifdef CONFIG_SERIAL2
302 enable_uart1_pin_mux();
303#endif /* CONFIG_SERIAL2 */
304#ifdef CONFIG_SERIAL3
305 enable_uart2_pin_mux();
306#endif /* CONFIG_SERIAL3 */
307#ifdef CONFIG_SERIAL4
308 enable_uart3_pin_mux();
309#endif /* CONFIG_SERIAL4 */
310#ifdef CONFIG_SERIAL5
311 enable_uart4_pin_mux();
312#endif /* CONFIG_SERIAL5 */
313#ifdef CONFIG_SERIAL6
314 enable_uart5_pin_mux();
315#endif /* CONFIG_SERIAL6 */
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000316
Heiko Schocher57004c52013-06-04 11:00:57 +0200317 uart_soft_reset();
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000318
Steve Kipiszc1399b42013-07-18 15:13:04 -0400319#if defined(CONFIG_NOR_BOOT)
320 /* We want our console now. */
321 gd->baudrate = CONFIG_BAUDRATE;
322 serial_init();
323 gd->have_console = 1;
324#else
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000325 gd = &gdata;
326
327 preloader_console_init();
Steve Kipiszc1399b42013-07-18 15:13:04 -0400328#endif
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000329
330 /* Initalize the board header */
331 enable_i2c0_pin_mux();
332 i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
Tom Rini4021fd92013-07-18 15:13:01 -0400333 if (read_eeprom(&header) < 0)
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000334 puts("Could not get board ID.\n");
335
336 enable_board_pin_mux(&header);
Tom Rini4021fd92013-07-18 15:13:01 -0400337 if (board_is_evm_sk(&header)) {
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000338 /*
339 * EVM SK 1.2A and later use gpio0_7 to enable DDR3.
340 * This is safe enough to do on older revs.
341 */
342 gpio_request(GPIO_DDR_VTT_EN, "ddr_vtt_en");
343 gpio_direction_output(GPIO_DDR_VTT_EN, 1);
344 }
345
Tom Rini4021fd92013-07-18 15:13:01 -0400346 if (board_is_evm_sk(&header))
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000347 config_ddr(303, MT41J128MJT125_IOCTRL_VALUE, &ddr3_data,
Matt Porter65991ec2013-03-15 10:07:03 +0000348 &ddr3_cmd_ctrl_data, &ddr3_emif_reg_data, 0);
Tom Rini4021fd92013-07-18 15:13:01 -0400349 else if (board_is_bone_lt(&header))
Tom Rini8939ec32013-04-10 15:10:54 +0200350 config_ddr(400, MT41K256M16HA125E_IOCTRL_VALUE,
Tom Rini385bc752013-03-21 04:30:02 +0000351 &ddr3_beagleblack_data,
352 &ddr3_beagleblack_cmd_ctrl_data,
353 &ddr3_beagleblack_emif_reg_data, 0);
Tom Rini4021fd92013-07-18 15:13:01 -0400354 else if (board_is_evm_15_or_later(&header))
Jeff Lance7c03a222013-01-14 05:32:20 +0000355 config_ddr(303, MT41J512M8RH125_IOCTRL_VALUE, &ddr3_evm_data,
Matt Porter65991ec2013-03-15 10:07:03 +0000356 &ddr3_evm_cmd_ctrl_data, &ddr3_evm_emif_reg_data, 0);
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000357 else
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000358 config_ddr(266, MT47H128M16RT25E_IOCTRL_VALUE, &ddr2_data,
Matt Porter65991ec2013-03-15 10:07:03 +0000359 &ddr2_cmd_ctrl_data, &ddr2_emif_reg_data, 0);
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000360#endif
361}
362
363/*
364 * Basic board specific setup. Pinmux has been handled already.
365 */
366int board_init(void)
367{
Steve Kipiszbe9b6f82013-07-18 15:13:03 -0400368#ifdef CONFIG_NOR
369 const u32 gpmc_nor[GPMC_MAX_REG] = { STNOR_GPMC_CONFIG1,
370 STNOR_GPMC_CONFIG2, STNOR_GPMC_CONFIG3, STNOR_GPMC_CONFIG4,
371 STNOR_GPMC_CONFIG5, STNOR_GPMC_CONFIG6, STNOR_GPMC_CONFIG7 };
372#endif
373
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000374 gd->bd->bi_boot_params = PHYS_DRAM_1 + 0x100;
375
Ilya Yanok3d9725e2012-11-06 13:06:31 +0000376 gpmc_init();
377
Steve Kipiszbe9b6f82013-07-18 15:13:03 -0400378#ifdef CONFIG_NOR
379 /* Reconfigure CS0 for NOR instead of NAND. */
380 enable_gpmc_cs_config(gpmc_nor, &gpmc_cfg->cs[0],
381 CONFIG_SYS_FLASH_BASE, GPMC_SIZE_16M);
382#endif
383
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000384 return 0;
385}
386
Tom Rini40271852012-10-24 07:28:17 +0000387#ifdef CONFIG_BOARD_LATE_INIT
388int board_late_init(void)
389{
390#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
391 char safe_string[HDR_NAME_LEN + 1];
Tom Rini4021fd92013-07-18 15:13:01 -0400392 struct am335x_baseboard_id header;
393
394 if (read_eeprom(&header) < 0)
395 puts("Could not get board ID.\n");
Tom Rini40271852012-10-24 07:28:17 +0000396
397 /* Now set variables based on the header. */
398 strncpy(safe_string, (char *)header.name, sizeof(header.name));
399 safe_string[sizeof(header.name)] = 0;
400 setenv("board_name", safe_string);
401
402 strncpy(safe_string, (char *)header.version, sizeof(header.version));
403 safe_string[sizeof(header.version)] = 0;
404 setenv("board_rev", safe_string);
405#endif
406
407 return 0;
408}
409#endif
410
Ilya Yanok0760a0d2013-02-05 11:36:26 +0000411#if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) || \
412 (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD))
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000413static void cpsw_control(int enabled)
414{
415 /* VTP can be added here */
416
417 return;
418}
419
420static struct cpsw_slave_data cpsw_slaves[] = {
421 {
422 .slave_reg_ofs = 0x208,
423 .sliver_reg_ofs = 0xd80,
424 .phy_id = 0,
425 },
426 {
427 .slave_reg_ofs = 0x308,
428 .sliver_reg_ofs = 0xdc0,
429 .phy_id = 1,
430 },
431};
432
433static struct cpsw_platform_data cpsw_data = {
Matt Portere24646f2013-03-15 10:07:02 +0000434 .mdio_base = CPSW_MDIO_BASE,
435 .cpsw_base = CPSW_BASE,
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000436 .mdio_div = 0xff,
437 .channels = 8,
438 .cpdma_reg_ofs = 0x800,
439 .slaves = 1,
440 .slave_data = cpsw_slaves,
441 .ale_reg_ofs = 0xd00,
442 .ale_entries = 1024,
443 .host_port_reg_ofs = 0x108,
444 .hw_stats_reg_ofs = 0x900,
Mugunthan V Nff559872013-07-08 16:04:37 +0530445 .bd_ram_ofs = 0x2000,
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000446 .mac_control = (1 << 5),
447 .control = cpsw_control,
448 .host_port_num = 0,
449 .version = CPSW_CTRL_VERSION_2,
450};
Ilya Yanok44a2c072012-11-06 13:48:24 +0000451#endif
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000452
Ilya Yanok44a2c072012-11-06 13:48:24 +0000453#if defined(CONFIG_DRIVER_TI_CPSW) || \
454 (defined(CONFIG_USB_ETHER) && defined(CONFIG_MUSB_GADGET))
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000455int board_eth_init(bd_t *bis)
456{
Ilya Yanok44a2c072012-11-06 13:48:24 +0000457 int rv, n = 0;
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000458 uint8_t mac_addr[6];
459 uint32_t mac_hi, mac_lo;
Tom Rini4021fd92013-07-18 15:13:01 -0400460 __maybe_unused struct am335x_baseboard_id header;
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000461
Ilya Yanok0760a0d2013-02-05 11:36:26 +0000462 /* try reading mac address from efuse */
463 mac_lo = readl(&cdev->macid0l);
464 mac_hi = readl(&cdev->macid0h);
465 mac_addr[0] = mac_hi & 0xFF;
466 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
467 mac_addr[2] = (mac_hi & 0xFF0000) >> 16;
468 mac_addr[3] = (mac_hi & 0xFF000000) >> 24;
469 mac_addr[4] = mac_lo & 0xFF;
470 mac_addr[5] = (mac_lo & 0xFF00) >> 8;
471
472#if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) || \
473 (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD))
474 if (!getenv("ethaddr")) {
475 printf("<ethaddr> not set. Validating first E-fuse MAC\n");
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000476
477 if (is_valid_ether_addr(mac_addr))
478 eth_setenv_enetaddr("ethaddr", mac_addr);
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000479 }
480
Joel A Fernandesf7488542013-05-07 05:52:55 +0000481#ifdef CONFIG_DRIVER_TI_CPSW
Tom Rini4021fd92013-07-18 15:13:01 -0400482 if (read_eeprom(&header) < 0)
483 puts("Could not get board ID.\n");
484
485 if (board_is_bone(&header) || board_is_bone_lt(&header) ||
486 board_is_idk(&header)) {
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000487 writel(MII_MODE_ENABLE, &cdev->miisel);
488 cpsw_slaves[0].phy_if = cpsw_slaves[1].phy_if =
489 PHY_INTERFACE_MODE_MII;
490 } else {
491 writel(RGMII_MODE_ENABLE, &cdev->miisel);
492 cpsw_slaves[0].phy_if = cpsw_slaves[1].phy_if =
493 PHY_INTERFACE_MODE_RGMII;
494 }
495
Ilya Yanok44a2c072012-11-06 13:48:24 +0000496 rv = cpsw_register(&cpsw_data);
497 if (rv < 0)
498 printf("Error %d registering CPSW switch\n", rv);
499 else
500 n += rv;
Joel A Fernandesf7488542013-05-07 05:52:55 +0000501#endif
Tom Rini183943d2013-02-12 14:59:23 -0500502
503 /*
504 *
505 * CPSW RGMII Internal Delay Mode is not supported in all PVT
506 * operating points. So we must set the TX clock delay feature
507 * in the AR8051 PHY. Since we only support a single ethernet
508 * device in U-Boot, we only do this for the first instance.
509 */
510#define AR8051_PHY_DEBUG_ADDR_REG 0x1d
511#define AR8051_PHY_DEBUG_DATA_REG 0x1e
512#define AR8051_DEBUG_RGMII_CLK_DLY_REG 0x5
513#define AR8051_RGMII_TX_CLK_DLY 0x100
514
Tom Rini4021fd92013-07-18 15:13:01 -0400515 if (board_is_evm_sk(&header) || board_is_gp_evm(&header)) {
Tom Rini183943d2013-02-12 14:59:23 -0500516 const char *devname;
517 devname = miiphy_get_current_dev();
518
519 miiphy_write(devname, 0x0, AR8051_PHY_DEBUG_ADDR_REG,
520 AR8051_DEBUG_RGMII_CLK_DLY_REG);
521 miiphy_write(devname, 0x0, AR8051_PHY_DEBUG_DATA_REG,
522 AR8051_RGMII_TX_CLK_DLY);
523 }
Ilya Yanok44a2c072012-11-06 13:48:24 +0000524#endif
Ilya Yanok0760a0d2013-02-05 11:36:26 +0000525#if defined(CONFIG_USB_ETHER) && \
526 (!defined(CONFIG_SPL_BUILD) || defined(CONFIG_SPL_USBETH_SUPPORT))
527 if (is_valid_ether_addr(mac_addr))
528 eth_setenv_enetaddr("usbnet_devaddr", mac_addr);
529
Ilya Yanok44a2c072012-11-06 13:48:24 +0000530 rv = usb_eth_initialize(bis);
531 if (rv < 0)
532 printf("Error %d registering USB_ETHER\n", rv);
533 else
534 n += rv;
535#endif
536 return n;
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000537}
538#endif