blob: 46b95c78657c669ccd424431a0439db738128173 [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>
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000015#include <spl.h>
Lokesh Vutlaabb44e62016-05-16 11:47:29 +053016#include <serial.h>
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000017#include <asm/arch/cpu.h>
18#include <asm/arch/hardware.h>
19#include <asm/arch/omap.h>
20#include <asm/arch/ddr_defs.h>
21#include <asm/arch/clock.h>
Lokesh Vutla0d144f52016-05-16 11:47:26 +053022#include <asm/arch/clk_synthesizer.h>
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000023#include <asm/arch/gpio.h>
24#include <asm/arch/mmc_host_def.h>
25#include <asm/arch/sys_proto.h>
Steve Kipiszbe9b6f82013-07-18 15:13:03 -040026#include <asm/arch/mem.h>
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000027#include <asm/io.h>
28#include <asm/emif.h>
29#include <asm/gpio.h>
Semen Protsenkoa8cb0222017-06-02 18:00:00 +030030#include <asm/omap_common.h>
Andrew F. Davisbd249152016-08-30 14:06:24 -050031#include <asm/omap_sec_common.h>
Lokesh Vutla2fe7c792017-04-26 13:37:08 +053032#include <asm/omap_mmc.h>
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000033#include <i2c.h>
34#include <miiphy.h>
35#include <cpsw.h>
Tom Rini52437072013-08-30 16:28:46 -040036#include <power/tps65217.h>
37#include <power/tps65910.h>
Simon Glass9d1f6192019-08-02 09:44:25 -060038#include <env_internal.h>
Tom Rini303bfe82013-10-01 12:32:04 -040039#include <watchdog.h>
Nishanth Menon2afa70d2016-02-24 12:30:55 -060040#include "../common/board_detect.h"
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000041#include "board.h"
42
43DECLARE_GLOBAL_DATA_PTR;
44
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000045/* GPIO that controls power to DDR on EVM-SK */
Lokesh Vutla0d144f52016-05-16 11:47:26 +053046#define GPIO_TO_PIN(bank, gpio) (32 * (bank) + (gpio))
47#define GPIO_DDR_VTT_EN GPIO_TO_PIN(0, 7)
48#define ICE_GPIO_DDR_VTT_EN GPIO_TO_PIN(0, 18)
49#define GPIO_PR1_MII_CTRL GPIO_TO_PIN(3, 4)
50#define GPIO_MUX_MII_CTRL GPIO_TO_PIN(3, 10)
51#define GPIO_FET_SWITCH_CTRL GPIO_TO_PIN(0, 7)
52#define GPIO_PHY_RESET GPIO_TO_PIN(2, 5)
Roger Quadrosbcb4ee82016-08-24 15:35:50 +030053#define GPIO_ETH0_MODE GPIO_TO_PIN(0, 11)
54#define GPIO_ETH1_MODE GPIO_TO_PIN(1, 26)
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000055
56static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
57
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 */
Lokesh Vutla93e0f5b2016-10-14 10:35:25 +053070#ifdef CONFIG_TI_I2C_BOARD_DETECT
71void do_board_detect(void)
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000072{
Lokesh Vutla93e0f5b2016-10-14 10:35:25 +053073 enable_i2c0_pin_mux();
Jean-Jacques Hiblot52a51512018-12-07 14:50:49 +010074#ifndef CONFIG_DM_I2C
Lokesh Vutla93e0f5b2016-10-14 10:35:25 +053075 i2c_init(CONFIG_SYS_OMAP24_I2C_SPEED, CONFIG_SYS_OMAP24_I2C_SLAVE);
Jean-Jacques Hiblot52a51512018-12-07 14:50:49 +010076#endif
Simon Glass4df67572017-05-12 21:09:55 -060077 if (ti_i2c_eeprom_am_get(CONFIG_EEPROM_BUS_ADDRESS,
78 CONFIG_EEPROM_CHIP_ADDRESS))
Lokesh Vutla93e0f5b2016-10-14 10:35:25 +053079 printf("ti_i2c_eeprom_init failed\n");
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000080}
Lokesh Vutla93e0f5b2016-10-14 10:35:25 +053081#endif
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000082
Lokesh Vutlaabb44e62016-05-16 11:47:29 +053083#ifndef CONFIG_DM_SERIAL
84struct serial_device *default_serial_console(void)
85{
86 if (board_is_icev2())
87 return &eserial4_device;
88 else
89 return &eserial1_device;
90}
91#endif
92
Tom Rini8de09df2014-04-09 08:25:57 -040093#ifndef CONFIG_SKIP_LOWLEVEL_INIT
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +000094static const struct ddr_data ddr2_data = {
Tom Rini7f50a572014-07-07 21:40:16 -040095 .datardsratio0 = MT47H128M16RT25E_RD_DQS,
96 .datafwsratio0 = MT47H128M16RT25E_PHY_FIFO_WE,
97 .datawrsratio0 = MT47H128M16RT25E_PHY_WR_DATA,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +000098};
99
100static const struct cmd_control ddr2_cmd_ctrl_data = {
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000101 .cmd0csratio = MT47H128M16RT25E_RATIO,
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000102
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000103 .cmd1csratio = MT47H128M16RT25E_RATIO,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000104
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000105 .cmd2csratio = MT47H128M16RT25E_RATIO,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000106};
107
108static const struct emif_regs ddr2_emif_reg_data = {
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000109 .sdram_config = MT47H128M16RT25E_EMIF_SDCFG,
110 .ref_ctrl = MT47H128M16RT25E_EMIF_SDREF,
111 .sdram_tim1 = MT47H128M16RT25E_EMIF_TIM1,
112 .sdram_tim2 = MT47H128M16RT25E_EMIF_TIM2,
113 .sdram_tim3 = MT47H128M16RT25E_EMIF_TIM3,
114 .emif_ddr_phy_ctlr_1 = MT47H128M16RT25E_EMIF_READ_LATENCY,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000115};
116
Jyri Sarha8d2998b2016-12-09 12:29:13 +0200117static const struct emif_regs ddr2_evm_emif_reg_data = {
118 .sdram_config = MT47H128M16RT25E_EMIF_SDCFG,
119 .ref_ctrl = MT47H128M16RT25E_EMIF_SDREF,
120 .sdram_tim1 = MT47H128M16RT25E_EMIF_TIM1,
121 .sdram_tim2 = MT47H128M16RT25E_EMIF_TIM2,
122 .sdram_tim3 = MT47H128M16RT25E_EMIF_TIM3,
123 .ocp_config = EMIF_OCP_CONFIG_AM335X_EVM,
124 .emif_ddr_phy_ctlr_1 = MT47H128M16RT25E_EMIF_READ_LATENCY,
125};
126
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000127static const struct ddr_data ddr3_data = {
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000128 .datardsratio0 = MT41J128MJT125_RD_DQS,
129 .datawdsratio0 = MT41J128MJT125_WR_DQS,
130 .datafwsratio0 = MT41J128MJT125_PHY_FIFO_WE,
131 .datawrsratio0 = MT41J128MJT125_PHY_WR_DATA,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000132};
133
Tom Rini385bc752013-03-21 04:30:02 +0000134static const struct ddr_data ddr3_beagleblack_data = {
135 .datardsratio0 = MT41K256M16HA125E_RD_DQS,
136 .datawdsratio0 = MT41K256M16HA125E_WR_DQS,
137 .datafwsratio0 = MT41K256M16HA125E_PHY_FIFO_WE,
138 .datawrsratio0 = MT41K256M16HA125E_PHY_WR_DATA,
Tom Rini385bc752013-03-21 04:30:02 +0000139};
140
Jeff Lance7c03a222013-01-14 05:32:20 +0000141static const struct ddr_data ddr3_evm_data = {
142 .datardsratio0 = MT41J512M8RH125_RD_DQS,
143 .datawdsratio0 = MT41J512M8RH125_WR_DQS,
144 .datafwsratio0 = MT41J512M8RH125_PHY_FIFO_WE,
145 .datawrsratio0 = MT41J512M8RH125_PHY_WR_DATA,
Jeff Lance7c03a222013-01-14 05:32:20 +0000146};
147
Lokesh Vutla5837b902016-05-16 11:47:24 +0530148static const struct ddr_data ddr3_icev2_data = {
149 .datardsratio0 = MT41J128MJT125_RD_DQS_400MHz,
150 .datawdsratio0 = MT41J128MJT125_WR_DQS_400MHz,
151 .datafwsratio0 = MT41J128MJT125_PHY_FIFO_WE_400MHz,
152 .datawrsratio0 = MT41J128MJT125_PHY_WR_DATA_400MHz,
153};
154
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000155static const struct cmd_control ddr3_cmd_ctrl_data = {
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000156 .cmd0csratio = MT41J128MJT125_RATIO,
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000157 .cmd0iclkout = MT41J128MJT125_INVERT_CLKOUT,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000158
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000159 .cmd1csratio = MT41J128MJT125_RATIO,
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000160 .cmd1iclkout = MT41J128MJT125_INVERT_CLKOUT,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000161
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000162 .cmd2csratio = MT41J128MJT125_RATIO,
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000163 .cmd2iclkout = MT41J128MJT125_INVERT_CLKOUT,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000164};
165
Tom Rini385bc752013-03-21 04:30:02 +0000166static const struct cmd_control ddr3_beagleblack_cmd_ctrl_data = {
167 .cmd0csratio = MT41K256M16HA125E_RATIO,
Tom Rini385bc752013-03-21 04:30:02 +0000168 .cmd0iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
169
170 .cmd1csratio = MT41K256M16HA125E_RATIO,
Tom Rini385bc752013-03-21 04:30:02 +0000171 .cmd1iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
172
173 .cmd2csratio = MT41K256M16HA125E_RATIO,
Tom Rini385bc752013-03-21 04:30:02 +0000174 .cmd2iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
175};
176
Jeff Lance7c03a222013-01-14 05:32:20 +0000177static const struct cmd_control ddr3_evm_cmd_ctrl_data = {
178 .cmd0csratio = MT41J512M8RH125_RATIO,
Jeff Lance7c03a222013-01-14 05:32:20 +0000179 .cmd0iclkout = MT41J512M8RH125_INVERT_CLKOUT,
180
181 .cmd1csratio = MT41J512M8RH125_RATIO,
Jeff Lance7c03a222013-01-14 05:32:20 +0000182 .cmd1iclkout = MT41J512M8RH125_INVERT_CLKOUT,
183
184 .cmd2csratio = MT41J512M8RH125_RATIO,
Jeff Lance7c03a222013-01-14 05:32:20 +0000185 .cmd2iclkout = MT41J512M8RH125_INVERT_CLKOUT,
186};
187
Lokesh Vutla5837b902016-05-16 11:47:24 +0530188static const struct cmd_control ddr3_icev2_cmd_ctrl_data = {
189 .cmd0csratio = MT41J128MJT125_RATIO_400MHz,
190 .cmd0iclkout = MT41J128MJT125_INVERT_CLKOUT_400MHz,
191
192 .cmd1csratio = MT41J128MJT125_RATIO_400MHz,
193 .cmd1iclkout = MT41J128MJT125_INVERT_CLKOUT_400MHz,
194
195 .cmd2csratio = MT41J128MJT125_RATIO_400MHz,
196 .cmd2iclkout = MT41J128MJT125_INVERT_CLKOUT_400MHz,
197};
198
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000199static struct emif_regs ddr3_emif_reg_data = {
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000200 .sdram_config = MT41J128MJT125_EMIF_SDCFG,
201 .ref_ctrl = MT41J128MJT125_EMIF_SDREF,
202 .sdram_tim1 = MT41J128MJT125_EMIF_TIM1,
203 .sdram_tim2 = MT41J128MJT125_EMIF_TIM2,
204 .sdram_tim3 = MT41J128MJT125_EMIF_TIM3,
205 .zq_config = MT41J128MJT125_ZQ_CFG,
Vaibhav Hiremathc30d57b2013-03-14 21:11:16 +0000206 .emif_ddr_phy_ctlr_1 = MT41J128MJT125_EMIF_READ_LATENCY |
207 PHY_EN_DYN_PWRDN,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000208};
Jeff Lance7c03a222013-01-14 05:32:20 +0000209
Tom Rini385bc752013-03-21 04:30:02 +0000210static struct emif_regs ddr3_beagleblack_emif_reg_data = {
211 .sdram_config = MT41K256M16HA125E_EMIF_SDCFG,
212 .ref_ctrl = MT41K256M16HA125E_EMIF_SDREF,
213 .sdram_tim1 = MT41K256M16HA125E_EMIF_TIM1,
214 .sdram_tim2 = MT41K256M16HA125E_EMIF_TIM2,
215 .sdram_tim3 = MT41K256M16HA125E_EMIF_TIM3,
Jyri Sarha8d2998b2016-12-09 12:29:13 +0200216 .ocp_config = EMIF_OCP_CONFIG_BEAGLEBONE_BLACK,
Tom Rini385bc752013-03-21 04:30:02 +0000217 .zq_config = MT41K256M16HA125E_ZQ_CFG,
218 .emif_ddr_phy_ctlr_1 = MT41K256M16HA125E_EMIF_READ_LATENCY,
219};
220
Jeff Lance7c03a222013-01-14 05:32:20 +0000221static struct emif_regs ddr3_evm_emif_reg_data = {
222 .sdram_config = MT41J512M8RH125_EMIF_SDCFG,
223 .ref_ctrl = MT41J512M8RH125_EMIF_SDREF,
224 .sdram_tim1 = MT41J512M8RH125_EMIF_TIM1,
225 .sdram_tim2 = MT41J512M8RH125_EMIF_TIM2,
226 .sdram_tim3 = MT41J512M8RH125_EMIF_TIM3,
Jyri Sarha8d2998b2016-12-09 12:29:13 +0200227 .ocp_config = EMIF_OCP_CONFIG_AM335X_EVM,
Jeff Lance7c03a222013-01-14 05:32:20 +0000228 .zq_config = MT41J512M8RH125_ZQ_CFG,
Vaibhav Hiremathc30d57b2013-03-14 21:11:16 +0000229 .emif_ddr_phy_ctlr_1 = MT41J512M8RH125_EMIF_READ_LATENCY |
230 PHY_EN_DYN_PWRDN,
Jeff Lance7c03a222013-01-14 05:32:20 +0000231};
Peter Korsgaardeb204db2013-05-13 08:36:30 +0000232
Lokesh Vutla5837b902016-05-16 11:47:24 +0530233static struct emif_regs ddr3_icev2_emif_reg_data = {
234 .sdram_config = MT41J128MJT125_EMIF_SDCFG_400MHz,
235 .ref_ctrl = MT41J128MJT125_EMIF_SDREF_400MHz,
236 .sdram_tim1 = MT41J128MJT125_EMIF_TIM1_400MHz,
237 .sdram_tim2 = MT41J128MJT125_EMIF_TIM2_400MHz,
238 .sdram_tim3 = MT41J128MJT125_EMIF_TIM3_400MHz,
239 .zq_config = MT41J128MJT125_ZQ_CFG_400MHz,
240 .emif_ddr_phy_ctlr_1 = MT41J128MJT125_EMIF_READ_LATENCY_400MHz |
241 PHY_EN_DYN_PWRDN,
242};
243
Peter Korsgaardeb204db2013-05-13 08:36:30 +0000244#ifdef CONFIG_SPL_OS_BOOT
245int spl_start_uboot(void)
246{
Alex Kiernandf0df672018-04-19 04:32:53 +0000247#ifdef CONFIG_SPL_SERIAL_SUPPORT
Peter Korsgaardeb204db2013-05-13 08:36:30 +0000248 /* break into full u-boot on 'c' */
Tom Rini810b5812014-03-28 12:03:38 -0400249 if (serial_tstc() && serial_getc() == 'c')
250 return 1;
Alex Kiernandf0df672018-04-19 04:32:53 +0000251#endif
Tom Rini810b5812014-03-28 12:03:38 -0400252
253#ifdef CONFIG_SPL_ENV_SUPPORT
254 env_init();
Simon Glass17539572017-08-03 12:22:07 -0600255 env_load();
Simon Glass22c34c22017-08-03 12:22:13 -0600256 if (env_get_yesno("boot_os") != 1)
Tom Rini810b5812014-03-28 12:03:38 -0400257 return 1;
258#endif
259
260 return 0;
Peter Korsgaardeb204db2013-05-13 08:36:30 +0000261}
262#endif
263
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530264const struct dpll_params *get_dpll_ddr_params(void)
Tom Rini52437072013-08-30 16:28:46 -0400265{
Lokesh Vutla6302e532017-05-05 12:59:10 +0530266 int ind = get_sys_clk_index();
267
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530268 if (board_is_evm_sk())
Lokesh Vutla6302e532017-05-05 12:59:10 +0530269 return &dpll_ddr3_303MHz[ind];
Jason Kridnerb56b5b32018-03-07 05:40:41 -0500270 else if (board_is_pb() || board_is_bone_lt() || board_is_icev2())
Lokesh Vutla6302e532017-05-05 12:59:10 +0530271 return &dpll_ddr3_400MHz[ind];
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530272 else if (board_is_evm_15_or_later())
Lokesh Vutla6302e532017-05-05 12:59:10 +0530273 return &dpll_ddr3_303MHz[ind];
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530274 else
Lokesh Vutla6302e532017-05-05 12:59:10 +0530275 return &dpll_ddr2_266MHz[ind];
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530276}
Tom Rini52437072013-08-30 16:28:46 -0400277
Lokesh Vutla6302e532017-05-05 12:59:10 +0530278static u8 bone_not_connected_to_ac_power(void)
279{
280 if (board_is_bone()) {
281 uchar pmic_status_reg;
282 if (tps65217_reg_read(TPS65217_STATUS,
283 &pmic_status_reg))
284 return 1;
285 if (!(pmic_status_reg & TPS65217_PWR_SRC_AC_BITMASK)) {
286 puts("No AC power, switching to default OPP\n");
287 return 1;
288 }
289 }
290 return 0;
291}
292
293const struct dpll_params *get_dpll_mpu_params(void)
294{
295 int ind = get_sys_clk_index();
296 int freq = am335x_get_efuse_mpu_max_freq(cdev);
297
298 if (bone_not_connected_to_ac_power())
299 freq = MPUPLL_M_600;
300
Jason Kridnerb56b5b32018-03-07 05:40:41 -0500301 if (board_is_pb() || board_is_bone_lt())
Lokesh Vutla6302e532017-05-05 12:59:10 +0530302 freq = MPUPLL_M_1000;
303
304 switch (freq) {
305 case MPUPLL_M_1000:
306 return &dpll_mpu_opp[ind][5];
307 case MPUPLL_M_800:
308 return &dpll_mpu_opp[ind][4];
309 case MPUPLL_M_720:
310 return &dpll_mpu_opp[ind][3];
311 case MPUPLL_M_600:
312 return &dpll_mpu_opp[ind][2];
313 case MPUPLL_M_500:
314 return &dpll_mpu_opp100;
315 case MPUPLL_M_300:
316 return &dpll_mpu_opp[ind][0];
317 }
318
319 return &dpll_mpu_opp[ind][0];
320}
321
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530322static void scale_vcores_bone(int freq)
323{
324 int usb_cur_lim, mpu_vdd;
Tom Rini52437072013-08-30 16:28:46 -0400325
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530326 /*
327 * Only perform PMIC configurations if board rev > A1
328 * on Beaglebone White
329 */
330 if (board_is_bone() && !strncmp(board_ti_get_rev(), "00A1", 4))
331 return;
Tom Rini52437072013-08-30 16:28:46 -0400332
Jean-Jacques Hiblot52a51512018-12-07 14:50:49 +0100333#ifndef CONFIG_DM_I2C
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530334 if (i2c_probe(TPS65217_CHIP_PM))
335 return;
Jean-Jacques Hiblot52a51512018-12-07 14:50:49 +0100336#else
337 if (power_tps65217_init(0))
338 return;
339#endif
340
Tom Rini52437072013-08-30 16:28:46 -0400341
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530342 /*
343 * On Beaglebone White we need to ensure we have AC power
344 * before increasing the frequency.
345 */
Lokesh Vutla6302e532017-05-05 12:59:10 +0530346 if (bone_not_connected_to_ac_power())
347 freq = MPUPLL_M_600;
Tom Rini52437072013-08-30 16:28:46 -0400348
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530349 /*
350 * Override what we have detected since we know if we have
351 * a Beaglebone Black it supports 1GHz.
352 */
Jason Kridnerb56b5b32018-03-07 05:40:41 -0500353 if (board_is_pb() || board_is_bone_lt())
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530354 freq = MPUPLL_M_1000;
Tom Rini52437072013-08-30 16:28:46 -0400355
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530356 switch (freq) {
357 case MPUPLL_M_1000:
358 mpu_vdd = TPS65217_DCDC_VOLT_SEL_1325MV;
359 usb_cur_lim = TPS65217_USB_INPUT_CUR_LIMIT_1800MA;
360 break;
361 case MPUPLL_M_800:
362 mpu_vdd = TPS65217_DCDC_VOLT_SEL_1275MV;
Lokesh Vutlae29609a2017-06-10 13:22:56 +0530363 usb_cur_lim = TPS65217_USB_INPUT_CUR_LIMIT_1300MA;
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530364 break;
365 case MPUPLL_M_720:
366 mpu_vdd = TPS65217_DCDC_VOLT_SEL_1200MV;
Lokesh Vutlae29609a2017-06-10 13:22:56 +0530367 usb_cur_lim = TPS65217_USB_INPUT_CUR_LIMIT_1300MA;
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530368 break;
369 case MPUPLL_M_600:
370 case MPUPLL_M_500:
371 case MPUPLL_M_300:
Lokesh Vutlae29609a2017-06-10 13:22:56 +0530372 default:
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530373 mpu_vdd = TPS65217_DCDC_VOLT_SEL_1100MV;
374 usb_cur_lim = TPS65217_USB_INPUT_CUR_LIMIT_1300MA;
375 break;
376 }
Steve Kipisz5adac352013-08-14 10:51:31 -0400377
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530378 if (tps65217_reg_write(TPS65217_PROT_LEVEL_NONE,
379 TPS65217_POWER_PATH,
380 usb_cur_lim,
381 TPS65217_USB_INPUT_CUR_LIMIT_MASK))
382 puts("tps65217_reg_write failure\n");
Tom Rini52437072013-08-30 16:28:46 -0400383
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530384 /* Set DCDC3 (CORE) voltage to 1.10V */
385 if (tps65217_voltage_update(TPS65217_DEFDCDC3,
386 TPS65217_DCDC_VOLT_SEL_1100MV)) {
387 puts("tps65217_voltage_update failure\n");
388 return;
389 }
Tom Rini52437072013-08-30 16:28:46 -0400390
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530391 /* Set DCDC2 (MPU) voltage */
392 if (tps65217_voltage_update(TPS65217_DEFDCDC2, mpu_vdd)) {
393 puts("tps65217_voltage_update failure\n");
394 return;
395 }
Tom Rini52437072013-08-30 16:28:46 -0400396
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530397 /*
398 * Set LDO3, LDO4 output voltage to 3.3V for Beaglebone.
399 * Set LDO3 to 1.8V and LDO4 to 3.3V for Beaglebone Black.
400 */
401 if (board_is_bone()) {
Tom Rini52437072013-08-30 16:28:46 -0400402 if (tps65217_reg_write(TPS65217_PROT_LEVEL_2,
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530403 TPS65217_DEFLS1,
Tom Rini52437072013-08-30 16:28:46 -0400404 TPS65217_LDO_VOLTAGE_OUT_3_3,
405 TPS65217_LDO_MASK))
406 puts("tps65217_reg_write failure\n");
407 } else {
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530408 if (tps65217_reg_write(TPS65217_PROT_LEVEL_2,
409 TPS65217_DEFLS1,
410 TPS65217_LDO_VOLTAGE_OUT_1_8,
411 TPS65217_LDO_MASK))
412 puts("tps65217_reg_write failure\n");
413 }
Tom Rini52437072013-08-30 16:28:46 -0400414
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530415 if (tps65217_reg_write(TPS65217_PROT_LEVEL_2,
416 TPS65217_DEFLS2,
417 TPS65217_LDO_VOLTAGE_OUT_3_3,
418 TPS65217_LDO_MASK))
419 puts("tps65217_reg_write failure\n");
420}
Tom Rini52437072013-08-30 16:28:46 -0400421
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530422void scale_vcores_generic(int freq)
423{
424 int sil_rev, mpu_vdd;
Tom Rini52437072013-08-30 16:28:46 -0400425
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530426 /*
427 * The GP EVM, IDK and EVM SK use a TPS65910 PMIC. For all
428 * MPU frequencies we support we use a CORE voltage of
429 * 1.10V. For MPU voltage we need to switch based on
430 * the frequency we are running at.
431 */
Jean-Jacques Hiblot52a51512018-12-07 14:50:49 +0100432#ifndef CONFIG_DM_I2C
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530433 if (i2c_probe(TPS65910_CTRL_I2C_ADDR))
434 return;
Jean-Jacques Hiblot52a51512018-12-07 14:50:49 +0100435#else
436 if (power_tps65910_init(0))
437 return;
438#endif
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530439 /*
440 * Depending on MPU clock and PG we will need a different
441 * VDD to drive at that speed.
442 */
443 sil_rev = readl(&cdev->deviceid) >> 28;
444 mpu_vdd = am335x_get_tps65910_mpu_vdd(sil_rev, freq);
Tom Rini52437072013-08-30 16:28:46 -0400445
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530446 /* Tell the TPS65910 to use i2c */
447 tps65910_set_i2c_control();
Steve Kipisz5adac352013-08-14 10:51:31 -0400448
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530449 /* First update MPU voltage. */
450 if (tps65910_voltage_update(MPU, mpu_vdd))
451 return;
Tom Rini52437072013-08-30 16:28:46 -0400452
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530453 /* Second, update the CORE voltage. */
454 if (tps65910_voltage_update(CORE, TPS65910_OP_REG_SEL_1_1_0))
455 return;
456
Tom Rini52437072013-08-30 16:28:46 -0400457}
458
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530459void gpi2c_init(void)
Lokesh Vutla89a83bf2013-07-30 10:48:52 +0530460{
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530461 /* When needed to be invoked prior to BSS initialization */
462 static bool first_time = true;
463
464 if (first_time) {
465 enable_i2c0_pin_mux();
Jean-Jacques Hiblot52a51512018-12-07 14:50:49 +0100466#ifndef CONFIG_DM_I2C
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530467 i2c_init(CONFIG_SYS_OMAP24_I2C_SPEED,
468 CONFIG_SYS_OMAP24_I2C_SLAVE);
Jean-Jacques Hiblot52a51512018-12-07 14:50:49 +0100469#endif
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530470 first_time = false;
471 }
472}
473
474void scale_vcores(void)
475{
476 int freq;
477
478 gpi2c_init();
479 freq = am335x_get_efuse_mpu_max_freq(cdev);
480
Lokesh Vutlae29609a2017-06-10 13:22:56 +0530481 if (board_is_beaglebonex())
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530482 scale_vcores_bone(freq);
Lokesh Vutla89a83bf2013-07-30 10:48:52 +0530483 else
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530484 scale_vcores_generic(freq);
Lokesh Vutla89a83bf2013-07-30 10:48:52 +0530485}
486
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530487void set_uart_mux_conf(void)
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000488{
Tom Rini986d7552014-08-01 09:53:24 -0400489#if CONFIG_CONS_INDEX == 1
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000490 enable_uart0_pin_mux();
Tom Rini986d7552014-08-01 09:53:24 -0400491#elif CONFIG_CONS_INDEX == 2
Andrew Bradford65c51ff2012-10-25 08:21:30 -0400492 enable_uart1_pin_mux();
Tom Rini986d7552014-08-01 09:53:24 -0400493#elif CONFIG_CONS_INDEX == 3
Andrew Bradford65c51ff2012-10-25 08:21:30 -0400494 enable_uart2_pin_mux();
Tom Rini986d7552014-08-01 09:53:24 -0400495#elif CONFIG_CONS_INDEX == 4
Andrew Bradford65c51ff2012-10-25 08:21:30 -0400496 enable_uart3_pin_mux();
Tom Rini986d7552014-08-01 09:53:24 -0400497#elif CONFIG_CONS_INDEX == 5
Andrew Bradford65c51ff2012-10-25 08:21:30 -0400498 enable_uart4_pin_mux();
Tom Rini986d7552014-08-01 09:53:24 -0400499#elif CONFIG_CONS_INDEX == 6
Andrew Bradford65c51ff2012-10-25 08:21:30 -0400500 enable_uart5_pin_mux();
Tom Rini986d7552014-08-01 09:53:24 -0400501#endif
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530502}
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000503
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530504void set_mux_conf_regs(void)
505{
Nishanth Menon2afa70d2016-02-24 12:30:55 -0600506 enable_board_pin_mux();
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530507}
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000508
Lokesh Vutla303b2672013-12-10 15:02:21 +0530509const struct ctrl_ioregs ioregs_evmsk = {
510 .cm0ioctl = MT41J128MJT125_IOCTRL_VALUE,
511 .cm1ioctl = MT41J128MJT125_IOCTRL_VALUE,
512 .cm2ioctl = MT41J128MJT125_IOCTRL_VALUE,
513 .dt0ioctl = MT41J128MJT125_IOCTRL_VALUE,
514 .dt1ioctl = MT41J128MJT125_IOCTRL_VALUE,
515};
516
517const struct ctrl_ioregs ioregs_bonelt = {
518 .cm0ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
519 .cm1ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
520 .cm2ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
521 .dt0ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
522 .dt1ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
523};
524
525const struct ctrl_ioregs ioregs_evm15 = {
526 .cm0ioctl = MT41J512M8RH125_IOCTRL_VALUE,
527 .cm1ioctl = MT41J512M8RH125_IOCTRL_VALUE,
528 .cm2ioctl = MT41J512M8RH125_IOCTRL_VALUE,
529 .dt0ioctl = MT41J512M8RH125_IOCTRL_VALUE,
530 .dt1ioctl = MT41J512M8RH125_IOCTRL_VALUE,
531};
532
533const struct ctrl_ioregs ioregs = {
534 .cm0ioctl = MT47H128M16RT25E_IOCTRL_VALUE,
535 .cm1ioctl = MT47H128M16RT25E_IOCTRL_VALUE,
536 .cm2ioctl = MT47H128M16RT25E_IOCTRL_VALUE,
537 .dt0ioctl = MT47H128M16RT25E_IOCTRL_VALUE,
538 .dt1ioctl = MT47H128M16RT25E_IOCTRL_VALUE,
539};
540
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530541void sdram_init(void)
542{
Nishanth Menon2afa70d2016-02-24 12:30:55 -0600543 if (board_is_evm_sk()) {
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000544 /*
545 * EVM SK 1.2A and later use gpio0_7 to enable DDR3.
546 * This is safe enough to do on older revs.
547 */
548 gpio_request(GPIO_DDR_VTT_EN, "ddr_vtt_en");
549 gpio_direction_output(GPIO_DDR_VTT_EN, 1);
550 }
551
Lokesh Vutla5837b902016-05-16 11:47:24 +0530552 if (board_is_icev2()) {
553 gpio_request(ICE_GPIO_DDR_VTT_EN, "ddr_vtt_en");
554 gpio_direction_output(ICE_GPIO_DDR_VTT_EN, 1);
555 }
556
Nishanth Menon2afa70d2016-02-24 12:30:55 -0600557 if (board_is_evm_sk())
Lokesh Vutla303b2672013-12-10 15:02:21 +0530558 config_ddr(303, &ioregs_evmsk, &ddr3_data,
Matt Porter65991ec2013-03-15 10:07:03 +0000559 &ddr3_cmd_ctrl_data, &ddr3_emif_reg_data, 0);
Jason Kridnerb56b5b32018-03-07 05:40:41 -0500560 else if (board_is_pb() || board_is_bone_lt())
Lokesh Vutla303b2672013-12-10 15:02:21 +0530561 config_ddr(400, &ioregs_bonelt,
Tom Rini385bc752013-03-21 04:30:02 +0000562 &ddr3_beagleblack_data,
563 &ddr3_beagleblack_cmd_ctrl_data,
564 &ddr3_beagleblack_emif_reg_data, 0);
Nishanth Menon2afa70d2016-02-24 12:30:55 -0600565 else if (board_is_evm_15_or_later())
Lokesh Vutla303b2672013-12-10 15:02:21 +0530566 config_ddr(303, &ioregs_evm15, &ddr3_evm_data,
Matt Porter65991ec2013-03-15 10:07:03 +0000567 &ddr3_evm_cmd_ctrl_data, &ddr3_evm_emif_reg_data, 0);
Lokesh Vutla5837b902016-05-16 11:47:24 +0530568 else if (board_is_icev2())
569 config_ddr(400, &ioregs_evmsk, &ddr3_icev2_data,
570 &ddr3_icev2_cmd_ctrl_data, &ddr3_icev2_emif_reg_data,
571 0);
Jyri Sarha8d2998b2016-12-09 12:29:13 +0200572 else if (board_is_gp_evm())
573 config_ddr(266, &ioregs, &ddr2_data,
574 &ddr2_cmd_ctrl_data, &ddr2_evm_emif_reg_data, 0);
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000575 else
Lokesh Vutla303b2672013-12-10 15:02:21 +0530576 config_ddr(266, &ioregs, &ddr2_data,
Matt Porter65991ec2013-03-15 10:07:03 +0000577 &ddr2_cmd_ctrl_data, &ddr2_emif_reg_data, 0);
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000578}
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530579#endif
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000580
Alex Kiernan20bba2e2018-04-01 09:22:37 +0000581#if defined(CONFIG_CLOCK_SYNTHESIZER) && (!defined(CONFIG_SPL_BUILD) || \
582 (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD)))
Roger Quadrosbcb4ee82016-08-24 15:35:50 +0300583static void request_and_set_gpio(int gpio, char *name, int val)
Lokesh Vutla0d144f52016-05-16 11:47:26 +0530584{
585 int ret;
586
587 ret = gpio_request(gpio, name);
588 if (ret < 0) {
589 printf("%s: Unable to request %s\n", __func__, name);
590 return;
591 }
592
593 ret = gpio_direction_output(gpio, 0);
594 if (ret < 0) {
595 printf("%s: Unable to set %s as output\n", __func__, name);
596 goto err_free_gpio;
597 }
598
Roger Quadrosbcb4ee82016-08-24 15:35:50 +0300599 gpio_set_value(gpio, val);
Lokesh Vutla0d144f52016-05-16 11:47:26 +0530600
601 return;
602
603err_free_gpio:
604 gpio_free(gpio);
605}
606
Roger Quadrosbcb4ee82016-08-24 15:35:50 +0300607#define REQUEST_AND_SET_GPIO(N) request_and_set_gpio(N, #N, 1);
608#define REQUEST_AND_CLR_GPIO(N) request_and_set_gpio(N, #N, 0);
Lokesh Vutla0d144f52016-05-16 11:47:26 +0530609
610/**
611 * RMII mode on ICEv2 board needs 50MHz clock. Given the clock
612 * synthesizer With a capacitor of 18pF, and 25MHz input clock cycle
613 * PLL1 gives an output of 100MHz. So, configuring the div2/3 as 2 to
614 * give 50MHz output for Eth0 and 1.
615 */
616static struct clk_synth cdce913_data = {
617 .id = 0x81,
618 .capacitor = 0x90,
619 .mux = 0x6d,
620 .pdiv2 = 0x2,
621 .pdiv3 = 0x2,
622};
623#endif
624
Sekhar Norif357b112018-08-23 17:11:30 +0530625#if defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_CONTROL) && \
626 defined(CONFIG_DM_ETH) && defined(CONFIG_DRIVER_TI_CPSW)
627
628#define MAX_CPSW_SLAVES 2
629
630/* At the moment, we do not want to stop booting for any failures here */
631int ft_board_setup(void *fdt, bd_t *bd)
632{
633 const char *slave_path, *enet_name;
634 int enetnode, slavenode, phynode;
635 struct udevice *ethdev;
636 char alias[16];
637 u32 phy_id[2];
638 int phy_addr;
639 int i, ret;
640
641 /* phy address fixup needed only on beagle bone family */
642 if (!board_is_beaglebonex())
643 goto done;
644
645 for (i = 0; i < MAX_CPSW_SLAVES; i++) {
646 sprintf(alias, "ethernet%d", i);
647
648 slave_path = fdt_get_alias(fdt, alias);
649 if (!slave_path)
650 continue;
651
652 slavenode = fdt_path_offset(fdt, slave_path);
653 if (slavenode < 0)
654 continue;
655
656 enetnode = fdt_parent_offset(fdt, slavenode);
657 enet_name = fdt_get_name(fdt, enetnode, NULL);
658
659 ethdev = eth_get_dev_by_name(enet_name);
660 if (!ethdev)
661 continue;
662
663 phy_addr = cpsw_get_slave_phy_addr(ethdev, i);
664
665 /* check for phy_id as well as phy-handle properties */
666 ret = fdtdec_get_int_array_count(fdt, slavenode, "phy_id",
667 phy_id, 2);
668 if (ret == 2) {
669 if (phy_id[1] != phy_addr) {
670 printf("fixing up phy_id for %s, old: %d, new: %d\n",
671 alias, phy_id[1], phy_addr);
672
673 phy_id[0] = cpu_to_fdt32(phy_id[0]);
674 phy_id[1] = cpu_to_fdt32(phy_addr);
675 do_fixup_by_path(fdt, slave_path, "phy_id",
676 phy_id, sizeof(phy_id), 0);
677 }
678 } else {
679 phynode = fdtdec_lookup_phandle(fdt, slavenode,
680 "phy-handle");
681 if (phynode < 0)
682 continue;
683
684 ret = fdtdec_get_int(fdt, phynode, "reg", -ENOENT);
685 if (ret < 0)
686 continue;
687
688 if (ret != phy_addr) {
689 printf("fixing up phy-handle for %s, old: %d, new: %d\n",
690 alias, ret, phy_addr);
691
692 fdt_setprop_u32(fdt, phynode, "reg",
693 cpu_to_fdt32(phy_addr));
694 }
695 }
696 }
697
698done:
699 return 0;
700}
701#endif
702
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000703/*
704 * Basic board specific setup. Pinmux has been handled already.
705 */
706int board_init(void)
707{
Tom Rini303bfe82013-10-01 12:32:04 -0400708#if defined(CONFIG_HW_WATCHDOG)
709 hw_watchdog_init();
710#endif
711
Tom Rinif3b6a1d2013-08-09 11:22:13 -0400712 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
pekon gupta53b4b322013-11-18 19:03:02 +0530713#if defined(CONFIG_NOR) || defined(CONFIG_NAND)
Ilya Yanok3d9725e2012-11-06 13:06:31 +0000714 gpmc_init();
Steve Kipiszbe9b6f82013-07-18 15:13:03 -0400715#endif
Lokesh Vutla0d144f52016-05-16 11:47:26 +0530716
Alex Kiernan20bba2e2018-04-01 09:22:37 +0000717#if defined(CONFIG_CLOCK_SYNTHESIZER) && (!defined(CONFIG_SPL_BUILD) || \
718 (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD)))
Lokesh Vutla0d144f52016-05-16 11:47:26 +0530719 if (board_is_icev2()) {
Roger Quadrosbcb4ee82016-08-24 15:35:50 +0300720 int rv;
721 u32 reg;
722
Lokesh Vutla0d144f52016-05-16 11:47:26 +0530723 REQUEST_AND_SET_GPIO(GPIO_PR1_MII_CTRL);
Roger Quadrosbcb4ee82016-08-24 15:35:50 +0300724 /* Make J19 status available on GPIO1_26 */
725 REQUEST_AND_CLR_GPIO(GPIO_MUX_MII_CTRL);
726
Lokesh Vutla0d144f52016-05-16 11:47:26 +0530727 REQUEST_AND_SET_GPIO(GPIO_FET_SWITCH_CTRL);
Roger Quadrosbcb4ee82016-08-24 15:35:50 +0300728 /*
729 * Both ports can be set as RMII-CPSW or MII-PRU-ETH using
730 * jumpers near the port. Read the jumper value and set
731 * the pinmux, external mux and PHY clock accordingly.
732 * As jumper line is overridden by PHY RX_DV pin immediately
733 * after bootstrap (power-up/reset), we need to sample
734 * it during PHY reset using GPIO rising edge detection.
735 */
Lokesh Vutla0d144f52016-05-16 11:47:26 +0530736 REQUEST_AND_SET_GPIO(GPIO_PHY_RESET);
Roger Quadrosbcb4ee82016-08-24 15:35:50 +0300737 /* Enable rising edge IRQ on GPIO0_11 and GPIO 1_26 */
738 reg = readl(GPIO0_RISINGDETECT) | BIT(11);
739 writel(reg, GPIO0_RISINGDETECT);
740 reg = readl(GPIO1_RISINGDETECT) | BIT(26);
741 writel(reg, GPIO1_RISINGDETECT);
742 /* Reset PHYs to capture the Jumper setting */
743 gpio_set_value(GPIO_PHY_RESET, 0);
744 udelay(2); /* PHY datasheet states 1uS min. */
745 gpio_set_value(GPIO_PHY_RESET, 1);
746
747 reg = readl(GPIO0_IRQSTATUSRAW) & BIT(11);
748 if (reg) {
749 writel(reg, GPIO0_IRQSTATUS1); /* clear irq */
750 /* RMII mode */
751 printf("ETH0, CPSW\n");
752 } else {
753 /* MII mode */
754 printf("ETH0, PRU\n");
755 cdce913_data.pdiv3 = 4; /* 25MHz PHY clk */
756 }
757
758 reg = readl(GPIO1_IRQSTATUSRAW) & BIT(26);
759 if (reg) {
760 writel(reg, GPIO1_IRQSTATUS1); /* clear irq */
761 /* RMII mode */
762 printf("ETH1, CPSW\n");
763 gpio_set_value(GPIO_MUX_MII_CTRL, 1);
764 } else {
765 /* MII mode */
766 printf("ETH1, PRU\n");
767 cdce913_data.pdiv2 = 4; /* 25MHz PHY clk */
768 }
769
770 /* disable rising edge IRQs */
771 reg = readl(GPIO0_RISINGDETECT) & ~BIT(11);
772 writel(reg, GPIO0_RISINGDETECT);
773 reg = readl(GPIO1_RISINGDETECT) & ~BIT(26);
774 writel(reg, GPIO1_RISINGDETECT);
Lokesh Vutla0d144f52016-05-16 11:47:26 +0530775
776 rv = setup_clock_synthesizer(&cdce913_data);
777 if (rv) {
778 printf("Clock synthesizer setup failed %d\n", rv);
779 return rv;
780 }
Roger Quadrosbcb4ee82016-08-24 15:35:50 +0300781
782 /* reset PHYs */
783 gpio_set_value(GPIO_PHY_RESET, 0);
784 udelay(2); /* PHY datasheet states 1uS min. */
785 gpio_set_value(GPIO_PHY_RESET, 1);
Lokesh Vutla0d144f52016-05-16 11:47:26 +0530786 }
787#endif
788
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000789 return 0;
790}
791
Tom Rini40271852012-10-24 07:28:17 +0000792#ifdef CONFIG_BOARD_LATE_INIT
793int board_late_init(void)
794{
Tero Kristo67f79e72019-09-27 19:14:29 +0300795 struct udevice *dev;
Roger Quadros7c9d3782016-08-24 15:35:51 +0300796#if !defined(CONFIG_SPL_BUILD)
797 uint8_t mac_addr[6];
798 uint32_t mac_hi, mac_lo;
799#endif
800
Tom Rini40271852012-10-24 07:28:17 +0000801#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
Nishanth Menon2afa70d2016-02-24 12:30:55 -0600802 char *name = NULL;
Tom Rini4021fd92013-07-18 15:13:01 -0400803
robertcnelson@gmail.comc5d7d222017-03-30 14:29:52 -0500804 if (board_is_bone_lt()) {
805 /* BeagleBoard.org BeagleBone Black Wireless: */
806 if (!strncmp(board_ti_get_rev(), "BWA", 3)) {
807 name = "BBBW";
808 }
robertcnelson@gmail.comb55cd7a2017-03-30 14:29:53 -0500809 /* SeeedStudio BeagleBone Green Wireless */
810 if (!strncmp(board_ti_get_rev(), "GW1", 3)) {
811 name = "BBGW";
812 }
robertcnelson@gmail.com89ef1d62017-03-30 14:29:54 -0500813 /* BeagleBoard.org BeagleBone Blue */
814 if (!strncmp(board_ti_get_rev(), "BLA", 3)) {
815 name = "BBBL";
816 }
robertcnelson@gmail.comc5d7d222017-03-30 14:29:52 -0500817 }
818
Nishanth Menon2afa70d2016-02-24 12:30:55 -0600819 if (board_is_bbg1())
820 name = "BBG1";
Koen Kooi8a157862018-07-18 10:13:59 +0200821 if (board_is_bben())
822 name = "BBEN";
Nishanth Menon2afa70d2016-02-24 12:30:55 -0600823 set_board_info_env(name);
Lokesh Vutla1eb0f542016-11-29 11:58:03 +0530824
825 /*
826 * Default FIT boot on HS devices. Non FIT images are not allowed
827 * on HS devices.
828 */
829 if (get_device_type() == HS_DEVICE)
Simon Glass6a38e412017-08-03 12:22:09 -0600830 env_set("boot_fit", "1");
Tom Rini40271852012-10-24 07:28:17 +0000831#endif
832
Roger Quadros7c9d3782016-08-24 15:35:51 +0300833#if !defined(CONFIG_SPL_BUILD)
834 /* try reading mac address from efuse */
835 mac_lo = readl(&cdev->macid0l);
836 mac_hi = readl(&cdev->macid0h);
837 mac_addr[0] = mac_hi & 0xFF;
838 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
839 mac_addr[2] = (mac_hi & 0xFF0000) >> 16;
840 mac_addr[3] = (mac_hi & 0xFF000000) >> 24;
841 mac_addr[4] = mac_lo & 0xFF;
842 mac_addr[5] = (mac_lo & 0xFF00) >> 8;
843
Simon Glass64b723f2017-08-03 12:22:12 -0600844 if (!env_get("ethaddr")) {
Roger Quadros7c9d3782016-08-24 15:35:51 +0300845 printf("<ethaddr> not set. Validating first E-fuse MAC\n");
846
847 if (is_valid_ethaddr(mac_addr))
Simon Glass8551d552017-08-03 12:22:11 -0600848 eth_env_set_enetaddr("ethaddr", mac_addr);
Roger Quadros7c9d3782016-08-24 15:35:51 +0300849 }
850
851 mac_lo = readl(&cdev->macid1l);
852 mac_hi = readl(&cdev->macid1h);
853 mac_addr[0] = mac_hi & 0xFF;
854 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
855 mac_addr[2] = (mac_hi & 0xFF0000) >> 16;
856 mac_addr[3] = (mac_hi & 0xFF000000) >> 24;
857 mac_addr[4] = mac_lo & 0xFF;
858 mac_addr[5] = (mac_lo & 0xFF00) >> 8;
859
Simon Glass64b723f2017-08-03 12:22:12 -0600860 if (!env_get("eth1addr")) {
Roger Quadros7c9d3782016-08-24 15:35:51 +0300861 if (is_valid_ethaddr(mac_addr))
Simon Glass8551d552017-08-03 12:22:11 -0600862 eth_env_set_enetaddr("eth1addr", mac_addr);
Roger Quadros7c9d3782016-08-24 15:35:51 +0300863 }
864#endif
865
Sam Protsenkoa31ca622018-02-28 00:26:15 +0200866 if (!env_get("serial#")) {
867 char *board_serial = env_get("board_serial");
868 char *ethaddr = env_get("ethaddr");
869
870 if (!board_serial || !strncmp(board_serial, "unknown", 7))
871 env_set("serial#", ethaddr);
872 else
873 env_set("serial#", board_serial);
874 }
875
Tero Kristo67f79e72019-09-27 19:14:29 +0300876 /* Just probe the potentially supported cdce913 device */
877 uclass_get_device(UCLASS_CLK, 0, &dev);
878
Tom Rini40271852012-10-24 07:28:17 +0000879 return 0;
880}
881#endif
882
Faiz Abbas27866262019-03-18 13:54:37 +0530883/* CPSW platdata */
884#if !CONFIG_IS_ENABLED(OF_CONTROL)
885struct cpsw_slave_data slave_data[] = {
886 {
887 .slave_reg_ofs = CPSW_SLAVE0_OFFSET,
888 .sliver_reg_ofs = CPSW_SLIVER0_OFFSET,
889 .phy_addr = 0,
890 },
891 {
892 .slave_reg_ofs = CPSW_SLAVE1_OFFSET,
893 .sliver_reg_ofs = CPSW_SLIVER1_OFFSET,
894 .phy_addr = 1,
895 },
896};
897
898struct cpsw_platform_data am335_eth_data = {
899 .cpsw_base = CPSW_BASE,
900 .version = CPSW_CTRL_VERSION_2,
901 .bd_ram_ofs = CPSW_BD_OFFSET,
902 .ale_reg_ofs = CPSW_ALE_OFFSET,
903 .cpdma_reg_ofs = CPSW_CPDMA_OFFSET,
904 .mdio_div = CPSW_MDIO_DIV,
905 .host_port_reg_ofs = CPSW_HOST_PORT_OFFSET,
906 .channels = 8,
907 .slaves = 2,
908 .slave_data = slave_data,
909 .ale_entries = 1024,
910 .bd_ram_ofs = 0x2000,
911 .mac_control = 0x20,
912 .active_slave = 0,
913 .mdio_base = 0x4a101000,
914 .gmii_sel = 0x44e10650,
915 .phy_sel_compat = "ti,am3352-cpsw-phy-sel",
916 .syscon_addr = 0x44e10630,
917 .macid_sel_compat = "cpsw,am33xx",
918};
919
920struct eth_pdata cpsw_pdata = {
921 .iobase = 0x4a100000,
922 .phy_interface = 0,
923 .priv_pdata = &am335_eth_data,
924};
925
926U_BOOT_DEVICE(am335x_eth) = {
927 .name = "eth_cpsw",
928 .platdata = &cpsw_pdata,
929};
930#endif
931
Lokesh Vutla89b9f302016-05-16 11:24:24 +0530932#ifdef CONFIG_SPL_LOAD_FIT
933int board_fit_config_name_match(const char *name)
934{
935 if (board_is_gp_evm() && !strcmp(name, "am335x-evm"))
936 return 0;
937 else if (board_is_bone() && !strcmp(name, "am335x-bone"))
938 return 0;
939 else if (board_is_bone_lt() && !strcmp(name, "am335x-boneblack"))
940 return 0;
Jason Kridnerb56b5b32018-03-07 05:40:41 -0500941 else if (board_is_pb() && !strcmp(name, "am335x-pocketbeagle"))
942 return 0;
Lokesh Vutla5a954ba2016-05-16 11:24:28 +0530943 else if (board_is_evm_sk() && !strcmp(name, "am335x-evmsk"))
944 return 0;
Lokesh Vutla1edfcaf2016-05-16 11:24:29 +0530945 else if (board_is_bbg1() && !strcmp(name, "am335x-bonegreen"))
946 return 0;
Lokesh Vutla7ecf1962016-05-16 11:47:28 +0530947 else if (board_is_icev2() && !strcmp(name, "am335x-icev2"))
948 return 0;
Lokesh Vutla89b9f302016-05-16 11:24:24 +0530949 else
950 return -1;
951}
952#endif
Andrew F. Davisbd249152016-08-30 14:06:24 -0500953
954#ifdef CONFIG_TI_SECURE_DEVICE
955void board_fit_image_post_process(void **p_image, size_t *p_size)
956{
957 secure_boot_verify_image(p_image, p_size);
958}
959#endif
Lokesh Vutla2fe7c792017-04-26 13:37:08 +0530960
961#if !CONFIG_IS_ENABLED(OF_CONTROL)
962static const struct omap_hsmmc_plat am335x_mmc0_platdata = {
963 .base_addr = (struct hsmmc *)OMAP_HSMMC1_BASE,
964 .cfg.host_caps = MMC_MODE_HS_52MHz | MMC_MODE_HS | MMC_MODE_4BIT,
965 .cfg.f_min = 400000,
966 .cfg.f_max = 52000000,
967 .cfg.voltages = MMC_VDD_32_33 | MMC_VDD_33_34 | MMC_VDD_165_195,
968 .cfg.b_max = CONFIG_SYS_MMC_MAX_BLK_COUNT,
969};
970
971U_BOOT_DEVICE(am335x_mmc0) = {
972 .name = "omap_hsmmc",
973 .platdata = &am335x_mmc0_platdata,
974};
975
976static const struct omap_hsmmc_plat am335x_mmc1_platdata = {
977 .base_addr = (struct hsmmc *)OMAP_HSMMC2_BASE,
978 .cfg.host_caps = MMC_MODE_HS_52MHz | MMC_MODE_HS | MMC_MODE_8BIT,
979 .cfg.f_min = 400000,
980 .cfg.f_max = 52000000,
981 .cfg.voltages = MMC_VDD_32_33 | MMC_VDD_33_34 | MMC_VDD_165_195,
982 .cfg.b_max = CONFIG_SYS_MMC_MAX_BLK_COUNT,
983};
984
985U_BOOT_DEVICE(am335x_mmc1) = {
986 .name = "omap_hsmmc",
987 .platdata = &am335x_mmc1_platdata,
988};
989#endif