blob: 080b9e8de2ac7f4e7f16b3972964f207b6bf8f7e [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>
Lokesh Vutlaabb44e62016-05-16 11:47:29 +053014#include <serial.h>
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000015#include <asm/arch/cpu.h>
16#include <asm/arch/hardware.h>
17#include <asm/arch/omap.h>
18#include <asm/arch/ddr_defs.h>
19#include <asm/arch/clock.h>
Lokesh Vutla0d144f52016-05-16 11:47:26 +053020#include <asm/arch/clk_synthesizer.h>
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000021#include <asm/arch/gpio.h>
22#include <asm/arch/mmc_host_def.h>
23#include <asm/arch/sys_proto.h>
Steve Kipiszbe9b6f82013-07-18 15:13:03 -040024#include <asm/arch/mem.h>
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000025#include <asm/io.h>
26#include <asm/emif.h>
27#include <asm/gpio.h>
Andrew F. Davisbd249152016-08-30 14:06:24 -050028#include <asm/omap_sec_common.h>
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000029#include <i2c.h>
30#include <miiphy.h>
31#include <cpsw.h>
Tom Rini52437072013-08-30 16:28:46 -040032#include <power/tps65217.h>
33#include <power/tps65910.h>
Tom Rini303bfe82013-10-01 12:32:04 -040034#include <environment.h>
35#include <watchdog.h>
Tom Rini810b5812014-03-28 12:03:38 -040036#include <environment.h>
Nishanth Menon2afa70d2016-02-24 12:30:55 -060037#include "../common/board_detect.h"
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000038#include "board.h"
39
40DECLARE_GLOBAL_DATA_PTR;
41
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000042/* GPIO that controls power to DDR on EVM-SK */
Lokesh Vutla0d144f52016-05-16 11:47:26 +053043#define GPIO_TO_PIN(bank, gpio) (32 * (bank) + (gpio))
44#define GPIO_DDR_VTT_EN GPIO_TO_PIN(0, 7)
45#define ICE_GPIO_DDR_VTT_EN GPIO_TO_PIN(0, 18)
46#define GPIO_PR1_MII_CTRL GPIO_TO_PIN(3, 4)
47#define GPIO_MUX_MII_CTRL GPIO_TO_PIN(3, 10)
48#define GPIO_FET_SWITCH_CTRL GPIO_TO_PIN(0, 7)
49#define GPIO_PHY_RESET GPIO_TO_PIN(2, 5)
Roger Quadrosbcb4ee82016-08-24 15:35:50 +030050#define GPIO_ETH0_MODE GPIO_TO_PIN(0, 11)
51#define GPIO_ETH1_MODE GPIO_TO_PIN(1, 26)
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000052
Mugunthan V Ndf7a99f2015-09-07 14:22:18 +053053#if defined(CONFIG_SPL_BUILD) || \
54 (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_DM_ETH))
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000055static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
Mugunthan V Ndf7a99f2015-09-07 14:22:18 +053056#endif
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000057
Roger Quadrosbcb4ee82016-08-24 15:35:50 +030058#define GPIO0_RISINGDETECT (AM33XX_GPIO0_BASE + OMAP_GPIO_RISINGDETECT)
59#define GPIO1_RISINGDETECT (AM33XX_GPIO1_BASE + OMAP_GPIO_RISINGDETECT)
60
61#define GPIO0_IRQSTATUS1 (AM33XX_GPIO0_BASE + OMAP_GPIO_IRQSTATUS1)
62#define GPIO1_IRQSTATUS1 (AM33XX_GPIO1_BASE + OMAP_GPIO_IRQSTATUS1)
63
64#define GPIO0_IRQSTATUSRAW (AM33XX_GPIO0_BASE + 0x024)
65#define GPIO1_IRQSTATUSRAW (AM33XX_GPIO1_BASE + 0x024)
66
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000067/*
68 * Read header information from EEPROM into global structure.
69 */
Nishanth Menon2afa70d2016-02-24 12:30:55 -060070static inline int __maybe_unused read_eeprom(void)
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000071{
Nishanth Menon2afa70d2016-02-24 12:30:55 -060072 return ti_i2c_eeprom_am_get(-1, CONFIG_SYS_I2C_EEPROM_ADDR);
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000073}
74
Lokesh Vutlaabb44e62016-05-16 11:47:29 +053075#ifndef CONFIG_DM_SERIAL
76struct serial_device *default_serial_console(void)
77{
78 if (board_is_icev2())
79 return &eserial4_device;
80 else
81 return &eserial1_device;
82}
83#endif
84
Tom Rini8de09df2014-04-09 08:25:57 -040085#ifndef CONFIG_SKIP_LOWLEVEL_INIT
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +000086static const struct ddr_data ddr2_data = {
Tom Rini7f50a572014-07-07 21:40:16 -040087 .datardsratio0 = MT47H128M16RT25E_RD_DQS,
88 .datafwsratio0 = MT47H128M16RT25E_PHY_FIFO_WE,
89 .datawrsratio0 = MT47H128M16RT25E_PHY_WR_DATA,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +000090};
91
92static const struct cmd_control ddr2_cmd_ctrl_data = {
Peter Korsgaard3adb8272012-10-18 01:21:13 +000093 .cmd0csratio = MT47H128M16RT25E_RATIO,
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000094
Peter Korsgaard3adb8272012-10-18 01:21:13 +000095 .cmd1csratio = MT47H128M16RT25E_RATIO,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +000096
Peter Korsgaard3adb8272012-10-18 01:21:13 +000097 .cmd2csratio = MT47H128M16RT25E_RATIO,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +000098};
99
100static const struct emif_regs ddr2_emif_reg_data = {
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000101 .sdram_config = MT47H128M16RT25E_EMIF_SDCFG,
102 .ref_ctrl = MT47H128M16RT25E_EMIF_SDREF,
103 .sdram_tim1 = MT47H128M16RT25E_EMIF_TIM1,
104 .sdram_tim2 = MT47H128M16RT25E_EMIF_TIM2,
105 .sdram_tim3 = MT47H128M16RT25E_EMIF_TIM3,
106 .emif_ddr_phy_ctlr_1 = MT47H128M16RT25E_EMIF_READ_LATENCY,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000107};
108
109static const struct ddr_data ddr3_data = {
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000110 .datardsratio0 = MT41J128MJT125_RD_DQS,
111 .datawdsratio0 = MT41J128MJT125_WR_DQS,
112 .datafwsratio0 = MT41J128MJT125_PHY_FIFO_WE,
113 .datawrsratio0 = MT41J128MJT125_PHY_WR_DATA,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000114};
115
Tom Rini385bc752013-03-21 04:30:02 +0000116static const struct ddr_data ddr3_beagleblack_data = {
117 .datardsratio0 = MT41K256M16HA125E_RD_DQS,
118 .datawdsratio0 = MT41K256M16HA125E_WR_DQS,
119 .datafwsratio0 = MT41K256M16HA125E_PHY_FIFO_WE,
120 .datawrsratio0 = MT41K256M16HA125E_PHY_WR_DATA,
Tom Rini385bc752013-03-21 04:30:02 +0000121};
122
Jeff Lance7c03a222013-01-14 05:32:20 +0000123static const struct ddr_data ddr3_evm_data = {
124 .datardsratio0 = MT41J512M8RH125_RD_DQS,
125 .datawdsratio0 = MT41J512M8RH125_WR_DQS,
126 .datafwsratio0 = MT41J512M8RH125_PHY_FIFO_WE,
127 .datawrsratio0 = MT41J512M8RH125_PHY_WR_DATA,
Jeff Lance7c03a222013-01-14 05:32:20 +0000128};
129
Lokesh Vutla5837b902016-05-16 11:47:24 +0530130static const struct ddr_data ddr3_icev2_data = {
131 .datardsratio0 = MT41J128MJT125_RD_DQS_400MHz,
132 .datawdsratio0 = MT41J128MJT125_WR_DQS_400MHz,
133 .datafwsratio0 = MT41J128MJT125_PHY_FIFO_WE_400MHz,
134 .datawrsratio0 = MT41J128MJT125_PHY_WR_DATA_400MHz,
135};
136
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000137static const struct cmd_control ddr3_cmd_ctrl_data = {
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000138 .cmd0csratio = MT41J128MJT125_RATIO,
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000139 .cmd0iclkout = MT41J128MJT125_INVERT_CLKOUT,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000140
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000141 .cmd1csratio = MT41J128MJT125_RATIO,
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000142 .cmd1iclkout = MT41J128MJT125_INVERT_CLKOUT,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000143
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000144 .cmd2csratio = MT41J128MJT125_RATIO,
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000145 .cmd2iclkout = MT41J128MJT125_INVERT_CLKOUT,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000146};
147
Tom Rini385bc752013-03-21 04:30:02 +0000148static const struct cmd_control ddr3_beagleblack_cmd_ctrl_data = {
149 .cmd0csratio = MT41K256M16HA125E_RATIO,
Tom Rini385bc752013-03-21 04:30:02 +0000150 .cmd0iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
151
152 .cmd1csratio = MT41K256M16HA125E_RATIO,
Tom Rini385bc752013-03-21 04:30:02 +0000153 .cmd1iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
154
155 .cmd2csratio = MT41K256M16HA125E_RATIO,
Tom Rini385bc752013-03-21 04:30:02 +0000156 .cmd2iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
157};
158
Jeff Lance7c03a222013-01-14 05:32:20 +0000159static const struct cmd_control ddr3_evm_cmd_ctrl_data = {
160 .cmd0csratio = MT41J512M8RH125_RATIO,
Jeff Lance7c03a222013-01-14 05:32:20 +0000161 .cmd0iclkout = MT41J512M8RH125_INVERT_CLKOUT,
162
163 .cmd1csratio = MT41J512M8RH125_RATIO,
Jeff Lance7c03a222013-01-14 05:32:20 +0000164 .cmd1iclkout = MT41J512M8RH125_INVERT_CLKOUT,
165
166 .cmd2csratio = MT41J512M8RH125_RATIO,
Jeff Lance7c03a222013-01-14 05:32:20 +0000167 .cmd2iclkout = MT41J512M8RH125_INVERT_CLKOUT,
168};
169
Lokesh Vutla5837b902016-05-16 11:47:24 +0530170static const struct cmd_control ddr3_icev2_cmd_ctrl_data = {
171 .cmd0csratio = MT41J128MJT125_RATIO_400MHz,
172 .cmd0iclkout = MT41J128MJT125_INVERT_CLKOUT_400MHz,
173
174 .cmd1csratio = MT41J128MJT125_RATIO_400MHz,
175 .cmd1iclkout = MT41J128MJT125_INVERT_CLKOUT_400MHz,
176
177 .cmd2csratio = MT41J128MJT125_RATIO_400MHz,
178 .cmd2iclkout = MT41J128MJT125_INVERT_CLKOUT_400MHz,
179};
180
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000181static struct emif_regs ddr3_emif_reg_data = {
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000182 .sdram_config = MT41J128MJT125_EMIF_SDCFG,
183 .ref_ctrl = MT41J128MJT125_EMIF_SDREF,
184 .sdram_tim1 = MT41J128MJT125_EMIF_TIM1,
185 .sdram_tim2 = MT41J128MJT125_EMIF_TIM2,
186 .sdram_tim3 = MT41J128MJT125_EMIF_TIM3,
187 .zq_config = MT41J128MJT125_ZQ_CFG,
Vaibhav Hiremathc30d57b2013-03-14 21:11:16 +0000188 .emif_ddr_phy_ctlr_1 = MT41J128MJT125_EMIF_READ_LATENCY |
189 PHY_EN_DYN_PWRDN,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000190};
Jeff Lance7c03a222013-01-14 05:32:20 +0000191
Tom Rini385bc752013-03-21 04:30:02 +0000192static struct emif_regs ddr3_beagleblack_emif_reg_data = {
193 .sdram_config = MT41K256M16HA125E_EMIF_SDCFG,
194 .ref_ctrl = MT41K256M16HA125E_EMIF_SDREF,
195 .sdram_tim1 = MT41K256M16HA125E_EMIF_TIM1,
196 .sdram_tim2 = MT41K256M16HA125E_EMIF_TIM2,
197 .sdram_tim3 = MT41K256M16HA125E_EMIF_TIM3,
198 .zq_config = MT41K256M16HA125E_ZQ_CFG,
199 .emif_ddr_phy_ctlr_1 = MT41K256M16HA125E_EMIF_READ_LATENCY,
200};
201
Jeff Lance7c03a222013-01-14 05:32:20 +0000202static struct emif_regs ddr3_evm_emif_reg_data = {
203 .sdram_config = MT41J512M8RH125_EMIF_SDCFG,
204 .ref_ctrl = MT41J512M8RH125_EMIF_SDREF,
205 .sdram_tim1 = MT41J512M8RH125_EMIF_TIM1,
206 .sdram_tim2 = MT41J512M8RH125_EMIF_TIM2,
207 .sdram_tim3 = MT41J512M8RH125_EMIF_TIM3,
208 .zq_config = MT41J512M8RH125_ZQ_CFG,
Vaibhav Hiremathc30d57b2013-03-14 21:11:16 +0000209 .emif_ddr_phy_ctlr_1 = MT41J512M8RH125_EMIF_READ_LATENCY |
210 PHY_EN_DYN_PWRDN,
Jeff Lance7c03a222013-01-14 05:32:20 +0000211};
Peter Korsgaardeb204db2013-05-13 08:36:30 +0000212
Lokesh Vutla5837b902016-05-16 11:47:24 +0530213static struct emif_regs ddr3_icev2_emif_reg_data = {
214 .sdram_config = MT41J128MJT125_EMIF_SDCFG_400MHz,
215 .ref_ctrl = MT41J128MJT125_EMIF_SDREF_400MHz,
216 .sdram_tim1 = MT41J128MJT125_EMIF_TIM1_400MHz,
217 .sdram_tim2 = MT41J128MJT125_EMIF_TIM2_400MHz,
218 .sdram_tim3 = MT41J128MJT125_EMIF_TIM3_400MHz,
219 .zq_config = MT41J128MJT125_ZQ_CFG_400MHz,
220 .emif_ddr_phy_ctlr_1 = MT41J128MJT125_EMIF_READ_LATENCY_400MHz |
221 PHY_EN_DYN_PWRDN,
222};
223
Peter Korsgaardeb204db2013-05-13 08:36:30 +0000224#ifdef CONFIG_SPL_OS_BOOT
225int spl_start_uboot(void)
226{
227 /* break into full u-boot on 'c' */
Tom Rini810b5812014-03-28 12:03:38 -0400228 if (serial_tstc() && serial_getc() == 'c')
229 return 1;
230
231#ifdef CONFIG_SPL_ENV_SUPPORT
232 env_init();
233 env_relocate_spec();
234 if (getenv_yesno("boot_os") != 1)
235 return 1;
236#endif
237
238 return 0;
Peter Korsgaardeb204db2013-05-13 08:36:30 +0000239}
240#endif
241
Lokesh Vutla89a83bf2013-07-30 10:48:52 +0530242#define OSC (V_OSCK/1000000)
243const struct dpll_params dpll_ddr = {
244 266, OSC-1, 1, -1, -1, -1, -1};
245const struct dpll_params dpll_ddr_evm_sk = {
246 303, OSC-1, 1, -1, -1, -1, -1};
247const struct dpll_params dpll_ddr_bone_black = {
248 400, OSC-1, 1, -1, -1, -1, -1};
249
Tom Rini52437072013-08-30 16:28:46 -0400250void am33xx_spl_board_init(void)
251{
Tom Rini52437072013-08-30 16:28:46 -0400252 int mpu_vdd;
253
Nishanth Menon2afa70d2016-02-24 12:30:55 -0600254 if (read_eeprom() < 0)
Tom Rini52437072013-08-30 16:28:46 -0400255 puts("Could not get board ID.\n");
256
257 /* Get the frequency */
Steve Kipisz5adac352013-08-14 10:51:31 -0400258 dpll_mpu_opp100.m = am335x_get_efuse_mpu_max_freq(cdev);
Tom Rini52437072013-08-30 16:28:46 -0400259
Nishanth Menon2afa70d2016-02-24 12:30:55 -0600260 if (board_is_bone() || board_is_bone_lt()) {
Tom Rini52437072013-08-30 16:28:46 -0400261 /* BeagleBone PMIC Code */
262 int usb_cur_lim;
263
264 /*
265 * Only perform PMIC configurations if board rev > A1
266 * on Beaglebone White
267 */
Nishanth Menon2afa70d2016-02-24 12:30:55 -0600268 if (board_is_bone() && !strncmp(board_ti_get_rev(), "00A1", 4))
Tom Rini52437072013-08-30 16:28:46 -0400269 return;
270
271 if (i2c_probe(TPS65217_CHIP_PM))
272 return;
273
274 /*
275 * On Beaglebone White we need to ensure we have AC power
276 * before increasing the frequency.
277 */
Nishanth Menon2afa70d2016-02-24 12:30:55 -0600278 if (board_is_bone()) {
Tom Rini52437072013-08-30 16:28:46 -0400279 uchar pmic_status_reg;
280 if (tps65217_reg_read(TPS65217_STATUS,
281 &pmic_status_reg))
282 return;
283 if (!(pmic_status_reg & TPS65217_PWR_SRC_AC_BITMASK)) {
284 puts("No AC power, disabling frequency switch\n");
285 return;
286 }
287 }
288
289 /*
290 * Override what we have detected since we know if we have
291 * a Beaglebone Black it supports 1GHz.
292 */
Nishanth Menon2afa70d2016-02-24 12:30:55 -0600293 if (board_is_bone_lt())
Steve Kipisz5adac352013-08-14 10:51:31 -0400294 dpll_mpu_opp100.m = MPUPLL_M_1000;
Tom Rini52437072013-08-30 16:28:46 -0400295
296 /*
297 * Increase USB current limit to 1300mA or 1800mA and set
298 * the MPU voltage controller as needed.
299 */
Steve Kipisz5adac352013-08-14 10:51:31 -0400300 if (dpll_mpu_opp100.m == MPUPLL_M_1000) {
Tom Rini52437072013-08-30 16:28:46 -0400301 usb_cur_lim = TPS65217_USB_INPUT_CUR_LIMIT_1800MA;
302 mpu_vdd = TPS65217_DCDC_VOLT_SEL_1325MV;
303 } else {
304 usb_cur_lim = TPS65217_USB_INPUT_CUR_LIMIT_1300MA;
305 mpu_vdd = TPS65217_DCDC_VOLT_SEL_1275MV;
306 }
307
308 if (tps65217_reg_write(TPS65217_PROT_LEVEL_NONE,
309 TPS65217_POWER_PATH,
310 usb_cur_lim,
311 TPS65217_USB_INPUT_CUR_LIMIT_MASK))
312 puts("tps65217_reg_write failure\n");
313
Steve Kipisz5adac352013-08-14 10:51:31 -0400314 /* Set DCDC3 (CORE) voltage to 1.125V */
315 if (tps65217_voltage_update(TPS65217_DEFDCDC3,
316 TPS65217_DCDC_VOLT_SEL_1125MV)) {
317 puts("tps65217_voltage_update failure\n");
318 return;
319 }
320
321 /* Set CORE Frequencies to OPP100 */
322 do_setup_dpll(&dpll_core_regs, &dpll_core_opp100);
Tom Rini52437072013-08-30 16:28:46 -0400323
324 /* Set DCDC2 (MPU) voltage */
325 if (tps65217_voltage_update(TPS65217_DEFDCDC2, mpu_vdd)) {
326 puts("tps65217_voltage_update failure\n");
327 return;
328 }
329
330 /*
331 * Set LDO3, LDO4 output voltage to 3.3V for Beaglebone.
332 * Set LDO3 to 1.8V and LDO4 to 3.3V for Beaglebone Black.
333 */
Nishanth Menon2afa70d2016-02-24 12:30:55 -0600334 if (board_is_bone()) {
Tom Rini52437072013-08-30 16:28:46 -0400335 if (tps65217_reg_write(TPS65217_PROT_LEVEL_2,
336 TPS65217_DEFLS1,
337 TPS65217_LDO_VOLTAGE_OUT_3_3,
338 TPS65217_LDO_MASK))
339 puts("tps65217_reg_write failure\n");
340 } else {
341 if (tps65217_reg_write(TPS65217_PROT_LEVEL_2,
342 TPS65217_DEFLS1,
343 TPS65217_LDO_VOLTAGE_OUT_1_8,
344 TPS65217_LDO_MASK))
345 puts("tps65217_reg_write failure\n");
346 }
347
348 if (tps65217_reg_write(TPS65217_PROT_LEVEL_2,
349 TPS65217_DEFLS2,
350 TPS65217_LDO_VOLTAGE_OUT_3_3,
351 TPS65217_LDO_MASK))
352 puts("tps65217_reg_write failure\n");
353 } else {
354 int sil_rev;
355
356 /*
357 * The GP EVM, IDK and EVM SK use a TPS65910 PMIC. For all
358 * MPU frequencies we support we use a CORE voltage of
359 * 1.1375V. For MPU voltage we need to switch based on
360 * the frequency we are running at.
361 */
362 if (i2c_probe(TPS65910_CTRL_I2C_ADDR))
363 return;
364
365 /*
366 * Depending on MPU clock and PG we will need a different
367 * VDD to drive at that speed.
368 */
369 sil_rev = readl(&cdev->deviceid) >> 28;
Steve Kipisz5adac352013-08-14 10:51:31 -0400370 mpu_vdd = am335x_get_tps65910_mpu_vdd(sil_rev,
371 dpll_mpu_opp100.m);
Tom Rini52437072013-08-30 16:28:46 -0400372
373 /* Tell the TPS65910 to use i2c */
374 tps65910_set_i2c_control();
375
376 /* First update MPU voltage. */
377 if (tps65910_voltage_update(MPU, mpu_vdd))
378 return;
379
380 /* Second, update the CORE voltage. */
381 if (tps65910_voltage_update(CORE, TPS65910_OP_REG_SEL_1_1_3))
382 return;
Steve Kipisz5adac352013-08-14 10:51:31 -0400383
384 /* Set CORE Frequencies to OPP100 */
385 do_setup_dpll(&dpll_core_regs, &dpll_core_opp100);
Tom Rini52437072013-08-30 16:28:46 -0400386 }
387
388 /* Set MPU Frequency to what we detected now that voltages are set */
Steve Kipisz5adac352013-08-14 10:51:31 -0400389 do_setup_dpll(&dpll_mpu_regs, &dpll_mpu_opp100);
Tom Rini52437072013-08-30 16:28:46 -0400390}
391
Lokesh Vutla89a83bf2013-07-30 10:48:52 +0530392const struct dpll_params *get_dpll_ddr_params(void)
393{
Lokesh Vutla89a83bf2013-07-30 10:48:52 +0530394 enable_i2c0_pin_mux();
Heiko Schocherf53f2b82013-10-22 11:03:18 +0200395 i2c_init(CONFIG_SYS_OMAP24_I2C_SPEED, CONFIG_SYS_OMAP24_I2C_SLAVE);
Nishanth Menon2afa70d2016-02-24 12:30:55 -0600396 if (read_eeprom() < 0)
Lokesh Vutla89a83bf2013-07-30 10:48:52 +0530397 puts("Could not get board ID.\n");
398
Nishanth Menon2afa70d2016-02-24 12:30:55 -0600399 if (board_is_evm_sk())
Lokesh Vutla89a83bf2013-07-30 10:48:52 +0530400 return &dpll_ddr_evm_sk;
Lokesh Vutla5837b902016-05-16 11:47:24 +0530401 else if (board_is_bone_lt() || board_is_icev2())
Lokesh Vutla89a83bf2013-07-30 10:48:52 +0530402 return &dpll_ddr_bone_black;
Nishanth Menon2afa70d2016-02-24 12:30:55 -0600403 else if (board_is_evm_15_or_later())
Lokesh Vutla89a83bf2013-07-30 10:48:52 +0530404 return &dpll_ddr_evm_sk;
405 else
406 return &dpll_ddr;
407}
408
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530409void set_uart_mux_conf(void)
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000410{
Tom Rini986d7552014-08-01 09:53:24 -0400411#if CONFIG_CONS_INDEX == 1
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000412 enable_uart0_pin_mux();
Tom Rini986d7552014-08-01 09:53:24 -0400413#elif CONFIG_CONS_INDEX == 2
Andrew Bradford65c51ff2012-10-25 08:21:30 -0400414 enable_uart1_pin_mux();
Tom Rini986d7552014-08-01 09:53:24 -0400415#elif CONFIG_CONS_INDEX == 3
Andrew Bradford65c51ff2012-10-25 08:21:30 -0400416 enable_uart2_pin_mux();
Tom Rini986d7552014-08-01 09:53:24 -0400417#elif CONFIG_CONS_INDEX == 4
Andrew Bradford65c51ff2012-10-25 08:21:30 -0400418 enable_uart3_pin_mux();
Tom Rini986d7552014-08-01 09:53:24 -0400419#elif CONFIG_CONS_INDEX == 5
Andrew Bradford65c51ff2012-10-25 08:21:30 -0400420 enable_uart4_pin_mux();
Tom Rini986d7552014-08-01 09:53:24 -0400421#elif CONFIG_CONS_INDEX == 6
Andrew Bradford65c51ff2012-10-25 08:21:30 -0400422 enable_uart5_pin_mux();
Tom Rini986d7552014-08-01 09:53:24 -0400423#endif
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530424}
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000425
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530426void set_mux_conf_regs(void)
427{
Nishanth Menon2afa70d2016-02-24 12:30:55 -0600428 if (read_eeprom() < 0)
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530429 puts("Could not get board ID.\n");
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000430
Nishanth Menon2afa70d2016-02-24 12:30:55 -0600431 enable_board_pin_mux();
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530432}
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000433
Lokesh Vutla303b2672013-12-10 15:02:21 +0530434const struct ctrl_ioregs ioregs_evmsk = {
435 .cm0ioctl = MT41J128MJT125_IOCTRL_VALUE,
436 .cm1ioctl = MT41J128MJT125_IOCTRL_VALUE,
437 .cm2ioctl = MT41J128MJT125_IOCTRL_VALUE,
438 .dt0ioctl = MT41J128MJT125_IOCTRL_VALUE,
439 .dt1ioctl = MT41J128MJT125_IOCTRL_VALUE,
440};
441
442const struct ctrl_ioregs ioregs_bonelt = {
443 .cm0ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
444 .cm1ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
445 .cm2ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
446 .dt0ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
447 .dt1ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
448};
449
450const struct ctrl_ioregs ioregs_evm15 = {
451 .cm0ioctl = MT41J512M8RH125_IOCTRL_VALUE,
452 .cm1ioctl = MT41J512M8RH125_IOCTRL_VALUE,
453 .cm2ioctl = MT41J512M8RH125_IOCTRL_VALUE,
454 .dt0ioctl = MT41J512M8RH125_IOCTRL_VALUE,
455 .dt1ioctl = MT41J512M8RH125_IOCTRL_VALUE,
456};
457
458const struct ctrl_ioregs ioregs = {
459 .cm0ioctl = MT47H128M16RT25E_IOCTRL_VALUE,
460 .cm1ioctl = MT47H128M16RT25E_IOCTRL_VALUE,
461 .cm2ioctl = MT47H128M16RT25E_IOCTRL_VALUE,
462 .dt0ioctl = MT47H128M16RT25E_IOCTRL_VALUE,
463 .dt1ioctl = MT47H128M16RT25E_IOCTRL_VALUE,
464};
465
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530466void sdram_init(void)
467{
Nishanth Menon2afa70d2016-02-24 12:30:55 -0600468 if (read_eeprom() < 0)
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000469 puts("Could not get board ID.\n");
470
Nishanth Menon2afa70d2016-02-24 12:30:55 -0600471 if (board_is_evm_sk()) {
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000472 /*
473 * EVM SK 1.2A and later use gpio0_7 to enable DDR3.
474 * This is safe enough to do on older revs.
475 */
476 gpio_request(GPIO_DDR_VTT_EN, "ddr_vtt_en");
477 gpio_direction_output(GPIO_DDR_VTT_EN, 1);
478 }
479
Lokesh Vutla5837b902016-05-16 11:47:24 +0530480 if (board_is_icev2()) {
481 gpio_request(ICE_GPIO_DDR_VTT_EN, "ddr_vtt_en");
482 gpio_direction_output(ICE_GPIO_DDR_VTT_EN, 1);
483 }
484
Nishanth Menon2afa70d2016-02-24 12:30:55 -0600485 if (board_is_evm_sk())
Lokesh Vutla303b2672013-12-10 15:02:21 +0530486 config_ddr(303, &ioregs_evmsk, &ddr3_data,
Matt Porter65991ec2013-03-15 10:07:03 +0000487 &ddr3_cmd_ctrl_data, &ddr3_emif_reg_data, 0);
Nishanth Menon2afa70d2016-02-24 12:30:55 -0600488 else if (board_is_bone_lt())
Lokesh Vutla303b2672013-12-10 15:02:21 +0530489 config_ddr(400, &ioregs_bonelt,
Tom Rini385bc752013-03-21 04:30:02 +0000490 &ddr3_beagleblack_data,
491 &ddr3_beagleblack_cmd_ctrl_data,
492 &ddr3_beagleblack_emif_reg_data, 0);
Nishanth Menon2afa70d2016-02-24 12:30:55 -0600493 else if (board_is_evm_15_or_later())
Lokesh Vutla303b2672013-12-10 15:02:21 +0530494 config_ddr(303, &ioregs_evm15, &ddr3_evm_data,
Matt Porter65991ec2013-03-15 10:07:03 +0000495 &ddr3_evm_cmd_ctrl_data, &ddr3_evm_emif_reg_data, 0);
Lokesh Vutla5837b902016-05-16 11:47:24 +0530496 else if (board_is_icev2())
497 config_ddr(400, &ioregs_evmsk, &ddr3_icev2_data,
498 &ddr3_icev2_cmd_ctrl_data, &ddr3_icev2_emif_reg_data,
499 0);
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000500 else
Lokesh Vutla303b2672013-12-10 15:02:21 +0530501 config_ddr(266, &ioregs, &ddr2_data,
Matt Porter65991ec2013-03-15 10:07:03 +0000502 &ddr2_cmd_ctrl_data, &ddr2_emif_reg_data, 0);
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000503}
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530504#endif
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000505
Roger Quadrosbcb4ee82016-08-24 15:35:50 +0300506#if !defined(CONFIG_SPL_BUILD) || \
Lokesh Vutla0d144f52016-05-16 11:47:26 +0530507 (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD))
Roger Quadrosbcb4ee82016-08-24 15:35:50 +0300508static void request_and_set_gpio(int gpio, char *name, int val)
Lokesh Vutla0d144f52016-05-16 11:47:26 +0530509{
510 int ret;
511
512 ret = gpio_request(gpio, name);
513 if (ret < 0) {
514 printf("%s: Unable to request %s\n", __func__, name);
515 return;
516 }
517
518 ret = gpio_direction_output(gpio, 0);
519 if (ret < 0) {
520 printf("%s: Unable to set %s as output\n", __func__, name);
521 goto err_free_gpio;
522 }
523
Roger Quadrosbcb4ee82016-08-24 15:35:50 +0300524 gpio_set_value(gpio, val);
Lokesh Vutla0d144f52016-05-16 11:47:26 +0530525
526 return;
527
528err_free_gpio:
529 gpio_free(gpio);
530}
531
Roger Quadrosbcb4ee82016-08-24 15:35:50 +0300532#define REQUEST_AND_SET_GPIO(N) request_and_set_gpio(N, #N, 1);
533#define REQUEST_AND_CLR_GPIO(N) request_and_set_gpio(N, #N, 0);
Lokesh Vutla0d144f52016-05-16 11:47:26 +0530534
535/**
536 * RMII mode on ICEv2 board needs 50MHz clock. Given the clock
537 * synthesizer With a capacitor of 18pF, and 25MHz input clock cycle
538 * PLL1 gives an output of 100MHz. So, configuring the div2/3 as 2 to
539 * give 50MHz output for Eth0 and 1.
540 */
541static struct clk_synth cdce913_data = {
542 .id = 0x81,
543 .capacitor = 0x90,
544 .mux = 0x6d,
545 .pdiv2 = 0x2,
546 .pdiv3 = 0x2,
547};
548#endif
549
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000550/*
551 * Basic board specific setup. Pinmux has been handled already.
552 */
553int board_init(void)
554{
Tom Rini303bfe82013-10-01 12:32:04 -0400555#if defined(CONFIG_HW_WATCHDOG)
556 hw_watchdog_init();
557#endif
558
Tom Rinif3b6a1d2013-08-09 11:22:13 -0400559 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
pekon gupta53b4b322013-11-18 19:03:02 +0530560#if defined(CONFIG_NOR) || defined(CONFIG_NAND)
Ilya Yanok3d9725e2012-11-06 13:06:31 +0000561 gpmc_init();
Steve Kipiszbe9b6f82013-07-18 15:13:03 -0400562#endif
Lokesh Vutla0d144f52016-05-16 11:47:26 +0530563
Roger Quadrosbcb4ee82016-08-24 15:35:50 +0300564#if !defined(CONFIG_SPL_BUILD) || \
565 (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD))
Lokesh Vutla0d144f52016-05-16 11:47:26 +0530566 if (board_is_icev2()) {
Roger Quadrosbcb4ee82016-08-24 15:35:50 +0300567 int rv;
568 u32 reg;
569
Lokesh Vutla0d144f52016-05-16 11:47:26 +0530570 REQUEST_AND_SET_GPIO(GPIO_PR1_MII_CTRL);
Roger Quadrosbcb4ee82016-08-24 15:35:50 +0300571 /* Make J19 status available on GPIO1_26 */
572 REQUEST_AND_CLR_GPIO(GPIO_MUX_MII_CTRL);
573
Lokesh Vutla0d144f52016-05-16 11:47:26 +0530574 REQUEST_AND_SET_GPIO(GPIO_FET_SWITCH_CTRL);
Roger Quadrosbcb4ee82016-08-24 15:35:50 +0300575 /*
576 * Both ports can be set as RMII-CPSW or MII-PRU-ETH using
577 * jumpers near the port. Read the jumper value and set
578 * the pinmux, external mux and PHY clock accordingly.
579 * As jumper line is overridden by PHY RX_DV pin immediately
580 * after bootstrap (power-up/reset), we need to sample
581 * it during PHY reset using GPIO rising edge detection.
582 */
Lokesh Vutla0d144f52016-05-16 11:47:26 +0530583 REQUEST_AND_SET_GPIO(GPIO_PHY_RESET);
Roger Quadrosbcb4ee82016-08-24 15:35:50 +0300584 /* Enable rising edge IRQ on GPIO0_11 and GPIO 1_26 */
585 reg = readl(GPIO0_RISINGDETECT) | BIT(11);
586 writel(reg, GPIO0_RISINGDETECT);
587 reg = readl(GPIO1_RISINGDETECT) | BIT(26);
588 writel(reg, GPIO1_RISINGDETECT);
589 /* Reset PHYs to capture the Jumper setting */
590 gpio_set_value(GPIO_PHY_RESET, 0);
591 udelay(2); /* PHY datasheet states 1uS min. */
592 gpio_set_value(GPIO_PHY_RESET, 1);
593
594 reg = readl(GPIO0_IRQSTATUSRAW) & BIT(11);
595 if (reg) {
596 writel(reg, GPIO0_IRQSTATUS1); /* clear irq */
597 /* RMII mode */
598 printf("ETH0, CPSW\n");
599 } else {
600 /* MII mode */
601 printf("ETH0, PRU\n");
602 cdce913_data.pdiv3 = 4; /* 25MHz PHY clk */
603 }
604
605 reg = readl(GPIO1_IRQSTATUSRAW) & BIT(26);
606 if (reg) {
607 writel(reg, GPIO1_IRQSTATUS1); /* clear irq */
608 /* RMII mode */
609 printf("ETH1, CPSW\n");
610 gpio_set_value(GPIO_MUX_MII_CTRL, 1);
611 } else {
612 /* MII mode */
613 printf("ETH1, PRU\n");
614 cdce913_data.pdiv2 = 4; /* 25MHz PHY clk */
615 }
616
617 /* disable rising edge IRQs */
618 reg = readl(GPIO0_RISINGDETECT) & ~BIT(11);
619 writel(reg, GPIO0_RISINGDETECT);
620 reg = readl(GPIO1_RISINGDETECT) & ~BIT(26);
621 writel(reg, GPIO1_RISINGDETECT);
Lokesh Vutla0d144f52016-05-16 11:47:26 +0530622
623 rv = setup_clock_synthesizer(&cdce913_data);
624 if (rv) {
625 printf("Clock synthesizer setup failed %d\n", rv);
626 return rv;
627 }
Roger Quadrosbcb4ee82016-08-24 15:35:50 +0300628
629 /* reset PHYs */
630 gpio_set_value(GPIO_PHY_RESET, 0);
631 udelay(2); /* PHY datasheet states 1uS min. */
632 gpio_set_value(GPIO_PHY_RESET, 1);
Lokesh Vutla0d144f52016-05-16 11:47:26 +0530633 }
634#endif
635
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000636 return 0;
637}
638
Tom Rini40271852012-10-24 07:28:17 +0000639#ifdef CONFIG_BOARD_LATE_INIT
640int board_late_init(void)
641{
642#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
Nishanth Menon2afa70d2016-02-24 12:30:55 -0600643 int rc;
644 char *name = NULL;
Tom Rini4021fd92013-07-18 15:13:01 -0400645
Nishanth Menon2afa70d2016-02-24 12:30:55 -0600646 rc = read_eeprom();
647 if (rc)
Tom Rini4021fd92013-07-18 15:13:01 -0400648 puts("Could not get board ID.\n");
Tom Rini40271852012-10-24 07:28:17 +0000649
Nishanth Menon2afa70d2016-02-24 12:30:55 -0600650 if (board_is_bbg1())
651 name = "BBG1";
652 set_board_info_env(name);
Tom Rini40271852012-10-24 07:28:17 +0000653#endif
654
655 return 0;
656}
657#endif
658
Mugunthan V Ndf7a99f2015-09-07 14:22:18 +0530659#ifndef CONFIG_DM_ETH
660
Ilya Yanok0760a0d2013-02-05 11:36:26 +0000661#if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) || \
662 (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD))
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000663static void cpsw_control(int enabled)
664{
665 /* VTP can be added here */
666
667 return;
668}
669
670static struct cpsw_slave_data cpsw_slaves[] = {
671 {
672 .slave_reg_ofs = 0x208,
673 .sliver_reg_ofs = 0xd80,
Mugunthan V N4944f372014-02-18 07:31:52 -0500674 .phy_addr = 0,
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000675 },
676 {
677 .slave_reg_ofs = 0x308,
678 .sliver_reg_ofs = 0xdc0,
Mugunthan V N4944f372014-02-18 07:31:52 -0500679 .phy_addr = 1,
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000680 },
681};
682
683static struct cpsw_platform_data cpsw_data = {
Matt Portere24646f2013-03-15 10:07:02 +0000684 .mdio_base = CPSW_MDIO_BASE,
685 .cpsw_base = CPSW_BASE,
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000686 .mdio_div = 0xff,
687 .channels = 8,
688 .cpdma_reg_ofs = 0x800,
689 .slaves = 1,
690 .slave_data = cpsw_slaves,
691 .ale_reg_ofs = 0xd00,
692 .ale_entries = 1024,
693 .host_port_reg_ofs = 0x108,
694 .hw_stats_reg_ofs = 0x900,
Mugunthan V Nff559872013-07-08 16:04:37 +0530695 .bd_ram_ofs = 0x2000,
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000696 .mac_control = (1 << 5),
697 .control = cpsw_control,
698 .host_port_num = 0,
699 .version = CPSW_CTRL_VERSION_2,
700};
Ilya Yanok44a2c072012-11-06 13:48:24 +0000701#endif
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000702
Lokesh Vutla0d144f52016-05-16 11:47:26 +0530703#if ((defined(CONFIG_SPL_ETH_SUPPORT) || defined(CONFIG_SPL_USBETH_SUPPORT)) &&\
704 defined(CONFIG_SPL_BUILD)) || \
705 ((defined(CONFIG_DRIVER_TI_CPSW) || \
706 defined(CONFIG_USB_ETHER) && defined(CONFIG_MUSB_GADGET)) && \
707 !defined(CONFIG_SPL_BUILD))
708
Tom Rini60fcaaa2014-03-26 15:53:12 -0400709/*
710 * This function will:
711 * Read the eFuse for MAC addresses, and set ethaddr/eth1addr/usbnet_devaddr
712 * in the environment
713 * Perform fixups to the PHY present on certain boards. We only need this
714 * function in:
715 * - SPL with either CPSW or USB ethernet support
716 * - Full U-Boot, with either CPSW or USB ethernet
717 * Build in only these cases to avoid warnings about unused variables
718 * when we build an SPL that has neither option but full U-Boot will.
719 */
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000720int board_eth_init(bd_t *bis)
721{
Ilya Yanok44a2c072012-11-06 13:48:24 +0000722 int rv, n = 0;
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000723 uint8_t mac_addr[6];
724 uint32_t mac_hi, mac_lo;
Nishanth Menon2afa70d2016-02-24 12:30:55 -0600725 __maybe_unused struct ti_am_eeprom *header;
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000726
Ilya Yanok0760a0d2013-02-05 11:36:26 +0000727 /* try reading mac address from efuse */
728 mac_lo = readl(&cdev->macid0l);
729 mac_hi = readl(&cdev->macid0h);
730 mac_addr[0] = mac_hi & 0xFF;
731 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
732 mac_addr[2] = (mac_hi & 0xFF0000) >> 16;
733 mac_addr[3] = (mac_hi & 0xFF000000) >> 24;
734 mac_addr[4] = mac_lo & 0xFF;
735 mac_addr[5] = (mac_lo & 0xFF00) >> 8;
736
737#if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) || \
738 (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD))
739 if (!getenv("ethaddr")) {
740 printf("<ethaddr> not set. Validating first E-fuse MAC\n");
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000741
Joe Hershberger8ecdbed2015-04-08 01:41:04 -0500742 if (is_valid_ethaddr(mac_addr))
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000743 eth_setenv_enetaddr("ethaddr", mac_addr);
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000744 }
745
Joel A Fernandesf7488542013-05-07 05:52:55 +0000746#ifdef CONFIG_DRIVER_TI_CPSW
Mugunthan V N0c1d8562014-02-18 07:31:55 -0500747
748 mac_lo = readl(&cdev->macid1l);
749 mac_hi = readl(&cdev->macid1h);
750 mac_addr[0] = mac_hi & 0xFF;
751 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
752 mac_addr[2] = (mac_hi & 0xFF0000) >> 16;
753 mac_addr[3] = (mac_hi & 0xFF000000) >> 24;
754 mac_addr[4] = mac_lo & 0xFF;
755 mac_addr[5] = (mac_lo & 0xFF00) >> 8;
756
757 if (!getenv("eth1addr")) {
Joe Hershberger8ecdbed2015-04-08 01:41:04 -0500758 if (is_valid_ethaddr(mac_addr))
Mugunthan V N0c1d8562014-02-18 07:31:55 -0500759 eth_setenv_enetaddr("eth1addr", mac_addr);
760 }
761
Nishanth Menon2afa70d2016-02-24 12:30:55 -0600762 if (read_eeprom() < 0)
Tom Rini4021fd92013-07-18 15:13:01 -0400763 puts("Could not get board ID.\n");
764
Nishanth Menon2afa70d2016-02-24 12:30:55 -0600765 if (board_is_bone() || board_is_bone_lt() ||
766 board_is_idk()) {
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000767 writel(MII_MODE_ENABLE, &cdev->miisel);
768 cpsw_slaves[0].phy_if = cpsw_slaves[1].phy_if =
769 PHY_INTERFACE_MODE_MII;
Lokesh Vutla0d144f52016-05-16 11:47:26 +0530770 } else if (board_is_icev2()) {
771 writel(RMII_MODE_ENABLE | RMII_CHIPCKL_ENABLE, &cdev->miisel);
772 cpsw_slaves[0].phy_if = PHY_INTERFACE_MODE_RMII;
773 cpsw_slaves[1].phy_if = PHY_INTERFACE_MODE_RMII;
774 cpsw_slaves[0].phy_addr = 1;
775 cpsw_slaves[1].phy_addr = 3;
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000776 } else {
Heiko Schocherc4fea292013-08-19 16:38:56 +0200777 writel((RGMII_MODE_ENABLE | RGMII_INT_DELAY), &cdev->miisel);
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000778 cpsw_slaves[0].phy_if = cpsw_slaves[1].phy_if =
779 PHY_INTERFACE_MODE_RGMII;
780 }
781
Ilya Yanok44a2c072012-11-06 13:48:24 +0000782 rv = cpsw_register(&cpsw_data);
783 if (rv < 0)
784 printf("Error %d registering CPSW switch\n", rv);
785 else
786 n += rv;
Joel A Fernandesf7488542013-05-07 05:52:55 +0000787#endif
Tom Rini183943d2013-02-12 14:59:23 -0500788
789 /*
790 *
791 * CPSW RGMII Internal Delay Mode is not supported in all PVT
792 * operating points. So we must set the TX clock delay feature
793 * in the AR8051 PHY. Since we only support a single ethernet
794 * device in U-Boot, we only do this for the first instance.
795 */
796#define AR8051_PHY_DEBUG_ADDR_REG 0x1d
797#define AR8051_PHY_DEBUG_DATA_REG 0x1e
798#define AR8051_DEBUG_RGMII_CLK_DLY_REG 0x5
799#define AR8051_RGMII_TX_CLK_DLY 0x100
800
Nishanth Menon2afa70d2016-02-24 12:30:55 -0600801 if (board_is_evm_sk() || board_is_gp_evm()) {
Tom Rini183943d2013-02-12 14:59:23 -0500802 const char *devname;
803 devname = miiphy_get_current_dev();
804
805 miiphy_write(devname, 0x0, AR8051_PHY_DEBUG_ADDR_REG,
806 AR8051_DEBUG_RGMII_CLK_DLY_REG);
807 miiphy_write(devname, 0x0, AR8051_PHY_DEBUG_DATA_REG,
808 AR8051_RGMII_TX_CLK_DLY);
809 }
Ilya Yanok44a2c072012-11-06 13:48:24 +0000810#endif
Ilya Yanok0760a0d2013-02-05 11:36:26 +0000811#if defined(CONFIG_USB_ETHER) && \
812 (!defined(CONFIG_SPL_BUILD) || defined(CONFIG_SPL_USBETH_SUPPORT))
Joe Hershberger8ecdbed2015-04-08 01:41:04 -0500813 if (is_valid_ethaddr(mac_addr))
Ilya Yanok0760a0d2013-02-05 11:36:26 +0000814 eth_setenv_enetaddr("usbnet_devaddr", mac_addr);
815
Ilya Yanok44a2c072012-11-06 13:48:24 +0000816 rv = usb_eth_initialize(bis);
817 if (rv < 0)
818 printf("Error %d registering USB_ETHER\n", rv);
819 else
820 n += rv;
821#endif
822 return n;
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000823}
824#endif
Mugunthan V Ndf7a99f2015-09-07 14:22:18 +0530825
826#endif /* CONFIG_DM_ETH */
Lokesh Vutla89b9f302016-05-16 11:24:24 +0530827
828#ifdef CONFIG_SPL_LOAD_FIT
829int board_fit_config_name_match(const char *name)
830{
831 if (board_is_gp_evm() && !strcmp(name, "am335x-evm"))
832 return 0;
833 else if (board_is_bone() && !strcmp(name, "am335x-bone"))
834 return 0;
835 else if (board_is_bone_lt() && !strcmp(name, "am335x-boneblack"))
836 return 0;
Lokesh Vutla5a954ba2016-05-16 11:24:28 +0530837 else if (board_is_evm_sk() && !strcmp(name, "am335x-evmsk"))
838 return 0;
Lokesh Vutla1edfcaf2016-05-16 11:24:29 +0530839 else if (board_is_bbg1() && !strcmp(name, "am335x-bonegreen"))
840 return 0;
Lokesh Vutla7ecf1962016-05-16 11:47:28 +0530841 else if (board_is_icev2() && !strcmp(name, "am335x-icev2"))
842 return 0;
Lokesh Vutla89b9f302016-05-16 11:24:24 +0530843 else
844 return -1;
845}
846#endif
Andrew F. Davisbd249152016-08-30 14:06:24 -0500847
848#ifdef CONFIG_TI_SECURE_DEVICE
849void board_fit_image_post_process(void **p_image, size_t *p_size)
850{
851 secure_boot_verify_image(p_image, p_size);
852}
853#endif