blob: f56d17ec58e17a6532b5df649249b4038b475897 [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>
Tom Rini52437072013-08-30 16:28:46 -040029#include <power/tps65217.h>
30#include <power/tps65910.h>
Tom Rini303bfe82013-10-01 12:32:04 -040031#include <environment.h>
32#include <watchdog.h>
Tom Rini810b5812014-03-28 12:03:38 -040033#include <environment.h>
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000034#include "board.h"
35
36DECLARE_GLOBAL_DATA_PTR;
37
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000038/* GPIO that controls power to DDR on EVM-SK */
39#define GPIO_DDR_VTT_EN 7
40
Mugunthan V Ndf7a99f2015-09-07 14:22:18 +053041#if defined(CONFIG_SPL_BUILD) || \
42 (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_DM_ETH))
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000043static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
Mugunthan V Ndf7a99f2015-09-07 14:22:18 +053044#endif
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000045
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000046/*
47 * Read header information from EEPROM into global structure.
48 */
Tom Rini4021fd92013-07-18 15:13:01 -040049static int read_eeprom(struct am335x_baseboard_id *header)
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000050{
51 /* Check if baseboard eeprom is available */
52 if (i2c_probe(CONFIG_SYS_I2C_EEPROM_ADDR)) {
53 puts("Could not probe the EEPROM; something fundamentally "
54 "wrong on the I2C bus.\n");
55 return -ENODEV;
56 }
57
58 /* read the eeprom using i2c */
Tom Rini4021fd92013-07-18 15:13:01 -040059 if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0, 2, (uchar *)header,
60 sizeof(struct am335x_baseboard_id))) {
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000061 puts("Could not read the EEPROM; something fundamentally"
62 " wrong on the I2C bus.\n");
63 return -EIO;
64 }
65
Tom Rini4021fd92013-07-18 15:13:01 -040066 if (header->magic != 0xEE3355AA) {
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000067 /*
68 * read the eeprom using i2c again,
69 * but use only a 1 byte address
70 */
Tom Rini4021fd92013-07-18 15:13:01 -040071 if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0, 1, (uchar *)header,
72 sizeof(struct am335x_baseboard_id))) {
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000073 puts("Could not read the EEPROM; something "
74 "fundamentally wrong on the I2C bus.\n");
75 return -EIO;
76 }
77
Tom Rini4021fd92013-07-18 15:13:01 -040078 if (header->magic != 0xEE3355AA) {
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000079 printf("Incorrect magic number (0x%x) in EEPROM\n",
Tom Rini4021fd92013-07-18 15:13:01 -040080 header->magic);
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000081 return -EINVAL;
82 }
83 }
84
85 return 0;
86}
87
Tom Rini8de09df2014-04-09 08:25:57 -040088#ifndef CONFIG_SKIP_LOWLEVEL_INIT
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +000089static const struct ddr_data ddr2_data = {
Tom Rini7f50a572014-07-07 21:40:16 -040090 .datardsratio0 = MT47H128M16RT25E_RD_DQS,
91 .datafwsratio0 = MT47H128M16RT25E_PHY_FIFO_WE,
92 .datawrsratio0 = MT47H128M16RT25E_PHY_WR_DATA,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +000093};
94
95static const struct cmd_control ddr2_cmd_ctrl_data = {
Peter Korsgaard3adb8272012-10-18 01:21:13 +000096 .cmd0csratio = MT47H128M16RT25E_RATIO,
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000097
Peter Korsgaard3adb8272012-10-18 01:21:13 +000098 .cmd1csratio = MT47H128M16RT25E_RATIO,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +000099
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000100 .cmd2csratio = MT47H128M16RT25E_RATIO,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000101};
102
103static const struct emif_regs ddr2_emif_reg_data = {
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000104 .sdram_config = MT47H128M16RT25E_EMIF_SDCFG,
105 .ref_ctrl = MT47H128M16RT25E_EMIF_SDREF,
106 .sdram_tim1 = MT47H128M16RT25E_EMIF_TIM1,
107 .sdram_tim2 = MT47H128M16RT25E_EMIF_TIM2,
108 .sdram_tim3 = MT47H128M16RT25E_EMIF_TIM3,
109 .emif_ddr_phy_ctlr_1 = MT47H128M16RT25E_EMIF_READ_LATENCY,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000110};
111
112static const struct ddr_data ddr3_data = {
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000113 .datardsratio0 = MT41J128MJT125_RD_DQS,
114 .datawdsratio0 = MT41J128MJT125_WR_DQS,
115 .datafwsratio0 = MT41J128MJT125_PHY_FIFO_WE,
116 .datawrsratio0 = MT41J128MJT125_PHY_WR_DATA,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000117};
118
Tom Rini385bc752013-03-21 04:30:02 +0000119static const struct ddr_data ddr3_beagleblack_data = {
120 .datardsratio0 = MT41K256M16HA125E_RD_DQS,
121 .datawdsratio0 = MT41K256M16HA125E_WR_DQS,
122 .datafwsratio0 = MT41K256M16HA125E_PHY_FIFO_WE,
123 .datawrsratio0 = MT41K256M16HA125E_PHY_WR_DATA,
Tom Rini385bc752013-03-21 04:30:02 +0000124};
125
Jeff Lance7c03a222013-01-14 05:32:20 +0000126static const struct ddr_data ddr3_evm_data = {
127 .datardsratio0 = MT41J512M8RH125_RD_DQS,
128 .datawdsratio0 = MT41J512M8RH125_WR_DQS,
129 .datafwsratio0 = MT41J512M8RH125_PHY_FIFO_WE,
130 .datawrsratio0 = MT41J512M8RH125_PHY_WR_DATA,
Jeff Lance7c03a222013-01-14 05:32:20 +0000131};
132
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000133static const struct cmd_control ddr3_cmd_ctrl_data = {
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000134 .cmd0csratio = MT41J128MJT125_RATIO,
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000135 .cmd0iclkout = MT41J128MJT125_INVERT_CLKOUT,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000136
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000137 .cmd1csratio = MT41J128MJT125_RATIO,
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000138 .cmd1iclkout = MT41J128MJT125_INVERT_CLKOUT,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000139
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000140 .cmd2csratio = MT41J128MJT125_RATIO,
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000141 .cmd2iclkout = MT41J128MJT125_INVERT_CLKOUT,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000142};
143
Tom Rini385bc752013-03-21 04:30:02 +0000144static const struct cmd_control ddr3_beagleblack_cmd_ctrl_data = {
145 .cmd0csratio = MT41K256M16HA125E_RATIO,
Tom Rini385bc752013-03-21 04:30:02 +0000146 .cmd0iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
147
148 .cmd1csratio = MT41K256M16HA125E_RATIO,
Tom Rini385bc752013-03-21 04:30:02 +0000149 .cmd1iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
150
151 .cmd2csratio = MT41K256M16HA125E_RATIO,
Tom Rini385bc752013-03-21 04:30:02 +0000152 .cmd2iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
153};
154
Jeff Lance7c03a222013-01-14 05:32:20 +0000155static const struct cmd_control ddr3_evm_cmd_ctrl_data = {
156 .cmd0csratio = MT41J512M8RH125_RATIO,
Jeff Lance7c03a222013-01-14 05:32:20 +0000157 .cmd0iclkout = MT41J512M8RH125_INVERT_CLKOUT,
158
159 .cmd1csratio = MT41J512M8RH125_RATIO,
Jeff Lance7c03a222013-01-14 05:32:20 +0000160 .cmd1iclkout = MT41J512M8RH125_INVERT_CLKOUT,
161
162 .cmd2csratio = MT41J512M8RH125_RATIO,
Jeff Lance7c03a222013-01-14 05:32:20 +0000163 .cmd2iclkout = MT41J512M8RH125_INVERT_CLKOUT,
164};
165
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000166static struct emif_regs ddr3_emif_reg_data = {
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000167 .sdram_config = MT41J128MJT125_EMIF_SDCFG,
168 .ref_ctrl = MT41J128MJT125_EMIF_SDREF,
169 .sdram_tim1 = MT41J128MJT125_EMIF_TIM1,
170 .sdram_tim2 = MT41J128MJT125_EMIF_TIM2,
171 .sdram_tim3 = MT41J128MJT125_EMIF_TIM3,
172 .zq_config = MT41J128MJT125_ZQ_CFG,
Vaibhav Hiremathc30d57b2013-03-14 21:11:16 +0000173 .emif_ddr_phy_ctlr_1 = MT41J128MJT125_EMIF_READ_LATENCY |
174 PHY_EN_DYN_PWRDN,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000175};
Jeff Lance7c03a222013-01-14 05:32:20 +0000176
Tom Rini385bc752013-03-21 04:30:02 +0000177static struct emif_regs ddr3_beagleblack_emif_reg_data = {
178 .sdram_config = MT41K256M16HA125E_EMIF_SDCFG,
179 .ref_ctrl = MT41K256M16HA125E_EMIF_SDREF,
180 .sdram_tim1 = MT41K256M16HA125E_EMIF_TIM1,
181 .sdram_tim2 = MT41K256M16HA125E_EMIF_TIM2,
182 .sdram_tim3 = MT41K256M16HA125E_EMIF_TIM3,
183 .zq_config = MT41K256M16HA125E_ZQ_CFG,
184 .emif_ddr_phy_ctlr_1 = MT41K256M16HA125E_EMIF_READ_LATENCY,
185};
186
Jeff Lance7c03a222013-01-14 05:32:20 +0000187static struct emif_regs ddr3_evm_emif_reg_data = {
188 .sdram_config = MT41J512M8RH125_EMIF_SDCFG,
189 .ref_ctrl = MT41J512M8RH125_EMIF_SDREF,
190 .sdram_tim1 = MT41J512M8RH125_EMIF_TIM1,
191 .sdram_tim2 = MT41J512M8RH125_EMIF_TIM2,
192 .sdram_tim3 = MT41J512M8RH125_EMIF_TIM3,
193 .zq_config = MT41J512M8RH125_ZQ_CFG,
Vaibhav Hiremathc30d57b2013-03-14 21:11:16 +0000194 .emif_ddr_phy_ctlr_1 = MT41J512M8RH125_EMIF_READ_LATENCY |
195 PHY_EN_DYN_PWRDN,
Jeff Lance7c03a222013-01-14 05:32:20 +0000196};
Peter Korsgaardeb204db2013-05-13 08:36:30 +0000197
198#ifdef CONFIG_SPL_OS_BOOT
199int spl_start_uboot(void)
200{
201 /* break into full u-boot on 'c' */
Tom Rini810b5812014-03-28 12:03:38 -0400202 if (serial_tstc() && serial_getc() == 'c')
203 return 1;
204
205#ifdef CONFIG_SPL_ENV_SUPPORT
206 env_init();
207 env_relocate_spec();
208 if (getenv_yesno("boot_os") != 1)
209 return 1;
210#endif
211
212 return 0;
Peter Korsgaardeb204db2013-05-13 08:36:30 +0000213}
214#endif
215
Lokesh Vutla89a83bf2013-07-30 10:48:52 +0530216#define OSC (V_OSCK/1000000)
217const struct dpll_params dpll_ddr = {
218 266, OSC-1, 1, -1, -1, -1, -1};
219const struct dpll_params dpll_ddr_evm_sk = {
220 303, OSC-1, 1, -1, -1, -1, -1};
221const struct dpll_params dpll_ddr_bone_black = {
222 400, OSC-1, 1, -1, -1, -1, -1};
223
Tom Rini52437072013-08-30 16:28:46 -0400224void am33xx_spl_board_init(void)
225{
226 struct am335x_baseboard_id header;
Tom Rini52437072013-08-30 16:28:46 -0400227 int mpu_vdd;
228
229 if (read_eeprom(&header) < 0)
230 puts("Could not get board ID.\n");
231
232 /* Get the frequency */
Steve Kipisz5adac352013-08-14 10:51:31 -0400233 dpll_mpu_opp100.m = am335x_get_efuse_mpu_max_freq(cdev);
Tom Rini52437072013-08-30 16:28:46 -0400234
235 if (board_is_bone(&header) || board_is_bone_lt(&header)) {
236 /* BeagleBone PMIC Code */
237 int usb_cur_lim;
238
239 /*
240 * Only perform PMIC configurations if board rev > A1
241 * on Beaglebone White
242 */
243 if (board_is_bone(&header) && !strncmp(header.version,
244 "00A1", 4))
245 return;
246
247 if (i2c_probe(TPS65217_CHIP_PM))
248 return;
249
250 /*
251 * On Beaglebone White we need to ensure we have AC power
252 * before increasing the frequency.
253 */
254 if (board_is_bone(&header)) {
255 uchar pmic_status_reg;
256 if (tps65217_reg_read(TPS65217_STATUS,
257 &pmic_status_reg))
258 return;
259 if (!(pmic_status_reg & TPS65217_PWR_SRC_AC_BITMASK)) {
260 puts("No AC power, disabling frequency switch\n");
261 return;
262 }
263 }
264
265 /*
266 * Override what we have detected since we know if we have
267 * a Beaglebone Black it supports 1GHz.
268 */
269 if (board_is_bone_lt(&header))
Steve Kipisz5adac352013-08-14 10:51:31 -0400270 dpll_mpu_opp100.m = MPUPLL_M_1000;
Tom Rini52437072013-08-30 16:28:46 -0400271
272 /*
273 * Increase USB current limit to 1300mA or 1800mA and set
274 * the MPU voltage controller as needed.
275 */
Steve Kipisz5adac352013-08-14 10:51:31 -0400276 if (dpll_mpu_opp100.m == MPUPLL_M_1000) {
Tom Rini52437072013-08-30 16:28:46 -0400277 usb_cur_lim = TPS65217_USB_INPUT_CUR_LIMIT_1800MA;
278 mpu_vdd = TPS65217_DCDC_VOLT_SEL_1325MV;
279 } else {
280 usb_cur_lim = TPS65217_USB_INPUT_CUR_LIMIT_1300MA;
281 mpu_vdd = TPS65217_DCDC_VOLT_SEL_1275MV;
282 }
283
284 if (tps65217_reg_write(TPS65217_PROT_LEVEL_NONE,
285 TPS65217_POWER_PATH,
286 usb_cur_lim,
287 TPS65217_USB_INPUT_CUR_LIMIT_MASK))
288 puts("tps65217_reg_write failure\n");
289
Steve Kipisz5adac352013-08-14 10:51:31 -0400290 /* Set DCDC3 (CORE) voltage to 1.125V */
291 if (tps65217_voltage_update(TPS65217_DEFDCDC3,
292 TPS65217_DCDC_VOLT_SEL_1125MV)) {
293 puts("tps65217_voltage_update failure\n");
294 return;
295 }
296
297 /* Set CORE Frequencies to OPP100 */
298 do_setup_dpll(&dpll_core_regs, &dpll_core_opp100);
Tom Rini52437072013-08-30 16:28:46 -0400299
300 /* Set DCDC2 (MPU) voltage */
301 if (tps65217_voltage_update(TPS65217_DEFDCDC2, mpu_vdd)) {
302 puts("tps65217_voltage_update failure\n");
303 return;
304 }
305
306 /*
307 * Set LDO3, LDO4 output voltage to 3.3V for Beaglebone.
308 * Set LDO3 to 1.8V and LDO4 to 3.3V for Beaglebone Black.
309 */
310 if (board_is_bone(&header)) {
311 if (tps65217_reg_write(TPS65217_PROT_LEVEL_2,
312 TPS65217_DEFLS1,
313 TPS65217_LDO_VOLTAGE_OUT_3_3,
314 TPS65217_LDO_MASK))
315 puts("tps65217_reg_write failure\n");
316 } else {
317 if (tps65217_reg_write(TPS65217_PROT_LEVEL_2,
318 TPS65217_DEFLS1,
319 TPS65217_LDO_VOLTAGE_OUT_1_8,
320 TPS65217_LDO_MASK))
321 puts("tps65217_reg_write failure\n");
322 }
323
324 if (tps65217_reg_write(TPS65217_PROT_LEVEL_2,
325 TPS65217_DEFLS2,
326 TPS65217_LDO_VOLTAGE_OUT_3_3,
327 TPS65217_LDO_MASK))
328 puts("tps65217_reg_write failure\n");
329 } else {
330 int sil_rev;
331
332 /*
333 * The GP EVM, IDK and EVM SK use a TPS65910 PMIC. For all
334 * MPU frequencies we support we use a CORE voltage of
335 * 1.1375V. For MPU voltage we need to switch based on
336 * the frequency we are running at.
337 */
338 if (i2c_probe(TPS65910_CTRL_I2C_ADDR))
339 return;
340
341 /*
342 * Depending on MPU clock and PG we will need a different
343 * VDD to drive at that speed.
344 */
345 sil_rev = readl(&cdev->deviceid) >> 28;
Steve Kipisz5adac352013-08-14 10:51:31 -0400346 mpu_vdd = am335x_get_tps65910_mpu_vdd(sil_rev,
347 dpll_mpu_opp100.m);
Tom Rini52437072013-08-30 16:28:46 -0400348
349 /* Tell the TPS65910 to use i2c */
350 tps65910_set_i2c_control();
351
352 /* First update MPU voltage. */
353 if (tps65910_voltage_update(MPU, mpu_vdd))
354 return;
355
356 /* Second, update the CORE voltage. */
357 if (tps65910_voltage_update(CORE, TPS65910_OP_REG_SEL_1_1_3))
358 return;
Steve Kipisz5adac352013-08-14 10:51:31 -0400359
360 /* Set CORE Frequencies to OPP100 */
361 do_setup_dpll(&dpll_core_regs, &dpll_core_opp100);
Tom Rini52437072013-08-30 16:28:46 -0400362 }
363
364 /* Set MPU Frequency to what we detected now that voltages are set */
Steve Kipisz5adac352013-08-14 10:51:31 -0400365 do_setup_dpll(&dpll_mpu_regs, &dpll_mpu_opp100);
Tom Rini52437072013-08-30 16:28:46 -0400366}
367
Lokesh Vutla89a83bf2013-07-30 10:48:52 +0530368const struct dpll_params *get_dpll_ddr_params(void)
369{
370 struct am335x_baseboard_id header;
371
372 enable_i2c0_pin_mux();
Heiko Schocherf53f2b82013-10-22 11:03:18 +0200373 i2c_init(CONFIG_SYS_OMAP24_I2C_SPEED, CONFIG_SYS_OMAP24_I2C_SLAVE);
Lokesh Vutla89a83bf2013-07-30 10:48:52 +0530374 if (read_eeprom(&header) < 0)
375 puts("Could not get board ID.\n");
376
377 if (board_is_evm_sk(&header))
378 return &dpll_ddr_evm_sk;
379 else if (board_is_bone_lt(&header))
380 return &dpll_ddr_bone_black;
381 else if (board_is_evm_15_or_later(&header))
382 return &dpll_ddr_evm_sk;
383 else
384 return &dpll_ddr;
385}
386
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530387void set_uart_mux_conf(void)
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000388{
Tom Rini986d7552014-08-01 09:53:24 -0400389#if CONFIG_CONS_INDEX == 1
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000390 enable_uart0_pin_mux();
Tom Rini986d7552014-08-01 09:53:24 -0400391#elif CONFIG_CONS_INDEX == 2
Andrew Bradford65c51ff2012-10-25 08:21:30 -0400392 enable_uart1_pin_mux();
Tom Rini986d7552014-08-01 09:53:24 -0400393#elif CONFIG_CONS_INDEX == 3
Andrew Bradford65c51ff2012-10-25 08:21:30 -0400394 enable_uart2_pin_mux();
Tom Rini986d7552014-08-01 09:53:24 -0400395#elif CONFIG_CONS_INDEX == 4
Andrew Bradford65c51ff2012-10-25 08:21:30 -0400396 enable_uart3_pin_mux();
Tom Rini986d7552014-08-01 09:53:24 -0400397#elif CONFIG_CONS_INDEX == 5
Andrew Bradford65c51ff2012-10-25 08:21:30 -0400398 enable_uart4_pin_mux();
Tom Rini986d7552014-08-01 09:53:24 -0400399#elif CONFIG_CONS_INDEX == 6
Andrew Bradford65c51ff2012-10-25 08:21:30 -0400400 enable_uart5_pin_mux();
Tom Rini986d7552014-08-01 09:53:24 -0400401#endif
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530402}
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000403
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530404void set_mux_conf_regs(void)
405{
406 __maybe_unused struct am335x_baseboard_id header;
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000407
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530408 if (read_eeprom(&header) < 0)
409 puts("Could not get board ID.\n");
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000410
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530411 enable_board_pin_mux(&header);
412}
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000413
Lokesh Vutla303b2672013-12-10 15:02:21 +0530414const struct ctrl_ioregs ioregs_evmsk = {
415 .cm0ioctl = MT41J128MJT125_IOCTRL_VALUE,
416 .cm1ioctl = MT41J128MJT125_IOCTRL_VALUE,
417 .cm2ioctl = MT41J128MJT125_IOCTRL_VALUE,
418 .dt0ioctl = MT41J128MJT125_IOCTRL_VALUE,
419 .dt1ioctl = MT41J128MJT125_IOCTRL_VALUE,
420};
421
422const struct ctrl_ioregs ioregs_bonelt = {
423 .cm0ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
424 .cm1ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
425 .cm2ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
426 .dt0ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
427 .dt1ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
428};
429
430const struct ctrl_ioregs ioregs_evm15 = {
431 .cm0ioctl = MT41J512M8RH125_IOCTRL_VALUE,
432 .cm1ioctl = MT41J512M8RH125_IOCTRL_VALUE,
433 .cm2ioctl = MT41J512M8RH125_IOCTRL_VALUE,
434 .dt0ioctl = MT41J512M8RH125_IOCTRL_VALUE,
435 .dt1ioctl = MT41J512M8RH125_IOCTRL_VALUE,
436};
437
438const struct ctrl_ioregs ioregs = {
439 .cm0ioctl = MT47H128M16RT25E_IOCTRL_VALUE,
440 .cm1ioctl = MT47H128M16RT25E_IOCTRL_VALUE,
441 .cm2ioctl = MT47H128M16RT25E_IOCTRL_VALUE,
442 .dt0ioctl = MT47H128M16RT25E_IOCTRL_VALUE,
443 .dt1ioctl = MT47H128M16RT25E_IOCTRL_VALUE,
444};
445
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530446void sdram_init(void)
447{
448 __maybe_unused struct am335x_baseboard_id header;
Lokesh Vutlab1b6fba2013-07-30 10:48:53 +0530449
Tom Rini4021fd92013-07-18 15:13:01 -0400450 if (read_eeprom(&header) < 0)
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000451 puts("Could not get board ID.\n");
452
Tom Rini4021fd92013-07-18 15:13:01 -0400453 if (board_is_evm_sk(&header)) {
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000454 /*
455 * EVM SK 1.2A and later use gpio0_7 to enable DDR3.
456 * This is safe enough to do on older revs.
457 */
458 gpio_request(GPIO_DDR_VTT_EN, "ddr_vtt_en");
459 gpio_direction_output(GPIO_DDR_VTT_EN, 1);
460 }
461
Tom Rini4021fd92013-07-18 15:13:01 -0400462 if (board_is_evm_sk(&header))
Lokesh Vutla303b2672013-12-10 15:02:21 +0530463 config_ddr(303, &ioregs_evmsk, &ddr3_data,
Matt Porter65991ec2013-03-15 10:07:03 +0000464 &ddr3_cmd_ctrl_data, &ddr3_emif_reg_data, 0);
Tom Rini4021fd92013-07-18 15:13:01 -0400465 else if (board_is_bone_lt(&header))
Lokesh Vutla303b2672013-12-10 15:02:21 +0530466 config_ddr(400, &ioregs_bonelt,
Tom Rini385bc752013-03-21 04:30:02 +0000467 &ddr3_beagleblack_data,
468 &ddr3_beagleblack_cmd_ctrl_data,
469 &ddr3_beagleblack_emif_reg_data, 0);
Tom Rini4021fd92013-07-18 15:13:01 -0400470 else if (board_is_evm_15_or_later(&header))
Lokesh Vutla303b2672013-12-10 15:02:21 +0530471 config_ddr(303, &ioregs_evm15, &ddr3_evm_data,
Matt Porter65991ec2013-03-15 10:07:03 +0000472 &ddr3_evm_cmd_ctrl_data, &ddr3_evm_emif_reg_data, 0);
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000473 else
Lokesh Vutla303b2672013-12-10 15:02:21 +0530474 config_ddr(266, &ioregs, &ddr2_data,
Matt Porter65991ec2013-03-15 10:07:03 +0000475 &ddr2_cmd_ctrl_data, &ddr2_emif_reg_data, 0);
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000476}
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530477#endif
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000478
479/*
480 * Basic board specific setup. Pinmux has been handled already.
481 */
482int board_init(void)
483{
Tom Rini303bfe82013-10-01 12:32:04 -0400484#if defined(CONFIG_HW_WATCHDOG)
485 hw_watchdog_init();
486#endif
487
Tom Rinif3b6a1d2013-08-09 11:22:13 -0400488 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
pekon gupta53b4b322013-11-18 19:03:02 +0530489#if defined(CONFIG_NOR) || defined(CONFIG_NAND)
Ilya Yanok3d9725e2012-11-06 13:06:31 +0000490 gpmc_init();
Steve Kipiszbe9b6f82013-07-18 15:13:03 -0400491#endif
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000492 return 0;
493}
494
Tom Rini40271852012-10-24 07:28:17 +0000495#ifdef CONFIG_BOARD_LATE_INIT
496int board_late_init(void)
497{
498#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
499 char safe_string[HDR_NAME_LEN + 1];
Tom Rini4021fd92013-07-18 15:13:01 -0400500 struct am335x_baseboard_id header;
501
502 if (read_eeprom(&header) < 0)
503 puts("Could not get board ID.\n");
Tom Rini40271852012-10-24 07:28:17 +0000504
505 /* Now set variables based on the header. */
506 strncpy(safe_string, (char *)header.name, sizeof(header.name));
507 safe_string[sizeof(header.name)] = 0;
508 setenv("board_name", safe_string);
509
robertcnelson@gmail.com7fea2102015-11-11 09:10:52 -0600510 /* BeagleBone Green eeprom, board_rev: 0x1a 0x00 0x00 0x00 */
511 if ( (header.version[0] == 0x1a) && (header.version[1] == 0x00) &&
512 (header.version[2] == 0x00) && (header.version[3] == 0x00) ) {
513 setenv("board_rev", "BBG1");
514 } else {
515 strncpy(safe_string, (char *)header.version, sizeof(header.version));
516 safe_string[sizeof(header.version)] = 0;
517 setenv("board_rev", safe_string);
518 }
Tom Rini40271852012-10-24 07:28:17 +0000519#endif
520
521 return 0;
522}
523#endif
524
Mugunthan V Ndf7a99f2015-09-07 14:22:18 +0530525#ifndef CONFIG_DM_ETH
526
Ilya Yanok0760a0d2013-02-05 11:36:26 +0000527#if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) || \
528 (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD))
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000529static void cpsw_control(int enabled)
530{
531 /* VTP can be added here */
532
533 return;
534}
535
536static struct cpsw_slave_data cpsw_slaves[] = {
537 {
538 .slave_reg_ofs = 0x208,
539 .sliver_reg_ofs = 0xd80,
Mugunthan V N4944f372014-02-18 07:31:52 -0500540 .phy_addr = 0,
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000541 },
542 {
543 .slave_reg_ofs = 0x308,
544 .sliver_reg_ofs = 0xdc0,
Mugunthan V N4944f372014-02-18 07:31:52 -0500545 .phy_addr = 1,
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000546 },
547};
548
549static struct cpsw_platform_data cpsw_data = {
Matt Portere24646f2013-03-15 10:07:02 +0000550 .mdio_base = CPSW_MDIO_BASE,
551 .cpsw_base = CPSW_BASE,
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000552 .mdio_div = 0xff,
553 .channels = 8,
554 .cpdma_reg_ofs = 0x800,
555 .slaves = 1,
556 .slave_data = cpsw_slaves,
557 .ale_reg_ofs = 0xd00,
558 .ale_entries = 1024,
559 .host_port_reg_ofs = 0x108,
560 .hw_stats_reg_ofs = 0x900,
Mugunthan V Nff559872013-07-08 16:04:37 +0530561 .bd_ram_ofs = 0x2000,
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000562 .mac_control = (1 << 5),
563 .control = cpsw_control,
564 .host_port_num = 0,
565 .version = CPSW_CTRL_VERSION_2,
566};
Ilya Yanok44a2c072012-11-06 13:48:24 +0000567#endif
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000568
Tom Rini60fcaaa2014-03-26 15:53:12 -0400569/*
570 * This function will:
571 * Read the eFuse for MAC addresses, and set ethaddr/eth1addr/usbnet_devaddr
572 * in the environment
573 * Perform fixups to the PHY present on certain boards. We only need this
574 * function in:
575 * - SPL with either CPSW or USB ethernet support
576 * - Full U-Boot, with either CPSW or USB ethernet
577 * Build in only these cases to avoid warnings about unused variables
578 * when we build an SPL that has neither option but full U-Boot will.
579 */
580#if ((defined(CONFIG_SPL_ETH_SUPPORT) || defined(CONFIG_SPL_USBETH_SUPPORT)) \
581 && defined(CONFIG_SPL_BUILD)) || \
582 ((defined(CONFIG_DRIVER_TI_CPSW) || \
Paul Kocialkowskif34dfcb2015-08-04 17:04:06 +0200583 defined(CONFIG_USB_ETHER) && defined(CONFIG_USB_MUSB_GADGET)) && \
Tom Rini60fcaaa2014-03-26 15:53:12 -0400584 !defined(CONFIG_SPL_BUILD))
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000585int board_eth_init(bd_t *bis)
586{
Ilya Yanok44a2c072012-11-06 13:48:24 +0000587 int rv, n = 0;
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000588 uint8_t mac_addr[6];
589 uint32_t mac_hi, mac_lo;
Tom Rini4021fd92013-07-18 15:13:01 -0400590 __maybe_unused struct am335x_baseboard_id header;
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000591
Ilya Yanok0760a0d2013-02-05 11:36:26 +0000592 /* try reading mac address from efuse */
593 mac_lo = readl(&cdev->macid0l);
594 mac_hi = readl(&cdev->macid0h);
595 mac_addr[0] = mac_hi & 0xFF;
596 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
597 mac_addr[2] = (mac_hi & 0xFF0000) >> 16;
598 mac_addr[3] = (mac_hi & 0xFF000000) >> 24;
599 mac_addr[4] = mac_lo & 0xFF;
600 mac_addr[5] = (mac_lo & 0xFF00) >> 8;
601
602#if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) || \
603 (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD))
604 if (!getenv("ethaddr")) {
605 printf("<ethaddr> not set. Validating first E-fuse MAC\n");
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000606
Joe Hershberger8ecdbed2015-04-08 01:41:04 -0500607 if (is_valid_ethaddr(mac_addr))
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000608 eth_setenv_enetaddr("ethaddr", mac_addr);
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000609 }
610
Joel A Fernandesf7488542013-05-07 05:52:55 +0000611#ifdef CONFIG_DRIVER_TI_CPSW
Mugunthan V N0c1d8562014-02-18 07:31:55 -0500612
613 mac_lo = readl(&cdev->macid1l);
614 mac_hi = readl(&cdev->macid1h);
615 mac_addr[0] = mac_hi & 0xFF;
616 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
617 mac_addr[2] = (mac_hi & 0xFF0000) >> 16;
618 mac_addr[3] = (mac_hi & 0xFF000000) >> 24;
619 mac_addr[4] = mac_lo & 0xFF;
620 mac_addr[5] = (mac_lo & 0xFF00) >> 8;
621
622 if (!getenv("eth1addr")) {
Joe Hershberger8ecdbed2015-04-08 01:41:04 -0500623 if (is_valid_ethaddr(mac_addr))
Mugunthan V N0c1d8562014-02-18 07:31:55 -0500624 eth_setenv_enetaddr("eth1addr", mac_addr);
625 }
626
Tom Rini4021fd92013-07-18 15:13:01 -0400627 if (read_eeprom(&header) < 0)
628 puts("Could not get board ID.\n");
629
630 if (board_is_bone(&header) || board_is_bone_lt(&header) ||
631 board_is_idk(&header)) {
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000632 writel(MII_MODE_ENABLE, &cdev->miisel);
633 cpsw_slaves[0].phy_if = cpsw_slaves[1].phy_if =
634 PHY_INTERFACE_MODE_MII;
635 } else {
Heiko Schocherc4fea292013-08-19 16:38:56 +0200636 writel((RGMII_MODE_ENABLE | RGMII_INT_DELAY), &cdev->miisel);
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000637 cpsw_slaves[0].phy_if = cpsw_slaves[1].phy_if =
638 PHY_INTERFACE_MODE_RGMII;
639 }
640
Ilya Yanok44a2c072012-11-06 13:48:24 +0000641 rv = cpsw_register(&cpsw_data);
642 if (rv < 0)
643 printf("Error %d registering CPSW switch\n", rv);
644 else
645 n += rv;
Joel A Fernandesf7488542013-05-07 05:52:55 +0000646#endif
Tom Rini183943d2013-02-12 14:59:23 -0500647
648 /*
649 *
650 * CPSW RGMII Internal Delay Mode is not supported in all PVT
651 * operating points. So we must set the TX clock delay feature
652 * in the AR8051 PHY. Since we only support a single ethernet
653 * device in U-Boot, we only do this for the first instance.
654 */
655#define AR8051_PHY_DEBUG_ADDR_REG 0x1d
656#define AR8051_PHY_DEBUG_DATA_REG 0x1e
657#define AR8051_DEBUG_RGMII_CLK_DLY_REG 0x5
658#define AR8051_RGMII_TX_CLK_DLY 0x100
659
Tom Rini4021fd92013-07-18 15:13:01 -0400660 if (board_is_evm_sk(&header) || board_is_gp_evm(&header)) {
Tom Rini183943d2013-02-12 14:59:23 -0500661 const char *devname;
662 devname = miiphy_get_current_dev();
663
664 miiphy_write(devname, 0x0, AR8051_PHY_DEBUG_ADDR_REG,
665 AR8051_DEBUG_RGMII_CLK_DLY_REG);
666 miiphy_write(devname, 0x0, AR8051_PHY_DEBUG_DATA_REG,
667 AR8051_RGMII_TX_CLK_DLY);
668 }
Ilya Yanok44a2c072012-11-06 13:48:24 +0000669#endif
Ilya Yanok0760a0d2013-02-05 11:36:26 +0000670#if defined(CONFIG_USB_ETHER) && \
671 (!defined(CONFIG_SPL_BUILD) || defined(CONFIG_SPL_USBETH_SUPPORT))
Joe Hershberger8ecdbed2015-04-08 01:41:04 -0500672 if (is_valid_ethaddr(mac_addr))
Ilya Yanok0760a0d2013-02-05 11:36:26 +0000673 eth_setenv_enetaddr("usbnet_devaddr", mac_addr);
674
Ilya Yanok44a2c072012-11-06 13:48:24 +0000675 rv = usb_eth_initialize(bis);
676 if (rv < 0)
677 printf("Error %d registering USB_ETHER\n", rv);
678 else
679 n += rv;
680#endif
681 return n;
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000682}
683#endif
Mugunthan V Ndf7a99f2015-09-07 14:22:18 +0530684
685#endif /* CONFIG_DM_ETH */