blob: 3e815213998fe36a97ff2e758c728e44dba933e5 [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>
Lokesh Vutla2fe7c792017-04-26 13:37:08 +053012#include <dm.h>
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000013#include <errno.h>
14#include <spl.h>
Lokesh Vutlaabb44e62016-05-16 11:47:29 +053015#include <serial.h>
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000016#include <asm/arch/cpu.h>
17#include <asm/arch/hardware.h>
18#include <asm/arch/omap.h>
19#include <asm/arch/ddr_defs.h>
20#include <asm/arch/clock.h>
Lokesh Vutla0d144f52016-05-16 11:47:26 +053021#include <asm/arch/clk_synthesizer.h>
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000022#include <asm/arch/gpio.h>
23#include <asm/arch/mmc_host_def.h>
24#include <asm/arch/sys_proto.h>
Steve Kipiszbe9b6f82013-07-18 15:13:03 -040025#include <asm/arch/mem.h>
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000026#include <asm/io.h>
27#include <asm/emif.h>
28#include <asm/gpio.h>
Andrew F. Davisbd249152016-08-30 14:06:24 -050029#include <asm/omap_sec_common.h>
Lokesh Vutla2fe7c792017-04-26 13:37:08 +053030#include <asm/omap_mmc.h>
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000031#include <i2c.h>
32#include <miiphy.h>
33#include <cpsw.h>
Tom Rini52437072013-08-30 16:28:46 -040034#include <power/tps65217.h>
35#include <power/tps65910.h>
Tom Rini303bfe82013-10-01 12:32:04 -040036#include <environment.h>
37#include <watchdog.h>
Tom Rini810b5812014-03-28 12:03:38 -040038#include <environment.h>
Nishanth Menon2afa70d2016-02-24 12:30:55 -060039#include "../common/board_detect.h"
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000040#include "board.h"
41
42DECLARE_GLOBAL_DATA_PTR;
43
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000044/* GPIO that controls power to DDR on EVM-SK */
Lokesh Vutla0d144f52016-05-16 11:47:26 +053045#define GPIO_TO_PIN(bank, gpio) (32 * (bank) + (gpio))
46#define GPIO_DDR_VTT_EN GPIO_TO_PIN(0, 7)
47#define ICE_GPIO_DDR_VTT_EN GPIO_TO_PIN(0, 18)
48#define GPIO_PR1_MII_CTRL GPIO_TO_PIN(3, 4)
49#define GPIO_MUX_MII_CTRL GPIO_TO_PIN(3, 10)
50#define GPIO_FET_SWITCH_CTRL GPIO_TO_PIN(0, 7)
51#define GPIO_PHY_RESET GPIO_TO_PIN(2, 5)
Roger Quadrosbcb4ee82016-08-24 15:35:50 +030052#define GPIO_ETH0_MODE GPIO_TO_PIN(0, 11)
53#define GPIO_ETH1_MODE GPIO_TO_PIN(1, 26)
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000054
55static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
56
Roger Quadrosbcb4ee82016-08-24 15:35:50 +030057#define GPIO0_RISINGDETECT (AM33XX_GPIO0_BASE + OMAP_GPIO_RISINGDETECT)
58#define GPIO1_RISINGDETECT (AM33XX_GPIO1_BASE + OMAP_GPIO_RISINGDETECT)
59
60#define GPIO0_IRQSTATUS1 (AM33XX_GPIO0_BASE + OMAP_GPIO_IRQSTATUS1)
61#define GPIO1_IRQSTATUS1 (AM33XX_GPIO1_BASE + OMAP_GPIO_IRQSTATUS1)
62
63#define GPIO0_IRQSTATUSRAW (AM33XX_GPIO0_BASE + 0x024)
64#define GPIO1_IRQSTATUSRAW (AM33XX_GPIO1_BASE + 0x024)
65
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000066/*
67 * Read header information from EEPROM into global structure.
68 */
Lokesh Vutla93e0f5b2016-10-14 10:35:25 +053069#ifdef CONFIG_TI_I2C_BOARD_DETECT
70void do_board_detect(void)
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000071{
Lokesh Vutla93e0f5b2016-10-14 10:35:25 +053072 enable_i2c0_pin_mux();
73 i2c_init(CONFIG_SYS_OMAP24_I2C_SPEED, CONFIG_SYS_OMAP24_I2C_SLAVE);
74
75 if (ti_i2c_eeprom_am_get(-1, CONFIG_SYS_I2C_EEPROM_ADDR))
76 printf("ti_i2c_eeprom_init failed\n");
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000077}
Lokesh Vutla93e0f5b2016-10-14 10:35:25 +053078#endif
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000079
Lokesh Vutlaabb44e62016-05-16 11:47:29 +053080#ifndef CONFIG_DM_SERIAL
81struct serial_device *default_serial_console(void)
82{
83 if (board_is_icev2())
84 return &eserial4_device;
85 else
86 return &eserial1_device;
87}
88#endif
89
Tom Rini8de09df2014-04-09 08:25:57 -040090#ifndef CONFIG_SKIP_LOWLEVEL_INIT
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +000091static const struct ddr_data ddr2_data = {
Tom Rini7f50a572014-07-07 21:40:16 -040092 .datardsratio0 = MT47H128M16RT25E_RD_DQS,
93 .datafwsratio0 = MT47H128M16RT25E_PHY_FIFO_WE,
94 .datawrsratio0 = MT47H128M16RT25E_PHY_WR_DATA,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +000095};
96
97static const struct cmd_control ddr2_cmd_ctrl_data = {
Peter Korsgaard3adb8272012-10-18 01:21:13 +000098 .cmd0csratio = MT47H128M16RT25E_RATIO,
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000099
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000100 .cmd1csratio = MT47H128M16RT25E_RATIO,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000101
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000102 .cmd2csratio = MT47H128M16RT25E_RATIO,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000103};
104
105static const struct emif_regs ddr2_emif_reg_data = {
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000106 .sdram_config = MT47H128M16RT25E_EMIF_SDCFG,
107 .ref_ctrl = MT47H128M16RT25E_EMIF_SDREF,
108 .sdram_tim1 = MT47H128M16RT25E_EMIF_TIM1,
109 .sdram_tim2 = MT47H128M16RT25E_EMIF_TIM2,
110 .sdram_tim3 = MT47H128M16RT25E_EMIF_TIM3,
111 .emif_ddr_phy_ctlr_1 = MT47H128M16RT25E_EMIF_READ_LATENCY,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000112};
113
Jyri Sarha8d2998b2016-12-09 12:29:13 +0200114static const struct emif_regs ddr2_evm_emif_reg_data = {
115 .sdram_config = MT47H128M16RT25E_EMIF_SDCFG,
116 .ref_ctrl = MT47H128M16RT25E_EMIF_SDREF,
117 .sdram_tim1 = MT47H128M16RT25E_EMIF_TIM1,
118 .sdram_tim2 = MT47H128M16RT25E_EMIF_TIM2,
119 .sdram_tim3 = MT47H128M16RT25E_EMIF_TIM3,
120 .ocp_config = EMIF_OCP_CONFIG_AM335X_EVM,
121 .emif_ddr_phy_ctlr_1 = MT47H128M16RT25E_EMIF_READ_LATENCY,
122};
123
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000124static const struct ddr_data ddr3_data = {
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000125 .datardsratio0 = MT41J128MJT125_RD_DQS,
126 .datawdsratio0 = MT41J128MJT125_WR_DQS,
127 .datafwsratio0 = MT41J128MJT125_PHY_FIFO_WE,
128 .datawrsratio0 = MT41J128MJT125_PHY_WR_DATA,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000129};
130
Tom Rini385bc752013-03-21 04:30:02 +0000131static const struct ddr_data ddr3_beagleblack_data = {
132 .datardsratio0 = MT41K256M16HA125E_RD_DQS,
133 .datawdsratio0 = MT41K256M16HA125E_WR_DQS,
134 .datafwsratio0 = MT41K256M16HA125E_PHY_FIFO_WE,
135 .datawrsratio0 = MT41K256M16HA125E_PHY_WR_DATA,
Tom Rini385bc752013-03-21 04:30:02 +0000136};
137
Jeff Lance7c03a222013-01-14 05:32:20 +0000138static const struct ddr_data ddr3_evm_data = {
139 .datardsratio0 = MT41J512M8RH125_RD_DQS,
140 .datawdsratio0 = MT41J512M8RH125_WR_DQS,
141 .datafwsratio0 = MT41J512M8RH125_PHY_FIFO_WE,
142 .datawrsratio0 = MT41J512M8RH125_PHY_WR_DATA,
Jeff Lance7c03a222013-01-14 05:32:20 +0000143};
144
Lokesh Vutla5837b902016-05-16 11:47:24 +0530145static const struct ddr_data ddr3_icev2_data = {
146 .datardsratio0 = MT41J128MJT125_RD_DQS_400MHz,
147 .datawdsratio0 = MT41J128MJT125_WR_DQS_400MHz,
148 .datafwsratio0 = MT41J128MJT125_PHY_FIFO_WE_400MHz,
149 .datawrsratio0 = MT41J128MJT125_PHY_WR_DATA_400MHz,
150};
151
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000152static const struct cmd_control ddr3_cmd_ctrl_data = {
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000153 .cmd0csratio = MT41J128MJT125_RATIO,
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000154 .cmd0iclkout = MT41J128MJT125_INVERT_CLKOUT,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000155
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000156 .cmd1csratio = MT41J128MJT125_RATIO,
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000157 .cmd1iclkout = MT41J128MJT125_INVERT_CLKOUT,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000158
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000159 .cmd2csratio = MT41J128MJT125_RATIO,
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000160 .cmd2iclkout = MT41J128MJT125_INVERT_CLKOUT,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000161};
162
Tom Rini385bc752013-03-21 04:30:02 +0000163static const struct cmd_control ddr3_beagleblack_cmd_ctrl_data = {
164 .cmd0csratio = MT41K256M16HA125E_RATIO,
Tom Rini385bc752013-03-21 04:30:02 +0000165 .cmd0iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
166
167 .cmd1csratio = MT41K256M16HA125E_RATIO,
Tom Rini385bc752013-03-21 04:30:02 +0000168 .cmd1iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
169
170 .cmd2csratio = MT41K256M16HA125E_RATIO,
Tom Rini385bc752013-03-21 04:30:02 +0000171 .cmd2iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
172};
173
Jeff Lance7c03a222013-01-14 05:32:20 +0000174static const struct cmd_control ddr3_evm_cmd_ctrl_data = {
175 .cmd0csratio = MT41J512M8RH125_RATIO,
Jeff Lance7c03a222013-01-14 05:32:20 +0000176 .cmd0iclkout = MT41J512M8RH125_INVERT_CLKOUT,
177
178 .cmd1csratio = MT41J512M8RH125_RATIO,
Jeff Lance7c03a222013-01-14 05:32:20 +0000179 .cmd1iclkout = MT41J512M8RH125_INVERT_CLKOUT,
180
181 .cmd2csratio = MT41J512M8RH125_RATIO,
Jeff Lance7c03a222013-01-14 05:32:20 +0000182 .cmd2iclkout = MT41J512M8RH125_INVERT_CLKOUT,
183};
184
Lokesh Vutla5837b902016-05-16 11:47:24 +0530185static const struct cmd_control ddr3_icev2_cmd_ctrl_data = {
186 .cmd0csratio = MT41J128MJT125_RATIO_400MHz,
187 .cmd0iclkout = MT41J128MJT125_INVERT_CLKOUT_400MHz,
188
189 .cmd1csratio = MT41J128MJT125_RATIO_400MHz,
190 .cmd1iclkout = MT41J128MJT125_INVERT_CLKOUT_400MHz,
191
192 .cmd2csratio = MT41J128MJT125_RATIO_400MHz,
193 .cmd2iclkout = MT41J128MJT125_INVERT_CLKOUT_400MHz,
194};
195
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000196static struct emif_regs ddr3_emif_reg_data = {
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000197 .sdram_config = MT41J128MJT125_EMIF_SDCFG,
198 .ref_ctrl = MT41J128MJT125_EMIF_SDREF,
199 .sdram_tim1 = MT41J128MJT125_EMIF_TIM1,
200 .sdram_tim2 = MT41J128MJT125_EMIF_TIM2,
201 .sdram_tim3 = MT41J128MJT125_EMIF_TIM3,
202 .zq_config = MT41J128MJT125_ZQ_CFG,
Vaibhav Hiremathc30d57b2013-03-14 21:11:16 +0000203 .emif_ddr_phy_ctlr_1 = MT41J128MJT125_EMIF_READ_LATENCY |
204 PHY_EN_DYN_PWRDN,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000205};
Jeff Lance7c03a222013-01-14 05:32:20 +0000206
Tom Rini385bc752013-03-21 04:30:02 +0000207static struct emif_regs ddr3_beagleblack_emif_reg_data = {
208 .sdram_config = MT41K256M16HA125E_EMIF_SDCFG,
209 .ref_ctrl = MT41K256M16HA125E_EMIF_SDREF,
210 .sdram_tim1 = MT41K256M16HA125E_EMIF_TIM1,
211 .sdram_tim2 = MT41K256M16HA125E_EMIF_TIM2,
212 .sdram_tim3 = MT41K256M16HA125E_EMIF_TIM3,
Jyri Sarha8d2998b2016-12-09 12:29:13 +0200213 .ocp_config = EMIF_OCP_CONFIG_BEAGLEBONE_BLACK,
Tom Rini385bc752013-03-21 04:30:02 +0000214 .zq_config = MT41K256M16HA125E_ZQ_CFG,
215 .emif_ddr_phy_ctlr_1 = MT41K256M16HA125E_EMIF_READ_LATENCY,
216};
217
Jeff Lance7c03a222013-01-14 05:32:20 +0000218static struct emif_regs ddr3_evm_emif_reg_data = {
219 .sdram_config = MT41J512M8RH125_EMIF_SDCFG,
220 .ref_ctrl = MT41J512M8RH125_EMIF_SDREF,
221 .sdram_tim1 = MT41J512M8RH125_EMIF_TIM1,
222 .sdram_tim2 = MT41J512M8RH125_EMIF_TIM2,
223 .sdram_tim3 = MT41J512M8RH125_EMIF_TIM3,
Jyri Sarha8d2998b2016-12-09 12:29:13 +0200224 .ocp_config = EMIF_OCP_CONFIG_AM335X_EVM,
Jeff Lance7c03a222013-01-14 05:32:20 +0000225 .zq_config = MT41J512M8RH125_ZQ_CFG,
Vaibhav Hiremathc30d57b2013-03-14 21:11:16 +0000226 .emif_ddr_phy_ctlr_1 = MT41J512M8RH125_EMIF_READ_LATENCY |
227 PHY_EN_DYN_PWRDN,
Jeff Lance7c03a222013-01-14 05:32:20 +0000228};
Peter Korsgaardeb204db2013-05-13 08:36:30 +0000229
Lokesh Vutla5837b902016-05-16 11:47:24 +0530230static struct emif_regs ddr3_icev2_emif_reg_data = {
231 .sdram_config = MT41J128MJT125_EMIF_SDCFG_400MHz,
232 .ref_ctrl = MT41J128MJT125_EMIF_SDREF_400MHz,
233 .sdram_tim1 = MT41J128MJT125_EMIF_TIM1_400MHz,
234 .sdram_tim2 = MT41J128MJT125_EMIF_TIM2_400MHz,
235 .sdram_tim3 = MT41J128MJT125_EMIF_TIM3_400MHz,
236 .zq_config = MT41J128MJT125_ZQ_CFG_400MHz,
237 .emif_ddr_phy_ctlr_1 = MT41J128MJT125_EMIF_READ_LATENCY_400MHz |
238 PHY_EN_DYN_PWRDN,
239};
240
Peter Korsgaardeb204db2013-05-13 08:36:30 +0000241#ifdef CONFIG_SPL_OS_BOOT
242int spl_start_uboot(void)
243{
244 /* break into full u-boot on 'c' */
Tom Rini810b5812014-03-28 12:03:38 -0400245 if (serial_tstc() && serial_getc() == 'c')
246 return 1;
247
248#ifdef CONFIG_SPL_ENV_SUPPORT
249 env_init();
250 env_relocate_spec();
251 if (getenv_yesno("boot_os") != 1)
252 return 1;
253#endif
254
255 return 0;
Peter Korsgaardeb204db2013-05-13 08:36:30 +0000256}
257#endif
258
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530259const struct dpll_params *get_dpll_ddr_params(void)
Tom Rini52437072013-08-30 16:28:46 -0400260{
Lokesh Vutla6302e532017-05-05 12:59:10 +0530261 int ind = get_sys_clk_index();
262
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530263 if (board_is_evm_sk())
Lokesh Vutla6302e532017-05-05 12:59:10 +0530264 return &dpll_ddr3_303MHz[ind];
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530265 else if (board_is_bone_lt() || board_is_icev2())
Lokesh Vutla6302e532017-05-05 12:59:10 +0530266 return &dpll_ddr3_400MHz[ind];
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530267 else if (board_is_evm_15_or_later())
Lokesh Vutla6302e532017-05-05 12:59:10 +0530268 return &dpll_ddr3_303MHz[ind];
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530269 else
Lokesh Vutla6302e532017-05-05 12:59:10 +0530270 return &dpll_ddr2_266MHz[ind];
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530271}
Tom Rini52437072013-08-30 16:28:46 -0400272
Lokesh Vutla6302e532017-05-05 12:59:10 +0530273static u8 bone_not_connected_to_ac_power(void)
274{
275 if (board_is_bone()) {
276 uchar pmic_status_reg;
277 if (tps65217_reg_read(TPS65217_STATUS,
278 &pmic_status_reg))
279 return 1;
280 if (!(pmic_status_reg & TPS65217_PWR_SRC_AC_BITMASK)) {
281 puts("No AC power, switching to default OPP\n");
282 return 1;
283 }
284 }
285 return 0;
286}
287
288const struct dpll_params *get_dpll_mpu_params(void)
289{
290 int ind = get_sys_clk_index();
291 int freq = am335x_get_efuse_mpu_max_freq(cdev);
292
293 if (bone_not_connected_to_ac_power())
294 freq = MPUPLL_M_600;
295
296 if (board_is_bone_lt())
297 freq = MPUPLL_M_1000;
298
299 switch (freq) {
300 case MPUPLL_M_1000:
301 return &dpll_mpu_opp[ind][5];
302 case MPUPLL_M_800:
303 return &dpll_mpu_opp[ind][4];
304 case MPUPLL_M_720:
305 return &dpll_mpu_opp[ind][3];
306 case MPUPLL_M_600:
307 return &dpll_mpu_opp[ind][2];
308 case MPUPLL_M_500:
309 return &dpll_mpu_opp100;
310 case MPUPLL_M_300:
311 return &dpll_mpu_opp[ind][0];
312 }
313
314 return &dpll_mpu_opp[ind][0];
315}
316
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530317static void scale_vcores_bone(int freq)
318{
319 int usb_cur_lim, mpu_vdd;
Tom Rini52437072013-08-30 16:28:46 -0400320
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530321 /*
322 * Only perform PMIC configurations if board rev > A1
323 * on Beaglebone White
324 */
325 if (board_is_bone() && !strncmp(board_ti_get_rev(), "00A1", 4))
326 return;
Tom Rini52437072013-08-30 16:28:46 -0400327
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530328 if (i2c_probe(TPS65217_CHIP_PM))
329 return;
Tom Rini52437072013-08-30 16:28:46 -0400330
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530331 /*
332 * On Beaglebone White we need to ensure we have AC power
333 * before increasing the frequency.
334 */
Lokesh Vutla6302e532017-05-05 12:59:10 +0530335 if (bone_not_connected_to_ac_power())
336 freq = MPUPLL_M_600;
Tom Rini52437072013-08-30 16:28:46 -0400337
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530338 /*
339 * Override what we have detected since we know if we have
340 * a Beaglebone Black it supports 1GHz.
341 */
342 if (board_is_bone_lt())
343 freq = MPUPLL_M_1000;
Tom Rini52437072013-08-30 16:28:46 -0400344
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530345 if (freq == MPUPLL_M_1000) {
346 usb_cur_lim = TPS65217_USB_INPUT_CUR_LIMIT_1800MA;
347 mpu_vdd = TPS65217_DCDC_VOLT_SEL_1325MV;
348 } else {
349 usb_cur_lim = TPS65217_USB_INPUT_CUR_LIMIT_1300MA;
350 mpu_vdd = TPS65217_DCDC_VOLT_SEL_1275MV;
351 }
Tom Rini52437072013-08-30 16:28:46 -0400352
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530353 switch (freq) {
354 case MPUPLL_M_1000:
355 mpu_vdd = TPS65217_DCDC_VOLT_SEL_1325MV;
356 usb_cur_lim = TPS65217_USB_INPUT_CUR_LIMIT_1800MA;
357 break;
358 case MPUPLL_M_800:
359 mpu_vdd = TPS65217_DCDC_VOLT_SEL_1275MV;
360 usb_cur_lim = TPS65217_USB_INPUT_CUR_LIMIT_1800MA;
361 break;
362 case MPUPLL_M_720:
363 mpu_vdd = TPS65217_DCDC_VOLT_SEL_1200MV;
364 usb_cur_lim = TPS65217_USB_INPUT_CUR_LIMIT_1800MA;
365 break;
366 case MPUPLL_M_600:
367 case MPUPLL_M_500:
368 case MPUPLL_M_300:
369 mpu_vdd = TPS65217_DCDC_VOLT_SEL_1100MV;
370 usb_cur_lim = TPS65217_USB_INPUT_CUR_LIMIT_1300MA;
371 break;
372 }
Steve Kipisz5adac352013-08-14 10:51:31 -0400373
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530374 if (tps65217_reg_write(TPS65217_PROT_LEVEL_NONE,
375 TPS65217_POWER_PATH,
376 usb_cur_lim,
377 TPS65217_USB_INPUT_CUR_LIMIT_MASK))
378 puts("tps65217_reg_write failure\n");
Tom Rini52437072013-08-30 16:28:46 -0400379
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530380 /* Set DCDC3 (CORE) voltage to 1.10V */
381 if (tps65217_voltage_update(TPS65217_DEFDCDC3,
382 TPS65217_DCDC_VOLT_SEL_1100MV)) {
383 puts("tps65217_voltage_update failure\n");
384 return;
385 }
Tom Rini52437072013-08-30 16:28:46 -0400386
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530387 /* Set DCDC2 (MPU) voltage */
388 if (tps65217_voltage_update(TPS65217_DEFDCDC2, mpu_vdd)) {
389 puts("tps65217_voltage_update failure\n");
390 return;
391 }
Tom Rini52437072013-08-30 16:28:46 -0400392
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530393 /*
394 * Set LDO3, LDO4 output voltage to 3.3V for Beaglebone.
395 * Set LDO3 to 1.8V and LDO4 to 3.3V for Beaglebone Black.
396 */
397 if (board_is_bone()) {
Tom Rini52437072013-08-30 16:28:46 -0400398 if (tps65217_reg_write(TPS65217_PROT_LEVEL_2,
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530399 TPS65217_DEFLS1,
Tom Rini52437072013-08-30 16:28:46 -0400400 TPS65217_LDO_VOLTAGE_OUT_3_3,
401 TPS65217_LDO_MASK))
402 puts("tps65217_reg_write failure\n");
403 } else {
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530404 if (tps65217_reg_write(TPS65217_PROT_LEVEL_2,
405 TPS65217_DEFLS1,
406 TPS65217_LDO_VOLTAGE_OUT_1_8,
407 TPS65217_LDO_MASK))
408 puts("tps65217_reg_write failure\n");
409 }
Tom Rini52437072013-08-30 16:28:46 -0400410
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530411 if (tps65217_reg_write(TPS65217_PROT_LEVEL_2,
412 TPS65217_DEFLS2,
413 TPS65217_LDO_VOLTAGE_OUT_3_3,
414 TPS65217_LDO_MASK))
415 puts("tps65217_reg_write failure\n");
416}
Tom Rini52437072013-08-30 16:28:46 -0400417
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530418void scale_vcores_generic(int freq)
419{
420 int sil_rev, mpu_vdd;
Tom Rini52437072013-08-30 16:28:46 -0400421
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530422 /*
423 * The GP EVM, IDK and EVM SK use a TPS65910 PMIC. For all
424 * MPU frequencies we support we use a CORE voltage of
425 * 1.10V. For MPU voltage we need to switch based on
426 * the frequency we are running at.
427 */
428 if (i2c_probe(TPS65910_CTRL_I2C_ADDR))
429 return;
Tom Rini52437072013-08-30 16:28:46 -0400430
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530431 /*
432 * Depending on MPU clock and PG we will need a different
433 * VDD to drive at that speed.
434 */
435 sil_rev = readl(&cdev->deviceid) >> 28;
436 mpu_vdd = am335x_get_tps65910_mpu_vdd(sil_rev, freq);
Tom Rini52437072013-08-30 16:28:46 -0400437
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530438 /* Tell the TPS65910 to use i2c */
439 tps65910_set_i2c_control();
Steve Kipisz5adac352013-08-14 10:51:31 -0400440
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530441 /* First update MPU voltage. */
442 if (tps65910_voltage_update(MPU, mpu_vdd))
443 return;
Tom Rini52437072013-08-30 16:28:46 -0400444
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530445 /* Second, update the CORE voltage. */
446 if (tps65910_voltage_update(CORE, TPS65910_OP_REG_SEL_1_1_0))
447 return;
448
Tom Rini52437072013-08-30 16:28:46 -0400449}
450
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530451void gpi2c_init(void)
Lokesh Vutla89a83bf2013-07-30 10:48:52 +0530452{
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530453 /* When needed to be invoked prior to BSS initialization */
454 static bool first_time = true;
455
456 if (first_time) {
457 enable_i2c0_pin_mux();
458 i2c_init(CONFIG_SYS_OMAP24_I2C_SPEED,
459 CONFIG_SYS_OMAP24_I2C_SLAVE);
460 first_time = false;
461 }
462}
463
464void scale_vcores(void)
465{
466 int freq;
467
468 gpi2c_init();
469 freq = am335x_get_efuse_mpu_max_freq(cdev);
470
471 if (board_is_bone())
472 scale_vcores_bone(freq);
Lokesh Vutla89a83bf2013-07-30 10:48:52 +0530473 else
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530474 scale_vcores_generic(freq);
Lokesh Vutla89a83bf2013-07-30 10:48:52 +0530475}
476
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530477void set_uart_mux_conf(void)
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000478{
Tom Rini986d7552014-08-01 09:53:24 -0400479#if CONFIG_CONS_INDEX == 1
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000480 enable_uart0_pin_mux();
Tom Rini986d7552014-08-01 09:53:24 -0400481#elif CONFIG_CONS_INDEX == 2
Andrew Bradford65c51ff2012-10-25 08:21:30 -0400482 enable_uart1_pin_mux();
Tom Rini986d7552014-08-01 09:53:24 -0400483#elif CONFIG_CONS_INDEX == 3
Andrew Bradford65c51ff2012-10-25 08:21:30 -0400484 enable_uart2_pin_mux();
Tom Rini986d7552014-08-01 09:53:24 -0400485#elif CONFIG_CONS_INDEX == 4
Andrew Bradford65c51ff2012-10-25 08:21:30 -0400486 enable_uart3_pin_mux();
Tom Rini986d7552014-08-01 09:53:24 -0400487#elif CONFIG_CONS_INDEX == 5
Andrew Bradford65c51ff2012-10-25 08:21:30 -0400488 enable_uart4_pin_mux();
Tom Rini986d7552014-08-01 09:53:24 -0400489#elif CONFIG_CONS_INDEX == 6
Andrew Bradford65c51ff2012-10-25 08:21:30 -0400490 enable_uart5_pin_mux();
Tom Rini986d7552014-08-01 09:53:24 -0400491#endif
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530492}
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000493
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530494void set_mux_conf_regs(void)
495{
Nishanth Menon2afa70d2016-02-24 12:30:55 -0600496 enable_board_pin_mux();
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530497}
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000498
Lokesh Vutla303b2672013-12-10 15:02:21 +0530499const struct ctrl_ioregs ioregs_evmsk = {
500 .cm0ioctl = MT41J128MJT125_IOCTRL_VALUE,
501 .cm1ioctl = MT41J128MJT125_IOCTRL_VALUE,
502 .cm2ioctl = MT41J128MJT125_IOCTRL_VALUE,
503 .dt0ioctl = MT41J128MJT125_IOCTRL_VALUE,
504 .dt1ioctl = MT41J128MJT125_IOCTRL_VALUE,
505};
506
507const struct ctrl_ioregs ioregs_bonelt = {
508 .cm0ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
509 .cm1ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
510 .cm2ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
511 .dt0ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
512 .dt1ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
513};
514
515const struct ctrl_ioregs ioregs_evm15 = {
516 .cm0ioctl = MT41J512M8RH125_IOCTRL_VALUE,
517 .cm1ioctl = MT41J512M8RH125_IOCTRL_VALUE,
518 .cm2ioctl = MT41J512M8RH125_IOCTRL_VALUE,
519 .dt0ioctl = MT41J512M8RH125_IOCTRL_VALUE,
520 .dt1ioctl = MT41J512M8RH125_IOCTRL_VALUE,
521};
522
523const struct ctrl_ioregs ioregs = {
524 .cm0ioctl = MT47H128M16RT25E_IOCTRL_VALUE,
525 .cm1ioctl = MT47H128M16RT25E_IOCTRL_VALUE,
526 .cm2ioctl = MT47H128M16RT25E_IOCTRL_VALUE,
527 .dt0ioctl = MT47H128M16RT25E_IOCTRL_VALUE,
528 .dt1ioctl = MT47H128M16RT25E_IOCTRL_VALUE,
529};
530
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530531void sdram_init(void)
532{
Nishanth Menon2afa70d2016-02-24 12:30:55 -0600533 if (board_is_evm_sk()) {
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000534 /*
535 * EVM SK 1.2A and later use gpio0_7 to enable DDR3.
536 * This is safe enough to do on older revs.
537 */
538 gpio_request(GPIO_DDR_VTT_EN, "ddr_vtt_en");
539 gpio_direction_output(GPIO_DDR_VTT_EN, 1);
540 }
541
Lokesh Vutla5837b902016-05-16 11:47:24 +0530542 if (board_is_icev2()) {
543 gpio_request(ICE_GPIO_DDR_VTT_EN, "ddr_vtt_en");
544 gpio_direction_output(ICE_GPIO_DDR_VTT_EN, 1);
545 }
546
Nishanth Menon2afa70d2016-02-24 12:30:55 -0600547 if (board_is_evm_sk())
Lokesh Vutla303b2672013-12-10 15:02:21 +0530548 config_ddr(303, &ioregs_evmsk, &ddr3_data,
Matt Porter65991ec2013-03-15 10:07:03 +0000549 &ddr3_cmd_ctrl_data, &ddr3_emif_reg_data, 0);
Nishanth Menon2afa70d2016-02-24 12:30:55 -0600550 else if (board_is_bone_lt())
Lokesh Vutla303b2672013-12-10 15:02:21 +0530551 config_ddr(400, &ioregs_bonelt,
Tom Rini385bc752013-03-21 04:30:02 +0000552 &ddr3_beagleblack_data,
553 &ddr3_beagleblack_cmd_ctrl_data,
554 &ddr3_beagleblack_emif_reg_data, 0);
Nishanth Menon2afa70d2016-02-24 12:30:55 -0600555 else if (board_is_evm_15_or_later())
Lokesh Vutla303b2672013-12-10 15:02:21 +0530556 config_ddr(303, &ioregs_evm15, &ddr3_evm_data,
Matt Porter65991ec2013-03-15 10:07:03 +0000557 &ddr3_evm_cmd_ctrl_data, &ddr3_evm_emif_reg_data, 0);
Lokesh Vutla5837b902016-05-16 11:47:24 +0530558 else if (board_is_icev2())
559 config_ddr(400, &ioregs_evmsk, &ddr3_icev2_data,
560 &ddr3_icev2_cmd_ctrl_data, &ddr3_icev2_emif_reg_data,
561 0);
Jyri Sarha8d2998b2016-12-09 12:29:13 +0200562 else if (board_is_gp_evm())
563 config_ddr(266, &ioregs, &ddr2_data,
564 &ddr2_cmd_ctrl_data, &ddr2_evm_emif_reg_data, 0);
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000565 else
Lokesh Vutla303b2672013-12-10 15:02:21 +0530566 config_ddr(266, &ioregs, &ddr2_data,
Matt Porter65991ec2013-03-15 10:07:03 +0000567 &ddr2_cmd_ctrl_data, &ddr2_emif_reg_data, 0);
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000568}
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530569#endif
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000570
Roger Quadrosbcb4ee82016-08-24 15:35:50 +0300571#if !defined(CONFIG_SPL_BUILD) || \
Lokesh Vutla0d144f52016-05-16 11:47:26 +0530572 (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD))
Roger Quadrosbcb4ee82016-08-24 15:35:50 +0300573static void request_and_set_gpio(int gpio, char *name, int val)
Lokesh Vutla0d144f52016-05-16 11:47:26 +0530574{
575 int ret;
576
577 ret = gpio_request(gpio, name);
578 if (ret < 0) {
579 printf("%s: Unable to request %s\n", __func__, name);
580 return;
581 }
582
583 ret = gpio_direction_output(gpio, 0);
584 if (ret < 0) {
585 printf("%s: Unable to set %s as output\n", __func__, name);
586 goto err_free_gpio;
587 }
588
Roger Quadrosbcb4ee82016-08-24 15:35:50 +0300589 gpio_set_value(gpio, val);
Lokesh Vutla0d144f52016-05-16 11:47:26 +0530590
591 return;
592
593err_free_gpio:
594 gpio_free(gpio);
595}
596
Roger Quadrosbcb4ee82016-08-24 15:35:50 +0300597#define REQUEST_AND_SET_GPIO(N) request_and_set_gpio(N, #N, 1);
598#define REQUEST_AND_CLR_GPIO(N) request_and_set_gpio(N, #N, 0);
Lokesh Vutla0d144f52016-05-16 11:47:26 +0530599
600/**
601 * RMII mode on ICEv2 board needs 50MHz clock. Given the clock
602 * synthesizer With a capacitor of 18pF, and 25MHz input clock cycle
603 * PLL1 gives an output of 100MHz. So, configuring the div2/3 as 2 to
604 * give 50MHz output for Eth0 and 1.
605 */
606static struct clk_synth cdce913_data = {
607 .id = 0x81,
608 .capacitor = 0x90,
609 .mux = 0x6d,
610 .pdiv2 = 0x2,
611 .pdiv3 = 0x2,
612};
613#endif
614
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000615/*
616 * Basic board specific setup. Pinmux has been handled already.
617 */
618int board_init(void)
619{
Tom Rini303bfe82013-10-01 12:32:04 -0400620#if defined(CONFIG_HW_WATCHDOG)
621 hw_watchdog_init();
622#endif
623
Tom Rinif3b6a1d2013-08-09 11:22:13 -0400624 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
pekon gupta53b4b322013-11-18 19:03:02 +0530625#if defined(CONFIG_NOR) || defined(CONFIG_NAND)
Ilya Yanok3d9725e2012-11-06 13:06:31 +0000626 gpmc_init();
Steve Kipiszbe9b6f82013-07-18 15:13:03 -0400627#endif
Lokesh Vutla0d144f52016-05-16 11:47:26 +0530628
Roger Quadrosbcb4ee82016-08-24 15:35:50 +0300629#if !defined(CONFIG_SPL_BUILD) || \
630 (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD))
Lokesh Vutla0d144f52016-05-16 11:47:26 +0530631 if (board_is_icev2()) {
Roger Quadrosbcb4ee82016-08-24 15:35:50 +0300632 int rv;
633 u32 reg;
634
Lokesh Vutla0d144f52016-05-16 11:47:26 +0530635 REQUEST_AND_SET_GPIO(GPIO_PR1_MII_CTRL);
Roger Quadrosbcb4ee82016-08-24 15:35:50 +0300636 /* Make J19 status available on GPIO1_26 */
637 REQUEST_AND_CLR_GPIO(GPIO_MUX_MII_CTRL);
638
Lokesh Vutla0d144f52016-05-16 11:47:26 +0530639 REQUEST_AND_SET_GPIO(GPIO_FET_SWITCH_CTRL);
Roger Quadrosbcb4ee82016-08-24 15:35:50 +0300640 /*
641 * Both ports can be set as RMII-CPSW or MII-PRU-ETH using
642 * jumpers near the port. Read the jumper value and set
643 * the pinmux, external mux and PHY clock accordingly.
644 * As jumper line is overridden by PHY RX_DV pin immediately
645 * after bootstrap (power-up/reset), we need to sample
646 * it during PHY reset using GPIO rising edge detection.
647 */
Lokesh Vutla0d144f52016-05-16 11:47:26 +0530648 REQUEST_AND_SET_GPIO(GPIO_PHY_RESET);
Roger Quadrosbcb4ee82016-08-24 15:35:50 +0300649 /* Enable rising edge IRQ on GPIO0_11 and GPIO 1_26 */
650 reg = readl(GPIO0_RISINGDETECT) | BIT(11);
651 writel(reg, GPIO0_RISINGDETECT);
652 reg = readl(GPIO1_RISINGDETECT) | BIT(26);
653 writel(reg, GPIO1_RISINGDETECT);
654 /* Reset PHYs to capture the Jumper setting */
655 gpio_set_value(GPIO_PHY_RESET, 0);
656 udelay(2); /* PHY datasheet states 1uS min. */
657 gpio_set_value(GPIO_PHY_RESET, 1);
658
659 reg = readl(GPIO0_IRQSTATUSRAW) & BIT(11);
660 if (reg) {
661 writel(reg, GPIO0_IRQSTATUS1); /* clear irq */
662 /* RMII mode */
663 printf("ETH0, CPSW\n");
664 } else {
665 /* MII mode */
666 printf("ETH0, PRU\n");
667 cdce913_data.pdiv3 = 4; /* 25MHz PHY clk */
668 }
669
670 reg = readl(GPIO1_IRQSTATUSRAW) & BIT(26);
671 if (reg) {
672 writel(reg, GPIO1_IRQSTATUS1); /* clear irq */
673 /* RMII mode */
674 printf("ETH1, CPSW\n");
675 gpio_set_value(GPIO_MUX_MII_CTRL, 1);
676 } else {
677 /* MII mode */
678 printf("ETH1, PRU\n");
679 cdce913_data.pdiv2 = 4; /* 25MHz PHY clk */
680 }
681
682 /* disable rising edge IRQs */
683 reg = readl(GPIO0_RISINGDETECT) & ~BIT(11);
684 writel(reg, GPIO0_RISINGDETECT);
685 reg = readl(GPIO1_RISINGDETECT) & ~BIT(26);
686 writel(reg, GPIO1_RISINGDETECT);
Lokesh Vutla0d144f52016-05-16 11:47:26 +0530687
688 rv = setup_clock_synthesizer(&cdce913_data);
689 if (rv) {
690 printf("Clock synthesizer setup failed %d\n", rv);
691 return rv;
692 }
Roger Quadrosbcb4ee82016-08-24 15:35:50 +0300693
694 /* reset PHYs */
695 gpio_set_value(GPIO_PHY_RESET, 0);
696 udelay(2); /* PHY datasheet states 1uS min. */
697 gpio_set_value(GPIO_PHY_RESET, 1);
Lokesh Vutla0d144f52016-05-16 11:47:26 +0530698 }
699#endif
700
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000701 return 0;
702}
703
Tom Rini40271852012-10-24 07:28:17 +0000704#ifdef CONFIG_BOARD_LATE_INIT
705int board_late_init(void)
706{
Roger Quadros7c9d3782016-08-24 15:35:51 +0300707#if !defined(CONFIG_SPL_BUILD)
708 uint8_t mac_addr[6];
709 uint32_t mac_hi, mac_lo;
710#endif
711
Tom Rini40271852012-10-24 07:28:17 +0000712#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
Nishanth Menon2afa70d2016-02-24 12:30:55 -0600713 char *name = NULL;
Tom Rini4021fd92013-07-18 15:13:01 -0400714
robertcnelson@gmail.comc5d7d222017-03-30 14:29:52 -0500715 if (board_is_bone_lt()) {
716 /* BeagleBoard.org BeagleBone Black Wireless: */
717 if (!strncmp(board_ti_get_rev(), "BWA", 3)) {
718 name = "BBBW";
719 }
robertcnelson@gmail.comb55cd7a2017-03-30 14:29:53 -0500720 /* SeeedStudio BeagleBone Green Wireless */
721 if (!strncmp(board_ti_get_rev(), "GW1", 3)) {
722 name = "BBGW";
723 }
robertcnelson@gmail.com89ef1d62017-03-30 14:29:54 -0500724 /* BeagleBoard.org BeagleBone Blue */
725 if (!strncmp(board_ti_get_rev(), "BLA", 3)) {
726 name = "BBBL";
727 }
robertcnelson@gmail.comc5d7d222017-03-30 14:29:52 -0500728 }
729
Nishanth Menon2afa70d2016-02-24 12:30:55 -0600730 if (board_is_bbg1())
731 name = "BBG1";
732 set_board_info_env(name);
Lokesh Vutla1eb0f542016-11-29 11:58:03 +0530733
734 /*
735 * Default FIT boot on HS devices. Non FIT images are not allowed
736 * on HS devices.
737 */
738 if (get_device_type() == HS_DEVICE)
739 setenv("boot_fit", "1");
Tom Rini40271852012-10-24 07:28:17 +0000740#endif
741
Roger Quadros7c9d3782016-08-24 15:35:51 +0300742#if !defined(CONFIG_SPL_BUILD)
743 /* try reading mac address from efuse */
744 mac_lo = readl(&cdev->macid0l);
745 mac_hi = readl(&cdev->macid0h);
746 mac_addr[0] = mac_hi & 0xFF;
747 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
748 mac_addr[2] = (mac_hi & 0xFF0000) >> 16;
749 mac_addr[3] = (mac_hi & 0xFF000000) >> 24;
750 mac_addr[4] = mac_lo & 0xFF;
751 mac_addr[5] = (mac_lo & 0xFF00) >> 8;
752
753 if (!getenv("ethaddr")) {
754 printf("<ethaddr> not set. Validating first E-fuse MAC\n");
755
756 if (is_valid_ethaddr(mac_addr))
757 eth_setenv_enetaddr("ethaddr", mac_addr);
758 }
759
760 mac_lo = readl(&cdev->macid1l);
761 mac_hi = readl(&cdev->macid1h);
762 mac_addr[0] = mac_hi & 0xFF;
763 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
764 mac_addr[2] = (mac_hi & 0xFF0000) >> 16;
765 mac_addr[3] = (mac_hi & 0xFF000000) >> 24;
766 mac_addr[4] = mac_lo & 0xFF;
767 mac_addr[5] = (mac_lo & 0xFF00) >> 8;
768
769 if (!getenv("eth1addr")) {
770 if (is_valid_ethaddr(mac_addr))
771 eth_setenv_enetaddr("eth1addr", mac_addr);
772 }
773#endif
774
Tom Rini40271852012-10-24 07:28:17 +0000775 return 0;
776}
777#endif
778
Mugunthan V Ndf7a99f2015-09-07 14:22:18 +0530779#ifndef CONFIG_DM_ETH
780
Ilya Yanok0760a0d2013-02-05 11:36:26 +0000781#if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) || \
782 (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD))
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000783static void cpsw_control(int enabled)
784{
785 /* VTP can be added here */
786
787 return;
788}
789
790static struct cpsw_slave_data cpsw_slaves[] = {
791 {
792 .slave_reg_ofs = 0x208,
793 .sliver_reg_ofs = 0xd80,
Mugunthan V N4944f372014-02-18 07:31:52 -0500794 .phy_addr = 0,
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000795 },
796 {
797 .slave_reg_ofs = 0x308,
798 .sliver_reg_ofs = 0xdc0,
Mugunthan V N4944f372014-02-18 07:31:52 -0500799 .phy_addr = 1,
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000800 },
801};
802
803static struct cpsw_platform_data cpsw_data = {
Matt Portere24646f2013-03-15 10:07:02 +0000804 .mdio_base = CPSW_MDIO_BASE,
805 .cpsw_base = CPSW_BASE,
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000806 .mdio_div = 0xff,
807 .channels = 8,
808 .cpdma_reg_ofs = 0x800,
809 .slaves = 1,
810 .slave_data = cpsw_slaves,
811 .ale_reg_ofs = 0xd00,
812 .ale_entries = 1024,
813 .host_port_reg_ofs = 0x108,
814 .hw_stats_reg_ofs = 0x900,
Mugunthan V Nff559872013-07-08 16:04:37 +0530815 .bd_ram_ofs = 0x2000,
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000816 .mac_control = (1 << 5),
817 .control = cpsw_control,
818 .host_port_num = 0,
819 .version = CPSW_CTRL_VERSION_2,
820};
Ilya Yanok44a2c072012-11-06 13:48:24 +0000821#endif
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000822
Lokesh Vutla0d144f52016-05-16 11:47:26 +0530823#if ((defined(CONFIG_SPL_ETH_SUPPORT) || defined(CONFIG_SPL_USBETH_SUPPORT)) &&\
824 defined(CONFIG_SPL_BUILD)) || \
825 ((defined(CONFIG_DRIVER_TI_CPSW) || \
826 defined(CONFIG_USB_ETHER) && defined(CONFIG_MUSB_GADGET)) && \
827 !defined(CONFIG_SPL_BUILD))
828
Tom Rini60fcaaa2014-03-26 15:53:12 -0400829/*
830 * This function will:
831 * Read the eFuse for MAC addresses, and set ethaddr/eth1addr/usbnet_devaddr
832 * in the environment
833 * Perform fixups to the PHY present on certain boards. We only need this
834 * function in:
835 * - SPL with either CPSW or USB ethernet support
836 * - Full U-Boot, with either CPSW or USB ethernet
837 * Build in only these cases to avoid warnings about unused variables
838 * when we build an SPL that has neither option but full U-Boot will.
839 */
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000840int board_eth_init(bd_t *bis)
841{
Ilya Yanok44a2c072012-11-06 13:48:24 +0000842 int rv, n = 0;
Roger Quadros7c9d3782016-08-24 15:35:51 +0300843#if defined(CONFIG_USB_ETHER) && \
844 (!defined(CONFIG_SPL_BUILD) || defined(CONFIG_SPL_USBETH_SUPPORT))
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000845 uint8_t mac_addr[6];
846 uint32_t mac_hi, mac_lo;
847
Roger Quadros7c9d3782016-08-24 15:35:51 +0300848 /*
849 * use efuse mac address for USB ethernet as we know that
850 * both CPSW and USB ethernet will never be active at the same time
851 */
Ilya Yanok0760a0d2013-02-05 11:36:26 +0000852 mac_lo = readl(&cdev->macid0l);
853 mac_hi = readl(&cdev->macid0h);
854 mac_addr[0] = mac_hi & 0xFF;
855 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
856 mac_addr[2] = (mac_hi & 0xFF0000) >> 16;
857 mac_addr[3] = (mac_hi & 0xFF000000) >> 24;
858 mac_addr[4] = mac_lo & 0xFF;
859 mac_addr[5] = (mac_lo & 0xFF00) >> 8;
Roger Quadros7c9d3782016-08-24 15:35:51 +0300860#endif
861
Ilya Yanok0760a0d2013-02-05 11:36:26 +0000862
863#if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) || \
864 (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD))
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000865
Joel A Fernandesf7488542013-05-07 05:52:55 +0000866#ifdef CONFIG_DRIVER_TI_CPSW
Nishanth Menon2afa70d2016-02-24 12:30:55 -0600867 if (board_is_bone() || board_is_bone_lt() ||
868 board_is_idk()) {
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000869 writel(MII_MODE_ENABLE, &cdev->miisel);
870 cpsw_slaves[0].phy_if = cpsw_slaves[1].phy_if =
871 PHY_INTERFACE_MODE_MII;
Lokesh Vutla0d144f52016-05-16 11:47:26 +0530872 } else if (board_is_icev2()) {
873 writel(RMII_MODE_ENABLE | RMII_CHIPCKL_ENABLE, &cdev->miisel);
874 cpsw_slaves[0].phy_if = PHY_INTERFACE_MODE_RMII;
875 cpsw_slaves[1].phy_if = PHY_INTERFACE_MODE_RMII;
876 cpsw_slaves[0].phy_addr = 1;
877 cpsw_slaves[1].phy_addr = 3;
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000878 } else {
Heiko Schocherc4fea292013-08-19 16:38:56 +0200879 writel((RGMII_MODE_ENABLE | RGMII_INT_DELAY), &cdev->miisel);
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000880 cpsw_slaves[0].phy_if = cpsw_slaves[1].phy_if =
881 PHY_INTERFACE_MODE_RGMII;
882 }
883
Ilya Yanok44a2c072012-11-06 13:48:24 +0000884 rv = cpsw_register(&cpsw_data);
885 if (rv < 0)
886 printf("Error %d registering CPSW switch\n", rv);
887 else
888 n += rv;
Joel A Fernandesf7488542013-05-07 05:52:55 +0000889#endif
Tom Rini183943d2013-02-12 14:59:23 -0500890
891 /*
892 *
893 * CPSW RGMII Internal Delay Mode is not supported in all PVT
894 * operating points. So we must set the TX clock delay feature
895 * in the AR8051 PHY. Since we only support a single ethernet
896 * device in U-Boot, we only do this for the first instance.
897 */
898#define AR8051_PHY_DEBUG_ADDR_REG 0x1d
899#define AR8051_PHY_DEBUG_DATA_REG 0x1e
900#define AR8051_DEBUG_RGMII_CLK_DLY_REG 0x5
901#define AR8051_RGMII_TX_CLK_DLY 0x100
902
Nishanth Menon2afa70d2016-02-24 12:30:55 -0600903 if (board_is_evm_sk() || board_is_gp_evm()) {
Tom Rini183943d2013-02-12 14:59:23 -0500904 const char *devname;
905 devname = miiphy_get_current_dev();
906
907 miiphy_write(devname, 0x0, AR8051_PHY_DEBUG_ADDR_REG,
908 AR8051_DEBUG_RGMII_CLK_DLY_REG);
909 miiphy_write(devname, 0x0, AR8051_PHY_DEBUG_DATA_REG,
910 AR8051_RGMII_TX_CLK_DLY);
911 }
Ilya Yanok44a2c072012-11-06 13:48:24 +0000912#endif
Ilya Yanok0760a0d2013-02-05 11:36:26 +0000913#if defined(CONFIG_USB_ETHER) && \
914 (!defined(CONFIG_SPL_BUILD) || defined(CONFIG_SPL_USBETH_SUPPORT))
Joe Hershberger8ecdbed2015-04-08 01:41:04 -0500915 if (is_valid_ethaddr(mac_addr))
Ilya Yanok0760a0d2013-02-05 11:36:26 +0000916 eth_setenv_enetaddr("usbnet_devaddr", mac_addr);
917
Ilya Yanok44a2c072012-11-06 13:48:24 +0000918 rv = usb_eth_initialize(bis);
919 if (rv < 0)
920 printf("Error %d registering USB_ETHER\n", rv);
921 else
922 n += rv;
923#endif
924 return n;
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000925}
926#endif
Mugunthan V Ndf7a99f2015-09-07 14:22:18 +0530927
928#endif /* CONFIG_DM_ETH */
Lokesh Vutla89b9f302016-05-16 11:24:24 +0530929
930#ifdef CONFIG_SPL_LOAD_FIT
931int board_fit_config_name_match(const char *name)
932{
933 if (board_is_gp_evm() && !strcmp(name, "am335x-evm"))
934 return 0;
935 else if (board_is_bone() && !strcmp(name, "am335x-bone"))
936 return 0;
937 else if (board_is_bone_lt() && !strcmp(name, "am335x-boneblack"))
938 return 0;
Lokesh Vutla5a954ba2016-05-16 11:24:28 +0530939 else if (board_is_evm_sk() && !strcmp(name, "am335x-evmsk"))
940 return 0;
Lokesh Vutla1edfcaf2016-05-16 11:24:29 +0530941 else if (board_is_bbg1() && !strcmp(name, "am335x-bonegreen"))
942 return 0;
Lokesh Vutla7ecf1962016-05-16 11:47:28 +0530943 else if (board_is_icev2() && !strcmp(name, "am335x-icev2"))
944 return 0;
Lokesh Vutla89b9f302016-05-16 11:24:24 +0530945 else
946 return -1;
947}
948#endif
Andrew F. Davisbd249152016-08-30 14:06:24 -0500949
950#ifdef CONFIG_TI_SECURE_DEVICE
951void board_fit_image_post_process(void **p_image, size_t *p_size)
952{
953 secure_boot_verify_image(p_image, p_size);
954}
955#endif
Lokesh Vutla2fe7c792017-04-26 13:37:08 +0530956
957#if !CONFIG_IS_ENABLED(OF_CONTROL)
958static const struct omap_hsmmc_plat am335x_mmc0_platdata = {
959 .base_addr = (struct hsmmc *)OMAP_HSMMC1_BASE,
960 .cfg.host_caps = MMC_MODE_HS_52MHz | MMC_MODE_HS | MMC_MODE_4BIT,
961 .cfg.f_min = 400000,
962 .cfg.f_max = 52000000,
963 .cfg.voltages = MMC_VDD_32_33 | MMC_VDD_33_34 | MMC_VDD_165_195,
964 .cfg.b_max = CONFIG_SYS_MMC_MAX_BLK_COUNT,
965};
966
967U_BOOT_DEVICE(am335x_mmc0) = {
968 .name = "omap_hsmmc",
969 .platdata = &am335x_mmc0_platdata,
970};
971
972static const struct omap_hsmmc_plat am335x_mmc1_platdata = {
973 .base_addr = (struct hsmmc *)OMAP_HSMMC2_BASE,
974 .cfg.host_caps = MMC_MODE_HS_52MHz | MMC_MODE_HS | MMC_MODE_8BIT,
975 .cfg.f_min = 400000,
976 .cfg.f_max = 52000000,
977 .cfg.voltages = MMC_VDD_32_33 | MMC_VDD_33_34 | MMC_VDD_165_195,
978 .cfg.b_max = CONFIG_SYS_MMC_MAX_BLK_COUNT,
979};
980
981U_BOOT_DEVICE(am335x_mmc1) = {
982 .name = "omap_hsmmc",
983 .platdata = &am335x_mmc1_platdata,
984};
985#endif