blob: 01b28e8da46b31fffce2cfe8ab821dd835a88ace [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Peter Korsgaard85ec2db2012-10-18 01:21:09 +00002/*
3 * board.c
4 *
5 * Board functions for TI AM335X based boards
6 *
7 * Copyright (C) 2011, Texas Instruments, Incorporated - http://www.ti.com/
Peter Korsgaard85ec2db2012-10-18 01:21:09 +00008 */
9
10#include <common.h>
Lokesh Vutla2fe7c792017-04-26 13:37:08 +053011#include <dm.h>
Simon Glass79fd2142019-08-01 09:46:43 -060012#include <env.h>
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000013#include <errno.h>
Simon Glassa7b51302019-11-14 12:57:46 -070014#include <init.h>
Simon Glass9bc15642020-02-03 07:36:16 -070015#include <malloc.h>
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000016#include <spl.h>
Lokesh Vutlaabb44e62016-05-16 11:47:29 +053017#include <serial.h>
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000018#include <asm/arch/cpu.h>
19#include <asm/arch/hardware.h>
20#include <asm/arch/omap.h>
21#include <asm/arch/ddr_defs.h>
22#include <asm/arch/clock.h>
Lokesh Vutla0d144f52016-05-16 11:47:26 +053023#include <asm/arch/clk_synthesizer.h>
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000024#include <asm/arch/gpio.h>
25#include <asm/arch/mmc_host_def.h>
26#include <asm/arch/sys_proto.h>
Steve Kipiszbe9b6f82013-07-18 15:13:03 -040027#include <asm/arch/mem.h>
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000028#include <asm/io.h>
29#include <asm/emif.h>
30#include <asm/gpio.h>
Semen Protsenkoa8cb0222017-06-02 18:00:00 +030031#include <asm/omap_common.h>
Andrew F. Davisbd249152016-08-30 14:06:24 -050032#include <asm/omap_sec_common.h>
Lokesh Vutla2fe7c792017-04-26 13:37:08 +053033#include <asm/omap_mmc.h>
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000034#include <i2c.h>
35#include <miiphy.h>
36#include <cpsw.h>
Tom Rini52437072013-08-30 16:28:46 -040037#include <power/tps65217.h>
38#include <power/tps65910.h>
Simon Glass9d1f6192019-08-02 09:44:25 -060039#include <env_internal.h>
Tom Rini303bfe82013-10-01 12:32:04 -040040#include <watchdog.h>
Nishanth Menon2afa70d2016-02-24 12:30:55 -060041#include "../common/board_detect.h"
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000042#include "board.h"
43
44DECLARE_GLOBAL_DATA_PTR;
45
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000046/* GPIO that controls power to DDR on EVM-SK */
Lokesh Vutla0d144f52016-05-16 11:47:26 +053047#define GPIO_TO_PIN(bank, gpio) (32 * (bank) + (gpio))
48#define GPIO_DDR_VTT_EN GPIO_TO_PIN(0, 7)
49#define ICE_GPIO_DDR_VTT_EN GPIO_TO_PIN(0, 18)
50#define GPIO_PR1_MII_CTRL GPIO_TO_PIN(3, 4)
51#define GPIO_MUX_MII_CTRL GPIO_TO_PIN(3, 10)
52#define GPIO_FET_SWITCH_CTRL GPIO_TO_PIN(0, 7)
53#define GPIO_PHY_RESET GPIO_TO_PIN(2, 5)
Roger Quadrosbcb4ee82016-08-24 15:35:50 +030054#define GPIO_ETH0_MODE GPIO_TO_PIN(0, 11)
55#define GPIO_ETH1_MODE GPIO_TO_PIN(1, 26)
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000056
57static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
58
Roger Quadrosbcb4ee82016-08-24 15:35:50 +030059#define GPIO0_RISINGDETECT (AM33XX_GPIO0_BASE + OMAP_GPIO_RISINGDETECT)
60#define GPIO1_RISINGDETECT (AM33XX_GPIO1_BASE + OMAP_GPIO_RISINGDETECT)
61
62#define GPIO0_IRQSTATUS1 (AM33XX_GPIO0_BASE + OMAP_GPIO_IRQSTATUS1)
63#define GPIO1_IRQSTATUS1 (AM33XX_GPIO1_BASE + OMAP_GPIO_IRQSTATUS1)
64
65#define GPIO0_IRQSTATUSRAW (AM33XX_GPIO0_BASE + 0x024)
66#define GPIO1_IRQSTATUSRAW (AM33XX_GPIO1_BASE + 0x024)
67
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000068/*
69 * Read header information from EEPROM into global structure.
70 */
Lokesh Vutla93e0f5b2016-10-14 10:35:25 +053071#ifdef CONFIG_TI_I2C_BOARD_DETECT
72void do_board_detect(void)
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000073{
Lokesh Vutla93e0f5b2016-10-14 10:35:25 +053074 enable_i2c0_pin_mux();
Jean-Jacques Hiblot52a51512018-12-07 14:50:49 +010075#ifndef CONFIG_DM_I2C
Lokesh Vutla93e0f5b2016-10-14 10:35:25 +053076 i2c_init(CONFIG_SYS_OMAP24_I2C_SPEED, CONFIG_SYS_OMAP24_I2C_SLAVE);
Jean-Jacques Hiblot52a51512018-12-07 14:50:49 +010077#endif
Simon Glass4df67572017-05-12 21:09:55 -060078 if (ti_i2c_eeprom_am_get(CONFIG_EEPROM_BUS_ADDRESS,
79 CONFIG_EEPROM_CHIP_ADDRESS))
Lokesh Vutla93e0f5b2016-10-14 10:35:25 +053080 printf("ti_i2c_eeprom_init failed\n");
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000081}
Lokesh Vutla93e0f5b2016-10-14 10:35:25 +053082#endif
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000083
Lokesh Vutlaabb44e62016-05-16 11:47:29 +053084#ifndef CONFIG_DM_SERIAL
85struct serial_device *default_serial_console(void)
86{
87 if (board_is_icev2())
88 return &eserial4_device;
89 else
90 return &eserial1_device;
91}
92#endif
93
Tom Rini8de09df2014-04-09 08:25:57 -040094#ifndef CONFIG_SKIP_LOWLEVEL_INIT
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +000095static const struct ddr_data ddr2_data = {
Tom Rini7f50a572014-07-07 21:40:16 -040096 .datardsratio0 = MT47H128M16RT25E_RD_DQS,
97 .datafwsratio0 = MT47H128M16RT25E_PHY_FIFO_WE,
98 .datawrsratio0 = MT47H128M16RT25E_PHY_WR_DATA,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +000099};
100
101static const struct cmd_control ddr2_cmd_ctrl_data = {
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000102 .cmd0csratio = MT47H128M16RT25E_RATIO,
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000103
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000104 .cmd1csratio = MT47H128M16RT25E_RATIO,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000105
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000106 .cmd2csratio = MT47H128M16RT25E_RATIO,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000107};
108
109static const struct emif_regs ddr2_emif_reg_data = {
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000110 .sdram_config = MT47H128M16RT25E_EMIF_SDCFG,
111 .ref_ctrl = MT47H128M16RT25E_EMIF_SDREF,
112 .sdram_tim1 = MT47H128M16RT25E_EMIF_TIM1,
113 .sdram_tim2 = MT47H128M16RT25E_EMIF_TIM2,
114 .sdram_tim3 = MT47H128M16RT25E_EMIF_TIM3,
115 .emif_ddr_phy_ctlr_1 = MT47H128M16RT25E_EMIF_READ_LATENCY,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000116};
117
Jyri Sarha8d2998b2016-12-09 12:29:13 +0200118static const struct emif_regs ddr2_evm_emif_reg_data = {
119 .sdram_config = MT47H128M16RT25E_EMIF_SDCFG,
120 .ref_ctrl = MT47H128M16RT25E_EMIF_SDREF,
121 .sdram_tim1 = MT47H128M16RT25E_EMIF_TIM1,
122 .sdram_tim2 = MT47H128M16RT25E_EMIF_TIM2,
123 .sdram_tim3 = MT47H128M16RT25E_EMIF_TIM3,
124 .ocp_config = EMIF_OCP_CONFIG_AM335X_EVM,
125 .emif_ddr_phy_ctlr_1 = MT47H128M16RT25E_EMIF_READ_LATENCY,
126};
127
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000128static const struct ddr_data ddr3_data = {
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000129 .datardsratio0 = MT41J128MJT125_RD_DQS,
130 .datawdsratio0 = MT41J128MJT125_WR_DQS,
131 .datafwsratio0 = MT41J128MJT125_PHY_FIFO_WE,
132 .datawrsratio0 = MT41J128MJT125_PHY_WR_DATA,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000133};
134
Tom Rini385bc752013-03-21 04:30:02 +0000135static const struct ddr_data ddr3_beagleblack_data = {
136 .datardsratio0 = MT41K256M16HA125E_RD_DQS,
137 .datawdsratio0 = MT41K256M16HA125E_WR_DQS,
138 .datafwsratio0 = MT41K256M16HA125E_PHY_FIFO_WE,
139 .datawrsratio0 = MT41K256M16HA125E_PHY_WR_DATA,
Tom Rini385bc752013-03-21 04:30:02 +0000140};
141
Jeff Lance7c03a222013-01-14 05:32:20 +0000142static const struct ddr_data ddr3_evm_data = {
143 .datardsratio0 = MT41J512M8RH125_RD_DQS,
144 .datawdsratio0 = MT41J512M8RH125_WR_DQS,
145 .datafwsratio0 = MT41J512M8RH125_PHY_FIFO_WE,
146 .datawrsratio0 = MT41J512M8RH125_PHY_WR_DATA,
Jeff Lance7c03a222013-01-14 05:32:20 +0000147};
148
Lokesh Vutla5837b902016-05-16 11:47:24 +0530149static const struct ddr_data ddr3_icev2_data = {
150 .datardsratio0 = MT41J128MJT125_RD_DQS_400MHz,
151 .datawdsratio0 = MT41J128MJT125_WR_DQS_400MHz,
152 .datafwsratio0 = MT41J128MJT125_PHY_FIFO_WE_400MHz,
153 .datawrsratio0 = MT41J128MJT125_PHY_WR_DATA_400MHz,
154};
155
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000156static const struct cmd_control ddr3_cmd_ctrl_data = {
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000157 .cmd0csratio = MT41J128MJT125_RATIO,
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000158 .cmd0iclkout = MT41J128MJT125_INVERT_CLKOUT,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000159
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000160 .cmd1csratio = MT41J128MJT125_RATIO,
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000161 .cmd1iclkout = MT41J128MJT125_INVERT_CLKOUT,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000162
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000163 .cmd2csratio = MT41J128MJT125_RATIO,
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000164 .cmd2iclkout = MT41J128MJT125_INVERT_CLKOUT,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000165};
166
Tom Rini385bc752013-03-21 04:30:02 +0000167static const struct cmd_control ddr3_beagleblack_cmd_ctrl_data = {
168 .cmd0csratio = MT41K256M16HA125E_RATIO,
Tom Rini385bc752013-03-21 04:30:02 +0000169 .cmd0iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
170
171 .cmd1csratio = MT41K256M16HA125E_RATIO,
Tom Rini385bc752013-03-21 04:30:02 +0000172 .cmd1iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
173
174 .cmd2csratio = MT41K256M16HA125E_RATIO,
Tom Rini385bc752013-03-21 04:30:02 +0000175 .cmd2iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
176};
177
Jeff Lance7c03a222013-01-14 05:32:20 +0000178static const struct cmd_control ddr3_evm_cmd_ctrl_data = {
179 .cmd0csratio = MT41J512M8RH125_RATIO,
Jeff Lance7c03a222013-01-14 05:32:20 +0000180 .cmd0iclkout = MT41J512M8RH125_INVERT_CLKOUT,
181
182 .cmd1csratio = MT41J512M8RH125_RATIO,
Jeff Lance7c03a222013-01-14 05:32:20 +0000183 .cmd1iclkout = MT41J512M8RH125_INVERT_CLKOUT,
184
185 .cmd2csratio = MT41J512M8RH125_RATIO,
Jeff Lance7c03a222013-01-14 05:32:20 +0000186 .cmd2iclkout = MT41J512M8RH125_INVERT_CLKOUT,
187};
188
Lokesh Vutla5837b902016-05-16 11:47:24 +0530189static const struct cmd_control ddr3_icev2_cmd_ctrl_data = {
190 .cmd0csratio = MT41J128MJT125_RATIO_400MHz,
191 .cmd0iclkout = MT41J128MJT125_INVERT_CLKOUT_400MHz,
192
193 .cmd1csratio = MT41J128MJT125_RATIO_400MHz,
194 .cmd1iclkout = MT41J128MJT125_INVERT_CLKOUT_400MHz,
195
196 .cmd2csratio = MT41J128MJT125_RATIO_400MHz,
197 .cmd2iclkout = MT41J128MJT125_INVERT_CLKOUT_400MHz,
198};
199
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000200static struct emif_regs ddr3_emif_reg_data = {
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000201 .sdram_config = MT41J128MJT125_EMIF_SDCFG,
202 .ref_ctrl = MT41J128MJT125_EMIF_SDREF,
203 .sdram_tim1 = MT41J128MJT125_EMIF_TIM1,
204 .sdram_tim2 = MT41J128MJT125_EMIF_TIM2,
205 .sdram_tim3 = MT41J128MJT125_EMIF_TIM3,
206 .zq_config = MT41J128MJT125_ZQ_CFG,
Vaibhav Hiremathc30d57b2013-03-14 21:11:16 +0000207 .emif_ddr_phy_ctlr_1 = MT41J128MJT125_EMIF_READ_LATENCY |
208 PHY_EN_DYN_PWRDN,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000209};
Jeff Lance7c03a222013-01-14 05:32:20 +0000210
Tom Rini385bc752013-03-21 04:30:02 +0000211static struct emif_regs ddr3_beagleblack_emif_reg_data = {
212 .sdram_config = MT41K256M16HA125E_EMIF_SDCFG,
213 .ref_ctrl = MT41K256M16HA125E_EMIF_SDREF,
214 .sdram_tim1 = MT41K256M16HA125E_EMIF_TIM1,
215 .sdram_tim2 = MT41K256M16HA125E_EMIF_TIM2,
216 .sdram_tim3 = MT41K256M16HA125E_EMIF_TIM3,
Jyri Sarha8d2998b2016-12-09 12:29:13 +0200217 .ocp_config = EMIF_OCP_CONFIG_BEAGLEBONE_BLACK,
Tom Rini385bc752013-03-21 04:30:02 +0000218 .zq_config = MT41K256M16HA125E_ZQ_CFG,
219 .emif_ddr_phy_ctlr_1 = MT41K256M16HA125E_EMIF_READ_LATENCY,
220};
221
Jeff Lance7c03a222013-01-14 05:32:20 +0000222static struct emif_regs ddr3_evm_emif_reg_data = {
223 .sdram_config = MT41J512M8RH125_EMIF_SDCFG,
224 .ref_ctrl = MT41J512M8RH125_EMIF_SDREF,
225 .sdram_tim1 = MT41J512M8RH125_EMIF_TIM1,
226 .sdram_tim2 = MT41J512M8RH125_EMIF_TIM2,
227 .sdram_tim3 = MT41J512M8RH125_EMIF_TIM3,
Jyri Sarha8d2998b2016-12-09 12:29:13 +0200228 .ocp_config = EMIF_OCP_CONFIG_AM335X_EVM,
Jeff Lance7c03a222013-01-14 05:32:20 +0000229 .zq_config = MT41J512M8RH125_ZQ_CFG,
Vaibhav Hiremathc30d57b2013-03-14 21:11:16 +0000230 .emif_ddr_phy_ctlr_1 = MT41J512M8RH125_EMIF_READ_LATENCY |
231 PHY_EN_DYN_PWRDN,
Jeff Lance7c03a222013-01-14 05:32:20 +0000232};
Peter Korsgaardeb204db2013-05-13 08:36:30 +0000233
Lokesh Vutla5837b902016-05-16 11:47:24 +0530234static struct emif_regs ddr3_icev2_emif_reg_data = {
235 .sdram_config = MT41J128MJT125_EMIF_SDCFG_400MHz,
236 .ref_ctrl = MT41J128MJT125_EMIF_SDREF_400MHz,
237 .sdram_tim1 = MT41J128MJT125_EMIF_TIM1_400MHz,
238 .sdram_tim2 = MT41J128MJT125_EMIF_TIM2_400MHz,
239 .sdram_tim3 = MT41J128MJT125_EMIF_TIM3_400MHz,
240 .zq_config = MT41J128MJT125_ZQ_CFG_400MHz,
241 .emif_ddr_phy_ctlr_1 = MT41J128MJT125_EMIF_READ_LATENCY_400MHz |
242 PHY_EN_DYN_PWRDN,
243};
244
Peter Korsgaardeb204db2013-05-13 08:36:30 +0000245#ifdef CONFIG_SPL_OS_BOOT
246int spl_start_uboot(void)
247{
Alex Kiernandf0df672018-04-19 04:32:53 +0000248#ifdef CONFIG_SPL_SERIAL_SUPPORT
Peter Korsgaardeb204db2013-05-13 08:36:30 +0000249 /* break into full u-boot on 'c' */
Tom Rini810b5812014-03-28 12:03:38 -0400250 if (serial_tstc() && serial_getc() == 'c')
251 return 1;
Alex Kiernandf0df672018-04-19 04:32:53 +0000252#endif
Tom Rini810b5812014-03-28 12:03:38 -0400253
254#ifdef CONFIG_SPL_ENV_SUPPORT
255 env_init();
Simon Glass17539572017-08-03 12:22:07 -0600256 env_load();
Simon Glass22c34c22017-08-03 12:22:13 -0600257 if (env_get_yesno("boot_os") != 1)
Tom Rini810b5812014-03-28 12:03:38 -0400258 return 1;
259#endif
260
261 return 0;
Peter Korsgaardeb204db2013-05-13 08:36:30 +0000262}
263#endif
264
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530265const struct dpll_params *get_dpll_ddr_params(void)
Tom Rini52437072013-08-30 16:28:46 -0400266{
Lokesh Vutla6302e532017-05-05 12:59:10 +0530267 int ind = get_sys_clk_index();
268
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530269 if (board_is_evm_sk())
Lokesh Vutla6302e532017-05-05 12:59:10 +0530270 return &dpll_ddr3_303MHz[ind];
Jason Kridnerb56b5b32018-03-07 05:40:41 -0500271 else if (board_is_pb() || board_is_bone_lt() || board_is_icev2())
Lokesh Vutla6302e532017-05-05 12:59:10 +0530272 return &dpll_ddr3_400MHz[ind];
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530273 else if (board_is_evm_15_or_later())
Lokesh Vutla6302e532017-05-05 12:59:10 +0530274 return &dpll_ddr3_303MHz[ind];
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530275 else
Lokesh Vutla6302e532017-05-05 12:59:10 +0530276 return &dpll_ddr2_266MHz[ind];
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530277}
Tom Rini52437072013-08-30 16:28:46 -0400278
Lokesh Vutla6302e532017-05-05 12:59:10 +0530279static u8 bone_not_connected_to_ac_power(void)
280{
281 if (board_is_bone()) {
282 uchar pmic_status_reg;
283 if (tps65217_reg_read(TPS65217_STATUS,
284 &pmic_status_reg))
285 return 1;
286 if (!(pmic_status_reg & TPS65217_PWR_SRC_AC_BITMASK)) {
287 puts("No AC power, switching to default OPP\n");
288 return 1;
289 }
290 }
291 return 0;
292}
293
294const struct dpll_params *get_dpll_mpu_params(void)
295{
296 int ind = get_sys_clk_index();
297 int freq = am335x_get_efuse_mpu_max_freq(cdev);
298
299 if (bone_not_connected_to_ac_power())
300 freq = MPUPLL_M_600;
301
Jason Kridnerb56b5b32018-03-07 05:40:41 -0500302 if (board_is_pb() || board_is_bone_lt())
Lokesh Vutla6302e532017-05-05 12:59:10 +0530303 freq = MPUPLL_M_1000;
304
305 switch (freq) {
306 case MPUPLL_M_1000:
307 return &dpll_mpu_opp[ind][5];
308 case MPUPLL_M_800:
309 return &dpll_mpu_opp[ind][4];
310 case MPUPLL_M_720:
311 return &dpll_mpu_opp[ind][3];
312 case MPUPLL_M_600:
313 return &dpll_mpu_opp[ind][2];
314 case MPUPLL_M_500:
315 return &dpll_mpu_opp100;
316 case MPUPLL_M_300:
317 return &dpll_mpu_opp[ind][0];
318 }
319
320 return &dpll_mpu_opp[ind][0];
321}
322
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530323static void scale_vcores_bone(int freq)
324{
325 int usb_cur_lim, mpu_vdd;
Tom Rini52437072013-08-30 16:28:46 -0400326
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530327 /*
328 * Only perform PMIC configurations if board rev > A1
329 * on Beaglebone White
330 */
331 if (board_is_bone() && !strncmp(board_ti_get_rev(), "00A1", 4))
332 return;
Tom Rini52437072013-08-30 16:28:46 -0400333
Jean-Jacques Hiblot52a51512018-12-07 14:50:49 +0100334#ifndef CONFIG_DM_I2C
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530335 if (i2c_probe(TPS65217_CHIP_PM))
336 return;
Jean-Jacques Hiblot52a51512018-12-07 14:50:49 +0100337#else
338 if (power_tps65217_init(0))
339 return;
340#endif
341
Tom Rini52437072013-08-30 16:28:46 -0400342
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530343 /*
344 * On Beaglebone White we need to ensure we have AC power
345 * before increasing the frequency.
346 */
Lokesh Vutla6302e532017-05-05 12:59:10 +0530347 if (bone_not_connected_to_ac_power())
348 freq = MPUPLL_M_600;
Tom Rini52437072013-08-30 16:28:46 -0400349
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530350 /*
351 * Override what we have detected since we know if we have
352 * a Beaglebone Black it supports 1GHz.
353 */
Jason Kridnerb56b5b32018-03-07 05:40:41 -0500354 if (board_is_pb() || board_is_bone_lt())
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530355 freq = MPUPLL_M_1000;
Tom Rini52437072013-08-30 16:28:46 -0400356
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530357 switch (freq) {
358 case MPUPLL_M_1000:
359 mpu_vdd = TPS65217_DCDC_VOLT_SEL_1325MV;
360 usb_cur_lim = TPS65217_USB_INPUT_CUR_LIMIT_1800MA;
361 break;
362 case MPUPLL_M_800:
363 mpu_vdd = TPS65217_DCDC_VOLT_SEL_1275MV;
Lokesh Vutlae29609a2017-06-10 13:22:56 +0530364 usb_cur_lim = TPS65217_USB_INPUT_CUR_LIMIT_1300MA;
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530365 break;
366 case MPUPLL_M_720:
367 mpu_vdd = TPS65217_DCDC_VOLT_SEL_1200MV;
Lokesh Vutlae29609a2017-06-10 13:22:56 +0530368 usb_cur_lim = TPS65217_USB_INPUT_CUR_LIMIT_1300MA;
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530369 break;
370 case MPUPLL_M_600:
371 case MPUPLL_M_500:
372 case MPUPLL_M_300:
Lokesh Vutlae29609a2017-06-10 13:22:56 +0530373 default:
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530374 mpu_vdd = TPS65217_DCDC_VOLT_SEL_1100MV;
375 usb_cur_lim = TPS65217_USB_INPUT_CUR_LIMIT_1300MA;
376 break;
377 }
Steve Kipisz5adac352013-08-14 10:51:31 -0400378
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530379 if (tps65217_reg_write(TPS65217_PROT_LEVEL_NONE,
380 TPS65217_POWER_PATH,
381 usb_cur_lim,
382 TPS65217_USB_INPUT_CUR_LIMIT_MASK))
383 puts("tps65217_reg_write failure\n");
Tom Rini52437072013-08-30 16:28:46 -0400384
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530385 /* Set DCDC3 (CORE) voltage to 1.10V */
386 if (tps65217_voltage_update(TPS65217_DEFDCDC3,
387 TPS65217_DCDC_VOLT_SEL_1100MV)) {
388 puts("tps65217_voltage_update failure\n");
389 return;
390 }
Tom Rini52437072013-08-30 16:28:46 -0400391
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530392 /* Set DCDC2 (MPU) voltage */
393 if (tps65217_voltage_update(TPS65217_DEFDCDC2, mpu_vdd)) {
394 puts("tps65217_voltage_update failure\n");
395 return;
396 }
Tom Rini52437072013-08-30 16:28:46 -0400397
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530398 /*
399 * Set LDO3, LDO4 output voltage to 3.3V for Beaglebone.
400 * Set LDO3 to 1.8V and LDO4 to 3.3V for Beaglebone Black.
401 */
402 if (board_is_bone()) {
Tom Rini52437072013-08-30 16:28:46 -0400403 if (tps65217_reg_write(TPS65217_PROT_LEVEL_2,
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530404 TPS65217_DEFLS1,
Tom Rini52437072013-08-30 16:28:46 -0400405 TPS65217_LDO_VOLTAGE_OUT_3_3,
406 TPS65217_LDO_MASK))
407 puts("tps65217_reg_write failure\n");
408 } else {
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530409 if (tps65217_reg_write(TPS65217_PROT_LEVEL_2,
410 TPS65217_DEFLS1,
411 TPS65217_LDO_VOLTAGE_OUT_1_8,
412 TPS65217_LDO_MASK))
413 puts("tps65217_reg_write failure\n");
414 }
Tom Rini52437072013-08-30 16:28:46 -0400415
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530416 if (tps65217_reg_write(TPS65217_PROT_LEVEL_2,
417 TPS65217_DEFLS2,
418 TPS65217_LDO_VOLTAGE_OUT_3_3,
419 TPS65217_LDO_MASK))
420 puts("tps65217_reg_write failure\n");
421}
Tom Rini52437072013-08-30 16:28:46 -0400422
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530423void scale_vcores_generic(int freq)
424{
425 int sil_rev, mpu_vdd;
Tom Rini52437072013-08-30 16:28:46 -0400426
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530427 /*
428 * The GP EVM, IDK and EVM SK use a TPS65910 PMIC. For all
429 * MPU frequencies we support we use a CORE voltage of
430 * 1.10V. For MPU voltage we need to switch based on
431 * the frequency we are running at.
432 */
Jean-Jacques Hiblot52a51512018-12-07 14:50:49 +0100433#ifndef CONFIG_DM_I2C
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530434 if (i2c_probe(TPS65910_CTRL_I2C_ADDR))
435 return;
Jean-Jacques Hiblot52a51512018-12-07 14:50:49 +0100436#else
437 if (power_tps65910_init(0))
438 return;
439#endif
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530440 /*
441 * Depending on MPU clock and PG we will need a different
442 * VDD to drive at that speed.
443 */
444 sil_rev = readl(&cdev->deviceid) >> 28;
445 mpu_vdd = am335x_get_tps65910_mpu_vdd(sil_rev, freq);
Tom Rini52437072013-08-30 16:28:46 -0400446
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530447 /* Tell the TPS65910 to use i2c */
448 tps65910_set_i2c_control();
Steve Kipisz5adac352013-08-14 10:51:31 -0400449
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530450 /* First update MPU voltage. */
451 if (tps65910_voltage_update(MPU, mpu_vdd))
452 return;
Tom Rini52437072013-08-30 16:28:46 -0400453
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530454 /* Second, update the CORE voltage. */
455 if (tps65910_voltage_update(CORE, TPS65910_OP_REG_SEL_1_1_0))
456 return;
457
Tom Rini52437072013-08-30 16:28:46 -0400458}
459
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530460void gpi2c_init(void)
Lokesh Vutla89a83bf2013-07-30 10:48:52 +0530461{
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530462 /* When needed to be invoked prior to BSS initialization */
463 static bool first_time = true;
464
465 if (first_time) {
466 enable_i2c0_pin_mux();
Jean-Jacques Hiblot52a51512018-12-07 14:50:49 +0100467#ifndef CONFIG_DM_I2C
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530468 i2c_init(CONFIG_SYS_OMAP24_I2C_SPEED,
469 CONFIG_SYS_OMAP24_I2C_SLAVE);
Jean-Jacques Hiblot52a51512018-12-07 14:50:49 +0100470#endif
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530471 first_time = false;
472 }
473}
474
475void scale_vcores(void)
476{
477 int freq;
478
479 gpi2c_init();
480 freq = am335x_get_efuse_mpu_max_freq(cdev);
481
Lokesh Vutlae29609a2017-06-10 13:22:56 +0530482 if (board_is_beaglebonex())
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530483 scale_vcores_bone(freq);
Lokesh Vutla89a83bf2013-07-30 10:48:52 +0530484 else
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530485 scale_vcores_generic(freq);
Lokesh Vutla89a83bf2013-07-30 10:48:52 +0530486}
487
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530488void set_uart_mux_conf(void)
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000489{
Tom Rini986d7552014-08-01 09:53:24 -0400490#if CONFIG_CONS_INDEX == 1
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000491 enable_uart0_pin_mux();
Tom Rini986d7552014-08-01 09:53:24 -0400492#elif CONFIG_CONS_INDEX == 2
Andrew Bradford65c51ff2012-10-25 08:21:30 -0400493 enable_uart1_pin_mux();
Tom Rini986d7552014-08-01 09:53:24 -0400494#elif CONFIG_CONS_INDEX == 3
Andrew Bradford65c51ff2012-10-25 08:21:30 -0400495 enable_uart2_pin_mux();
Tom Rini986d7552014-08-01 09:53:24 -0400496#elif CONFIG_CONS_INDEX == 4
Andrew Bradford65c51ff2012-10-25 08:21:30 -0400497 enable_uart3_pin_mux();
Tom Rini986d7552014-08-01 09:53:24 -0400498#elif CONFIG_CONS_INDEX == 5
Andrew Bradford65c51ff2012-10-25 08:21:30 -0400499 enable_uart4_pin_mux();
Tom Rini986d7552014-08-01 09:53:24 -0400500#elif CONFIG_CONS_INDEX == 6
Andrew Bradford65c51ff2012-10-25 08:21:30 -0400501 enable_uart5_pin_mux();
Tom Rini986d7552014-08-01 09:53:24 -0400502#endif
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530503}
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000504
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530505void set_mux_conf_regs(void)
506{
Nishanth Menon2afa70d2016-02-24 12:30:55 -0600507 enable_board_pin_mux();
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530508}
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000509
Lokesh Vutla303b2672013-12-10 15:02:21 +0530510const struct ctrl_ioregs ioregs_evmsk = {
511 .cm0ioctl = MT41J128MJT125_IOCTRL_VALUE,
512 .cm1ioctl = MT41J128MJT125_IOCTRL_VALUE,
513 .cm2ioctl = MT41J128MJT125_IOCTRL_VALUE,
514 .dt0ioctl = MT41J128MJT125_IOCTRL_VALUE,
515 .dt1ioctl = MT41J128MJT125_IOCTRL_VALUE,
516};
517
518const struct ctrl_ioregs ioregs_bonelt = {
519 .cm0ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
520 .cm1ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
521 .cm2ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
522 .dt0ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
523 .dt1ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
524};
525
526const struct ctrl_ioregs ioregs_evm15 = {
527 .cm0ioctl = MT41J512M8RH125_IOCTRL_VALUE,
528 .cm1ioctl = MT41J512M8RH125_IOCTRL_VALUE,
529 .cm2ioctl = MT41J512M8RH125_IOCTRL_VALUE,
530 .dt0ioctl = MT41J512M8RH125_IOCTRL_VALUE,
531 .dt1ioctl = MT41J512M8RH125_IOCTRL_VALUE,
532};
533
534const struct ctrl_ioregs ioregs = {
535 .cm0ioctl = MT47H128M16RT25E_IOCTRL_VALUE,
536 .cm1ioctl = MT47H128M16RT25E_IOCTRL_VALUE,
537 .cm2ioctl = MT47H128M16RT25E_IOCTRL_VALUE,
538 .dt0ioctl = MT47H128M16RT25E_IOCTRL_VALUE,
539 .dt1ioctl = MT47H128M16RT25E_IOCTRL_VALUE,
540};
541
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530542void sdram_init(void)
543{
Nishanth Menon2afa70d2016-02-24 12:30:55 -0600544 if (board_is_evm_sk()) {
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000545 /*
546 * EVM SK 1.2A and later use gpio0_7 to enable DDR3.
547 * This is safe enough to do on older revs.
548 */
549 gpio_request(GPIO_DDR_VTT_EN, "ddr_vtt_en");
550 gpio_direction_output(GPIO_DDR_VTT_EN, 1);
551 }
552
Lokesh Vutla5837b902016-05-16 11:47:24 +0530553 if (board_is_icev2()) {
554 gpio_request(ICE_GPIO_DDR_VTT_EN, "ddr_vtt_en");
555 gpio_direction_output(ICE_GPIO_DDR_VTT_EN, 1);
556 }
557
Nishanth Menon2afa70d2016-02-24 12:30:55 -0600558 if (board_is_evm_sk())
Lokesh Vutla303b2672013-12-10 15:02:21 +0530559 config_ddr(303, &ioregs_evmsk, &ddr3_data,
Matt Porter65991ec2013-03-15 10:07:03 +0000560 &ddr3_cmd_ctrl_data, &ddr3_emif_reg_data, 0);
Jason Kridnerb56b5b32018-03-07 05:40:41 -0500561 else if (board_is_pb() || board_is_bone_lt())
Lokesh Vutla303b2672013-12-10 15:02:21 +0530562 config_ddr(400, &ioregs_bonelt,
Tom Rini385bc752013-03-21 04:30:02 +0000563 &ddr3_beagleblack_data,
564 &ddr3_beagleblack_cmd_ctrl_data,
565 &ddr3_beagleblack_emif_reg_data, 0);
Nishanth Menon2afa70d2016-02-24 12:30:55 -0600566 else if (board_is_evm_15_or_later())
Lokesh Vutla303b2672013-12-10 15:02:21 +0530567 config_ddr(303, &ioregs_evm15, &ddr3_evm_data,
Matt Porter65991ec2013-03-15 10:07:03 +0000568 &ddr3_evm_cmd_ctrl_data, &ddr3_evm_emif_reg_data, 0);
Lokesh Vutla5837b902016-05-16 11:47:24 +0530569 else if (board_is_icev2())
570 config_ddr(400, &ioregs_evmsk, &ddr3_icev2_data,
571 &ddr3_icev2_cmd_ctrl_data, &ddr3_icev2_emif_reg_data,
572 0);
Jyri Sarha8d2998b2016-12-09 12:29:13 +0200573 else if (board_is_gp_evm())
574 config_ddr(266, &ioregs, &ddr2_data,
575 &ddr2_cmd_ctrl_data, &ddr2_evm_emif_reg_data, 0);
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000576 else
Lokesh Vutla303b2672013-12-10 15:02:21 +0530577 config_ddr(266, &ioregs, &ddr2_data,
Matt Porter65991ec2013-03-15 10:07:03 +0000578 &ddr2_cmd_ctrl_data, &ddr2_emif_reg_data, 0);
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000579}
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530580#endif
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000581
Alex Kiernan20bba2e2018-04-01 09:22:37 +0000582#if defined(CONFIG_CLOCK_SYNTHESIZER) && (!defined(CONFIG_SPL_BUILD) || \
583 (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD)))
Roger Quadrosbcb4ee82016-08-24 15:35:50 +0300584static void request_and_set_gpio(int gpio, char *name, int val)
Lokesh Vutla0d144f52016-05-16 11:47:26 +0530585{
586 int ret;
587
588 ret = gpio_request(gpio, name);
589 if (ret < 0) {
590 printf("%s: Unable to request %s\n", __func__, name);
591 return;
592 }
593
594 ret = gpio_direction_output(gpio, 0);
595 if (ret < 0) {
596 printf("%s: Unable to set %s as output\n", __func__, name);
597 goto err_free_gpio;
598 }
599
Roger Quadrosbcb4ee82016-08-24 15:35:50 +0300600 gpio_set_value(gpio, val);
Lokesh Vutla0d144f52016-05-16 11:47:26 +0530601
602 return;
603
604err_free_gpio:
605 gpio_free(gpio);
606}
607
Roger Quadrosbcb4ee82016-08-24 15:35:50 +0300608#define REQUEST_AND_SET_GPIO(N) request_and_set_gpio(N, #N, 1);
609#define REQUEST_AND_CLR_GPIO(N) request_and_set_gpio(N, #N, 0);
Lokesh Vutla0d144f52016-05-16 11:47:26 +0530610
611/**
612 * RMII mode on ICEv2 board needs 50MHz clock. Given the clock
613 * synthesizer With a capacitor of 18pF, and 25MHz input clock cycle
614 * PLL1 gives an output of 100MHz. So, configuring the div2/3 as 2 to
615 * give 50MHz output for Eth0 and 1.
616 */
617static struct clk_synth cdce913_data = {
618 .id = 0x81,
619 .capacitor = 0x90,
620 .mux = 0x6d,
621 .pdiv2 = 0x2,
622 .pdiv3 = 0x2,
623};
624#endif
625
Sekhar Norif357b112018-08-23 17:11:30 +0530626#if defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_CONTROL) && \
627 defined(CONFIG_DM_ETH) && defined(CONFIG_DRIVER_TI_CPSW)
628
629#define MAX_CPSW_SLAVES 2
630
631/* At the moment, we do not want to stop booting for any failures here */
632int ft_board_setup(void *fdt, bd_t *bd)
633{
634 const char *slave_path, *enet_name;
635 int enetnode, slavenode, phynode;
636 struct udevice *ethdev;
637 char alias[16];
638 u32 phy_id[2];
639 int phy_addr;
640 int i, ret;
641
642 /* phy address fixup needed only on beagle bone family */
643 if (!board_is_beaglebonex())
644 goto done;
645
646 for (i = 0; i < MAX_CPSW_SLAVES; i++) {
647 sprintf(alias, "ethernet%d", i);
648
649 slave_path = fdt_get_alias(fdt, alias);
650 if (!slave_path)
651 continue;
652
653 slavenode = fdt_path_offset(fdt, slave_path);
654 if (slavenode < 0)
655 continue;
656
657 enetnode = fdt_parent_offset(fdt, slavenode);
658 enet_name = fdt_get_name(fdt, enetnode, NULL);
659
660 ethdev = eth_get_dev_by_name(enet_name);
661 if (!ethdev)
662 continue;
663
664 phy_addr = cpsw_get_slave_phy_addr(ethdev, i);
665
666 /* check for phy_id as well as phy-handle properties */
667 ret = fdtdec_get_int_array_count(fdt, slavenode, "phy_id",
668 phy_id, 2);
669 if (ret == 2) {
670 if (phy_id[1] != phy_addr) {
671 printf("fixing up phy_id for %s, old: %d, new: %d\n",
672 alias, phy_id[1], phy_addr);
673
674 phy_id[0] = cpu_to_fdt32(phy_id[0]);
675 phy_id[1] = cpu_to_fdt32(phy_addr);
676 do_fixup_by_path(fdt, slave_path, "phy_id",
677 phy_id, sizeof(phy_id), 0);
678 }
679 } else {
680 phynode = fdtdec_lookup_phandle(fdt, slavenode,
681 "phy-handle");
682 if (phynode < 0)
683 continue;
684
685 ret = fdtdec_get_int(fdt, phynode, "reg", -ENOENT);
686 if (ret < 0)
687 continue;
688
689 if (ret != phy_addr) {
690 printf("fixing up phy-handle for %s, old: %d, new: %d\n",
691 alias, ret, phy_addr);
692
693 fdt_setprop_u32(fdt, phynode, "reg",
694 cpu_to_fdt32(phy_addr));
695 }
696 }
697 }
698
699done:
700 return 0;
701}
702#endif
703
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000704/*
705 * Basic board specific setup. Pinmux has been handled already.
706 */
707int board_init(void)
708{
Tom Rini303bfe82013-10-01 12:32:04 -0400709#if defined(CONFIG_HW_WATCHDOG)
710 hw_watchdog_init();
711#endif
712
Tom Rinif3b6a1d2013-08-09 11:22:13 -0400713 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
Miquel Raynald0935362019-10-03 19:50:03 +0200714#if defined(CONFIG_NOR) || defined(CONFIG_MTD_RAW_NAND)
Ilya Yanok3d9725e2012-11-06 13:06:31 +0000715 gpmc_init();
Steve Kipiszbe9b6f82013-07-18 15:13:03 -0400716#endif
Lokesh Vutla0d144f52016-05-16 11:47:26 +0530717
Alex Kiernan20bba2e2018-04-01 09:22:37 +0000718#if defined(CONFIG_CLOCK_SYNTHESIZER) && (!defined(CONFIG_SPL_BUILD) || \
719 (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD)))
Lokesh Vutla0d144f52016-05-16 11:47:26 +0530720 if (board_is_icev2()) {
Roger Quadrosbcb4ee82016-08-24 15:35:50 +0300721 int rv;
722 u32 reg;
723
Lokesh Vutla0d144f52016-05-16 11:47:26 +0530724 REQUEST_AND_SET_GPIO(GPIO_PR1_MII_CTRL);
Roger Quadrosbcb4ee82016-08-24 15:35:50 +0300725 /* Make J19 status available on GPIO1_26 */
726 REQUEST_AND_CLR_GPIO(GPIO_MUX_MII_CTRL);
727
Lokesh Vutla0d144f52016-05-16 11:47:26 +0530728 REQUEST_AND_SET_GPIO(GPIO_FET_SWITCH_CTRL);
Roger Quadrosbcb4ee82016-08-24 15:35:50 +0300729 /*
730 * Both ports can be set as RMII-CPSW or MII-PRU-ETH using
731 * jumpers near the port. Read the jumper value and set
732 * the pinmux, external mux and PHY clock accordingly.
733 * As jumper line is overridden by PHY RX_DV pin immediately
734 * after bootstrap (power-up/reset), we need to sample
735 * it during PHY reset using GPIO rising edge detection.
736 */
Lokesh Vutla0d144f52016-05-16 11:47:26 +0530737 REQUEST_AND_SET_GPIO(GPIO_PHY_RESET);
Roger Quadrosbcb4ee82016-08-24 15:35:50 +0300738 /* Enable rising edge IRQ on GPIO0_11 and GPIO 1_26 */
739 reg = readl(GPIO0_RISINGDETECT) | BIT(11);
740 writel(reg, GPIO0_RISINGDETECT);
741 reg = readl(GPIO1_RISINGDETECT) | BIT(26);
742 writel(reg, GPIO1_RISINGDETECT);
743 /* Reset PHYs to capture the Jumper setting */
744 gpio_set_value(GPIO_PHY_RESET, 0);
745 udelay(2); /* PHY datasheet states 1uS min. */
746 gpio_set_value(GPIO_PHY_RESET, 1);
747
748 reg = readl(GPIO0_IRQSTATUSRAW) & BIT(11);
749 if (reg) {
750 writel(reg, GPIO0_IRQSTATUS1); /* clear irq */
751 /* RMII mode */
752 printf("ETH0, CPSW\n");
753 } else {
754 /* MII mode */
755 printf("ETH0, PRU\n");
756 cdce913_data.pdiv3 = 4; /* 25MHz PHY clk */
757 }
758
759 reg = readl(GPIO1_IRQSTATUSRAW) & BIT(26);
760 if (reg) {
761 writel(reg, GPIO1_IRQSTATUS1); /* clear irq */
762 /* RMII mode */
763 printf("ETH1, CPSW\n");
764 gpio_set_value(GPIO_MUX_MII_CTRL, 1);
765 } else {
766 /* MII mode */
767 printf("ETH1, PRU\n");
768 cdce913_data.pdiv2 = 4; /* 25MHz PHY clk */
769 }
770
771 /* disable rising edge IRQs */
772 reg = readl(GPIO0_RISINGDETECT) & ~BIT(11);
773 writel(reg, GPIO0_RISINGDETECT);
774 reg = readl(GPIO1_RISINGDETECT) & ~BIT(26);
775 writel(reg, GPIO1_RISINGDETECT);
Lokesh Vutla0d144f52016-05-16 11:47:26 +0530776
777 rv = setup_clock_synthesizer(&cdce913_data);
778 if (rv) {
779 printf("Clock synthesizer setup failed %d\n", rv);
780 return rv;
781 }
Roger Quadrosbcb4ee82016-08-24 15:35:50 +0300782
783 /* reset PHYs */
784 gpio_set_value(GPIO_PHY_RESET, 0);
785 udelay(2); /* PHY datasheet states 1uS min. */
786 gpio_set_value(GPIO_PHY_RESET, 1);
Lokesh Vutla0d144f52016-05-16 11:47:26 +0530787 }
788#endif
789
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000790 return 0;
791}
792
Tom Rini40271852012-10-24 07:28:17 +0000793#ifdef CONFIG_BOARD_LATE_INIT
794int board_late_init(void)
795{
Tero Kristo67f79e72019-09-27 19:14:29 +0300796 struct udevice *dev;
Roger Quadros7c9d3782016-08-24 15:35:51 +0300797#if !defined(CONFIG_SPL_BUILD)
798 uint8_t mac_addr[6];
799 uint32_t mac_hi, mac_lo;
800#endif
801
Tom Rini40271852012-10-24 07:28:17 +0000802#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
Nishanth Menon2afa70d2016-02-24 12:30:55 -0600803 char *name = NULL;
Tom Rini4021fd92013-07-18 15:13:01 -0400804
robertcnelson@gmail.comc5d7d222017-03-30 14:29:52 -0500805 if (board_is_bone_lt()) {
806 /* BeagleBoard.org BeagleBone Black Wireless: */
807 if (!strncmp(board_ti_get_rev(), "BWA", 3)) {
808 name = "BBBW";
809 }
robertcnelson@gmail.comb55cd7a2017-03-30 14:29:53 -0500810 /* SeeedStudio BeagleBone Green Wireless */
811 if (!strncmp(board_ti_get_rev(), "GW1", 3)) {
812 name = "BBGW";
813 }
robertcnelson@gmail.com89ef1d62017-03-30 14:29:54 -0500814 /* BeagleBoard.org BeagleBone Blue */
815 if (!strncmp(board_ti_get_rev(), "BLA", 3)) {
816 name = "BBBL";
817 }
robertcnelson@gmail.comc5d7d222017-03-30 14:29:52 -0500818 }
819
Nishanth Menon2afa70d2016-02-24 12:30:55 -0600820 if (board_is_bbg1())
821 name = "BBG1";
Koen Kooi8a157862018-07-18 10:13:59 +0200822 if (board_is_bben())
823 name = "BBEN";
Nishanth Menon2afa70d2016-02-24 12:30:55 -0600824 set_board_info_env(name);
Lokesh Vutla1eb0f542016-11-29 11:58:03 +0530825
826 /*
827 * Default FIT boot on HS devices. Non FIT images are not allowed
828 * on HS devices.
829 */
830 if (get_device_type() == HS_DEVICE)
Simon Glass6a38e412017-08-03 12:22:09 -0600831 env_set("boot_fit", "1");
Tom Rini40271852012-10-24 07:28:17 +0000832#endif
833
Roger Quadros7c9d3782016-08-24 15:35:51 +0300834#if !defined(CONFIG_SPL_BUILD)
835 /* try reading mac address from efuse */
836 mac_lo = readl(&cdev->macid0l);
837 mac_hi = readl(&cdev->macid0h);
838 mac_addr[0] = mac_hi & 0xFF;
839 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
840 mac_addr[2] = (mac_hi & 0xFF0000) >> 16;
841 mac_addr[3] = (mac_hi & 0xFF000000) >> 24;
842 mac_addr[4] = mac_lo & 0xFF;
843 mac_addr[5] = (mac_lo & 0xFF00) >> 8;
844
Simon Glass64b723f2017-08-03 12:22:12 -0600845 if (!env_get("ethaddr")) {
Roger Quadros7c9d3782016-08-24 15:35:51 +0300846 printf("<ethaddr> not set. Validating first E-fuse MAC\n");
847
848 if (is_valid_ethaddr(mac_addr))
Simon Glass8551d552017-08-03 12:22:11 -0600849 eth_env_set_enetaddr("ethaddr", mac_addr);
Roger Quadros7c9d3782016-08-24 15:35:51 +0300850 }
851
852 mac_lo = readl(&cdev->macid1l);
853 mac_hi = readl(&cdev->macid1h);
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;
860
Simon Glass64b723f2017-08-03 12:22:12 -0600861 if (!env_get("eth1addr")) {
Roger Quadros7c9d3782016-08-24 15:35:51 +0300862 if (is_valid_ethaddr(mac_addr))
Simon Glass8551d552017-08-03 12:22:11 -0600863 eth_env_set_enetaddr("eth1addr", mac_addr);
Roger Quadros7c9d3782016-08-24 15:35:51 +0300864 }
865#endif
866
Sam Protsenkoa31ca622018-02-28 00:26:15 +0200867 if (!env_get("serial#")) {
868 char *board_serial = env_get("board_serial");
869 char *ethaddr = env_get("ethaddr");
870
871 if (!board_serial || !strncmp(board_serial, "unknown", 7))
872 env_set("serial#", ethaddr);
873 else
874 env_set("serial#", board_serial);
875 }
876
Tero Kristo67f79e72019-09-27 19:14:29 +0300877 /* Just probe the potentially supported cdce913 device */
878 uclass_get_device(UCLASS_CLK, 0, &dev);
879
Tom Rini40271852012-10-24 07:28:17 +0000880 return 0;
881}
882#endif
883
Faiz Abbas27866262019-03-18 13:54:37 +0530884/* CPSW platdata */
885#if !CONFIG_IS_ENABLED(OF_CONTROL)
886struct cpsw_slave_data slave_data[] = {
887 {
888 .slave_reg_ofs = CPSW_SLAVE0_OFFSET,
889 .sliver_reg_ofs = CPSW_SLIVER0_OFFSET,
890 .phy_addr = 0,
891 },
892 {
893 .slave_reg_ofs = CPSW_SLAVE1_OFFSET,
894 .sliver_reg_ofs = CPSW_SLIVER1_OFFSET,
895 .phy_addr = 1,
896 },
897};
898
899struct cpsw_platform_data am335_eth_data = {
900 .cpsw_base = CPSW_BASE,
901 .version = CPSW_CTRL_VERSION_2,
902 .bd_ram_ofs = CPSW_BD_OFFSET,
903 .ale_reg_ofs = CPSW_ALE_OFFSET,
904 .cpdma_reg_ofs = CPSW_CPDMA_OFFSET,
905 .mdio_div = CPSW_MDIO_DIV,
906 .host_port_reg_ofs = CPSW_HOST_PORT_OFFSET,
907 .channels = 8,
908 .slaves = 2,
909 .slave_data = slave_data,
910 .ale_entries = 1024,
911 .bd_ram_ofs = 0x2000,
912 .mac_control = 0x20,
913 .active_slave = 0,
914 .mdio_base = 0x4a101000,
915 .gmii_sel = 0x44e10650,
916 .phy_sel_compat = "ti,am3352-cpsw-phy-sel",
917 .syscon_addr = 0x44e10630,
918 .macid_sel_compat = "cpsw,am33xx",
919};
920
921struct eth_pdata cpsw_pdata = {
922 .iobase = 0x4a100000,
923 .phy_interface = 0,
924 .priv_pdata = &am335_eth_data,
925};
926
927U_BOOT_DEVICE(am335x_eth) = {
928 .name = "eth_cpsw",
929 .platdata = &cpsw_pdata,
930};
931#endif
932
Lokesh Vutla89b9f302016-05-16 11:24:24 +0530933#ifdef CONFIG_SPL_LOAD_FIT
934int board_fit_config_name_match(const char *name)
935{
936 if (board_is_gp_evm() && !strcmp(name, "am335x-evm"))
937 return 0;
938 else if (board_is_bone() && !strcmp(name, "am335x-bone"))
939 return 0;
940 else if (board_is_bone_lt() && !strcmp(name, "am335x-boneblack"))
941 return 0;
Jason Kridnerb56b5b32018-03-07 05:40:41 -0500942 else if (board_is_pb() && !strcmp(name, "am335x-pocketbeagle"))
943 return 0;
Lokesh Vutla5a954ba2016-05-16 11:24:28 +0530944 else if (board_is_evm_sk() && !strcmp(name, "am335x-evmsk"))
945 return 0;
Lokesh Vutla1edfcaf2016-05-16 11:24:29 +0530946 else if (board_is_bbg1() && !strcmp(name, "am335x-bonegreen"))
947 return 0;
Lokesh Vutla7ecf1962016-05-16 11:47:28 +0530948 else if (board_is_icev2() && !strcmp(name, "am335x-icev2"))
949 return 0;
Lokesh Vutla89b9f302016-05-16 11:24:24 +0530950 else
951 return -1;
952}
953#endif
Andrew F. Davisbd249152016-08-30 14:06:24 -0500954
955#ifdef CONFIG_TI_SECURE_DEVICE
956void board_fit_image_post_process(void **p_image, size_t *p_size)
957{
958 secure_boot_verify_image(p_image, p_size);
959}
960#endif
Lokesh Vutla2fe7c792017-04-26 13:37:08 +0530961
962#if !CONFIG_IS_ENABLED(OF_CONTROL)
963static const struct omap_hsmmc_plat am335x_mmc0_platdata = {
964 .base_addr = (struct hsmmc *)OMAP_HSMMC1_BASE,
965 .cfg.host_caps = MMC_MODE_HS_52MHz | MMC_MODE_HS | MMC_MODE_4BIT,
966 .cfg.f_min = 400000,
967 .cfg.f_max = 52000000,
968 .cfg.voltages = MMC_VDD_32_33 | MMC_VDD_33_34 | MMC_VDD_165_195,
969 .cfg.b_max = CONFIG_SYS_MMC_MAX_BLK_COUNT,
970};
971
972U_BOOT_DEVICE(am335x_mmc0) = {
973 .name = "omap_hsmmc",
974 .platdata = &am335x_mmc0_platdata,
975};
976
977static const struct omap_hsmmc_plat am335x_mmc1_platdata = {
978 .base_addr = (struct hsmmc *)OMAP_HSMMC2_BASE,
979 .cfg.host_caps = MMC_MODE_HS_52MHz | MMC_MODE_HS | MMC_MODE_8BIT,
980 .cfg.f_min = 400000,
981 .cfg.f_max = 52000000,
982 .cfg.voltages = MMC_VDD_32_33 | MMC_VDD_33_34 | MMC_VDD_165_195,
983 .cfg.b_max = CONFIG_SYS_MMC_MAX_BLK_COUNT,
984};
985
986U_BOOT_DEVICE(am335x_mmc1) = {
987 .name = "omap_hsmmc",
988 .platdata = &am335x_mmc1_platdata,
989};
990#endif