blob: 13845251afb5ad93e7366895934308ad504e6a28 [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>
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000012#include <errno.h>
13#include <spl.h>
Lokesh Vutlaabb44e62016-05-16 11:47:29 +053014#include <serial.h>
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000015#include <asm/arch/cpu.h>
16#include <asm/arch/hardware.h>
17#include <asm/arch/omap.h>
18#include <asm/arch/ddr_defs.h>
19#include <asm/arch/clock.h>
Lokesh Vutla0d144f52016-05-16 11:47:26 +053020#include <asm/arch/clk_synthesizer.h>
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000021#include <asm/arch/gpio.h>
22#include <asm/arch/mmc_host_def.h>
23#include <asm/arch/sys_proto.h>
Steve Kipiszbe9b6f82013-07-18 15:13:03 -040024#include <asm/arch/mem.h>
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000025#include <asm/io.h>
26#include <asm/emif.h>
27#include <asm/gpio.h>
Semen Protsenkoa8cb0222017-06-02 18:00:00 +030028#include <asm/omap_common.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
Simon Glass4df67572017-05-12 21:09:55 -060075 if (ti_i2c_eeprom_am_get(CONFIG_EEPROM_BUS_ADDRESS,
76 CONFIG_EEPROM_CHIP_ADDRESS))
Lokesh Vutla93e0f5b2016-10-14 10:35:25 +053077 printf("ti_i2c_eeprom_init failed\n");
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000078}
Lokesh Vutla93e0f5b2016-10-14 10:35:25 +053079#endif
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000080
Lokesh Vutlaabb44e62016-05-16 11:47:29 +053081#ifndef CONFIG_DM_SERIAL
82struct serial_device *default_serial_console(void)
83{
84 if (board_is_icev2())
85 return &eserial4_device;
86 else
87 return &eserial1_device;
88}
89#endif
90
Tom Rini8de09df2014-04-09 08:25:57 -040091#ifndef CONFIG_SKIP_LOWLEVEL_INIT
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +000092static const struct ddr_data ddr2_data = {
Tom Rini7f50a572014-07-07 21:40:16 -040093 .datardsratio0 = MT47H128M16RT25E_RD_DQS,
94 .datafwsratio0 = MT47H128M16RT25E_PHY_FIFO_WE,
95 .datawrsratio0 = MT47H128M16RT25E_PHY_WR_DATA,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +000096};
97
98static const struct cmd_control ddr2_cmd_ctrl_data = {
Peter Korsgaard3adb8272012-10-18 01:21:13 +000099 .cmd0csratio = MT47H128M16RT25E_RATIO,
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000100
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000101 .cmd1csratio = MT47H128M16RT25E_RATIO,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000102
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000103 .cmd2csratio = MT47H128M16RT25E_RATIO,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000104};
105
106static const struct emif_regs ddr2_emif_reg_data = {
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000107 .sdram_config = MT47H128M16RT25E_EMIF_SDCFG,
108 .ref_ctrl = MT47H128M16RT25E_EMIF_SDREF,
109 .sdram_tim1 = MT47H128M16RT25E_EMIF_TIM1,
110 .sdram_tim2 = MT47H128M16RT25E_EMIF_TIM2,
111 .sdram_tim3 = MT47H128M16RT25E_EMIF_TIM3,
112 .emif_ddr_phy_ctlr_1 = MT47H128M16RT25E_EMIF_READ_LATENCY,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000113};
114
Jyri Sarha8d2998b2016-12-09 12:29:13 +0200115static const struct emif_regs ddr2_evm_emif_reg_data = {
116 .sdram_config = MT47H128M16RT25E_EMIF_SDCFG,
117 .ref_ctrl = MT47H128M16RT25E_EMIF_SDREF,
118 .sdram_tim1 = MT47H128M16RT25E_EMIF_TIM1,
119 .sdram_tim2 = MT47H128M16RT25E_EMIF_TIM2,
120 .sdram_tim3 = MT47H128M16RT25E_EMIF_TIM3,
121 .ocp_config = EMIF_OCP_CONFIG_AM335X_EVM,
122 .emif_ddr_phy_ctlr_1 = MT47H128M16RT25E_EMIF_READ_LATENCY,
123};
124
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000125static const struct ddr_data ddr3_data = {
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000126 .datardsratio0 = MT41J128MJT125_RD_DQS,
127 .datawdsratio0 = MT41J128MJT125_WR_DQS,
128 .datafwsratio0 = MT41J128MJT125_PHY_FIFO_WE,
129 .datawrsratio0 = MT41J128MJT125_PHY_WR_DATA,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000130};
131
Tom Rini385bc752013-03-21 04:30:02 +0000132static const struct ddr_data ddr3_beagleblack_data = {
133 .datardsratio0 = MT41K256M16HA125E_RD_DQS,
134 .datawdsratio0 = MT41K256M16HA125E_WR_DQS,
135 .datafwsratio0 = MT41K256M16HA125E_PHY_FIFO_WE,
136 .datawrsratio0 = MT41K256M16HA125E_PHY_WR_DATA,
Tom Rini385bc752013-03-21 04:30:02 +0000137};
138
Jeff Lance7c03a222013-01-14 05:32:20 +0000139static const struct ddr_data ddr3_evm_data = {
140 .datardsratio0 = MT41J512M8RH125_RD_DQS,
141 .datawdsratio0 = MT41J512M8RH125_WR_DQS,
142 .datafwsratio0 = MT41J512M8RH125_PHY_FIFO_WE,
143 .datawrsratio0 = MT41J512M8RH125_PHY_WR_DATA,
Jeff Lance7c03a222013-01-14 05:32:20 +0000144};
145
Lokesh Vutla5837b902016-05-16 11:47:24 +0530146static const struct ddr_data ddr3_icev2_data = {
147 .datardsratio0 = MT41J128MJT125_RD_DQS_400MHz,
148 .datawdsratio0 = MT41J128MJT125_WR_DQS_400MHz,
149 .datafwsratio0 = MT41J128MJT125_PHY_FIFO_WE_400MHz,
150 .datawrsratio0 = MT41J128MJT125_PHY_WR_DATA_400MHz,
151};
152
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000153static const struct cmd_control ddr3_cmd_ctrl_data = {
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000154 .cmd0csratio = MT41J128MJT125_RATIO,
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000155 .cmd0iclkout = MT41J128MJT125_INVERT_CLKOUT,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000156
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000157 .cmd1csratio = MT41J128MJT125_RATIO,
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000158 .cmd1iclkout = MT41J128MJT125_INVERT_CLKOUT,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000159
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000160 .cmd2csratio = MT41J128MJT125_RATIO,
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000161 .cmd2iclkout = MT41J128MJT125_INVERT_CLKOUT,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000162};
163
Tom Rini385bc752013-03-21 04:30:02 +0000164static const struct cmd_control ddr3_beagleblack_cmd_ctrl_data = {
165 .cmd0csratio = MT41K256M16HA125E_RATIO,
Tom Rini385bc752013-03-21 04:30:02 +0000166 .cmd0iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
167
168 .cmd1csratio = MT41K256M16HA125E_RATIO,
Tom Rini385bc752013-03-21 04:30:02 +0000169 .cmd1iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
170
171 .cmd2csratio = MT41K256M16HA125E_RATIO,
Tom Rini385bc752013-03-21 04:30:02 +0000172 .cmd2iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
173};
174
Jeff Lance7c03a222013-01-14 05:32:20 +0000175static const struct cmd_control ddr3_evm_cmd_ctrl_data = {
176 .cmd0csratio = MT41J512M8RH125_RATIO,
Jeff Lance7c03a222013-01-14 05:32:20 +0000177 .cmd0iclkout = MT41J512M8RH125_INVERT_CLKOUT,
178
179 .cmd1csratio = MT41J512M8RH125_RATIO,
Jeff Lance7c03a222013-01-14 05:32:20 +0000180 .cmd1iclkout = MT41J512M8RH125_INVERT_CLKOUT,
181
182 .cmd2csratio = MT41J512M8RH125_RATIO,
Jeff Lance7c03a222013-01-14 05:32:20 +0000183 .cmd2iclkout = MT41J512M8RH125_INVERT_CLKOUT,
184};
185
Lokesh Vutla5837b902016-05-16 11:47:24 +0530186static const struct cmd_control ddr3_icev2_cmd_ctrl_data = {
187 .cmd0csratio = MT41J128MJT125_RATIO_400MHz,
188 .cmd0iclkout = MT41J128MJT125_INVERT_CLKOUT_400MHz,
189
190 .cmd1csratio = MT41J128MJT125_RATIO_400MHz,
191 .cmd1iclkout = MT41J128MJT125_INVERT_CLKOUT_400MHz,
192
193 .cmd2csratio = MT41J128MJT125_RATIO_400MHz,
194 .cmd2iclkout = MT41J128MJT125_INVERT_CLKOUT_400MHz,
195};
196
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000197static struct emif_regs ddr3_emif_reg_data = {
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000198 .sdram_config = MT41J128MJT125_EMIF_SDCFG,
199 .ref_ctrl = MT41J128MJT125_EMIF_SDREF,
200 .sdram_tim1 = MT41J128MJT125_EMIF_TIM1,
201 .sdram_tim2 = MT41J128MJT125_EMIF_TIM2,
202 .sdram_tim3 = MT41J128MJT125_EMIF_TIM3,
203 .zq_config = MT41J128MJT125_ZQ_CFG,
Vaibhav Hiremathc30d57b2013-03-14 21:11:16 +0000204 .emif_ddr_phy_ctlr_1 = MT41J128MJT125_EMIF_READ_LATENCY |
205 PHY_EN_DYN_PWRDN,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000206};
Jeff Lance7c03a222013-01-14 05:32:20 +0000207
Tom Rini385bc752013-03-21 04:30:02 +0000208static struct emif_regs ddr3_beagleblack_emif_reg_data = {
209 .sdram_config = MT41K256M16HA125E_EMIF_SDCFG,
210 .ref_ctrl = MT41K256M16HA125E_EMIF_SDREF,
211 .sdram_tim1 = MT41K256M16HA125E_EMIF_TIM1,
212 .sdram_tim2 = MT41K256M16HA125E_EMIF_TIM2,
213 .sdram_tim3 = MT41K256M16HA125E_EMIF_TIM3,
Jyri Sarha8d2998b2016-12-09 12:29:13 +0200214 .ocp_config = EMIF_OCP_CONFIG_BEAGLEBONE_BLACK,
Tom Rini385bc752013-03-21 04:30:02 +0000215 .zq_config = MT41K256M16HA125E_ZQ_CFG,
216 .emif_ddr_phy_ctlr_1 = MT41K256M16HA125E_EMIF_READ_LATENCY,
217};
218
Jeff Lance7c03a222013-01-14 05:32:20 +0000219static struct emif_regs ddr3_evm_emif_reg_data = {
220 .sdram_config = MT41J512M8RH125_EMIF_SDCFG,
221 .ref_ctrl = MT41J512M8RH125_EMIF_SDREF,
222 .sdram_tim1 = MT41J512M8RH125_EMIF_TIM1,
223 .sdram_tim2 = MT41J512M8RH125_EMIF_TIM2,
224 .sdram_tim3 = MT41J512M8RH125_EMIF_TIM3,
Jyri Sarha8d2998b2016-12-09 12:29:13 +0200225 .ocp_config = EMIF_OCP_CONFIG_AM335X_EVM,
Jeff Lance7c03a222013-01-14 05:32:20 +0000226 .zq_config = MT41J512M8RH125_ZQ_CFG,
Vaibhav Hiremathc30d57b2013-03-14 21:11:16 +0000227 .emif_ddr_phy_ctlr_1 = MT41J512M8RH125_EMIF_READ_LATENCY |
228 PHY_EN_DYN_PWRDN,
Jeff Lance7c03a222013-01-14 05:32:20 +0000229};
Peter Korsgaardeb204db2013-05-13 08:36:30 +0000230
Lokesh Vutla5837b902016-05-16 11:47:24 +0530231static struct emif_regs ddr3_icev2_emif_reg_data = {
232 .sdram_config = MT41J128MJT125_EMIF_SDCFG_400MHz,
233 .ref_ctrl = MT41J128MJT125_EMIF_SDREF_400MHz,
234 .sdram_tim1 = MT41J128MJT125_EMIF_TIM1_400MHz,
235 .sdram_tim2 = MT41J128MJT125_EMIF_TIM2_400MHz,
236 .sdram_tim3 = MT41J128MJT125_EMIF_TIM3_400MHz,
237 .zq_config = MT41J128MJT125_ZQ_CFG_400MHz,
238 .emif_ddr_phy_ctlr_1 = MT41J128MJT125_EMIF_READ_LATENCY_400MHz |
239 PHY_EN_DYN_PWRDN,
240};
241
Peter Korsgaardeb204db2013-05-13 08:36:30 +0000242#ifdef CONFIG_SPL_OS_BOOT
243int spl_start_uboot(void)
244{
Alex Kiernandf0df672018-04-19 04:32:53 +0000245#ifdef CONFIG_SPL_SERIAL_SUPPORT
Peter Korsgaardeb204db2013-05-13 08:36:30 +0000246 /* break into full u-boot on 'c' */
Tom Rini810b5812014-03-28 12:03:38 -0400247 if (serial_tstc() && serial_getc() == 'c')
248 return 1;
Alex Kiernandf0df672018-04-19 04:32:53 +0000249#endif
Tom Rini810b5812014-03-28 12:03:38 -0400250
251#ifdef CONFIG_SPL_ENV_SUPPORT
252 env_init();
Simon Glass17539572017-08-03 12:22:07 -0600253 env_load();
Simon Glass22c34c22017-08-03 12:22:13 -0600254 if (env_get_yesno("boot_os") != 1)
Tom Rini810b5812014-03-28 12:03:38 -0400255 return 1;
256#endif
257
258 return 0;
Peter Korsgaardeb204db2013-05-13 08:36:30 +0000259}
260#endif
261
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530262const struct dpll_params *get_dpll_ddr_params(void)
Tom Rini52437072013-08-30 16:28:46 -0400263{
Lokesh Vutla6302e532017-05-05 12:59:10 +0530264 int ind = get_sys_clk_index();
265
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530266 if (board_is_evm_sk())
Lokesh Vutla6302e532017-05-05 12:59:10 +0530267 return &dpll_ddr3_303MHz[ind];
Jason Kridnerb56b5b32018-03-07 05:40:41 -0500268 else if (board_is_pb() || board_is_bone_lt() || board_is_icev2())
Lokesh Vutla6302e532017-05-05 12:59:10 +0530269 return &dpll_ddr3_400MHz[ind];
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530270 else if (board_is_evm_15_or_later())
Lokesh Vutla6302e532017-05-05 12:59:10 +0530271 return &dpll_ddr3_303MHz[ind];
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530272 else
Lokesh Vutla6302e532017-05-05 12:59:10 +0530273 return &dpll_ddr2_266MHz[ind];
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530274}
Tom Rini52437072013-08-30 16:28:46 -0400275
Lokesh Vutla6302e532017-05-05 12:59:10 +0530276static u8 bone_not_connected_to_ac_power(void)
277{
278 if (board_is_bone()) {
279 uchar pmic_status_reg;
280 if (tps65217_reg_read(TPS65217_STATUS,
281 &pmic_status_reg))
282 return 1;
283 if (!(pmic_status_reg & TPS65217_PWR_SRC_AC_BITMASK)) {
284 puts("No AC power, switching to default OPP\n");
285 return 1;
286 }
287 }
288 return 0;
289}
290
291const struct dpll_params *get_dpll_mpu_params(void)
292{
293 int ind = get_sys_clk_index();
294 int freq = am335x_get_efuse_mpu_max_freq(cdev);
295
296 if (bone_not_connected_to_ac_power())
297 freq = MPUPLL_M_600;
298
Jason Kridnerb56b5b32018-03-07 05:40:41 -0500299 if (board_is_pb() || board_is_bone_lt())
Lokesh Vutla6302e532017-05-05 12:59:10 +0530300 freq = MPUPLL_M_1000;
301
302 switch (freq) {
303 case MPUPLL_M_1000:
304 return &dpll_mpu_opp[ind][5];
305 case MPUPLL_M_800:
306 return &dpll_mpu_opp[ind][4];
307 case MPUPLL_M_720:
308 return &dpll_mpu_opp[ind][3];
309 case MPUPLL_M_600:
310 return &dpll_mpu_opp[ind][2];
311 case MPUPLL_M_500:
312 return &dpll_mpu_opp100;
313 case MPUPLL_M_300:
314 return &dpll_mpu_opp[ind][0];
315 }
316
317 return &dpll_mpu_opp[ind][0];
318}
319
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530320static void scale_vcores_bone(int freq)
321{
322 int usb_cur_lim, mpu_vdd;
Tom Rini52437072013-08-30 16:28:46 -0400323
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530324 /*
325 * Only perform PMIC configurations if board rev > A1
326 * on Beaglebone White
327 */
328 if (board_is_bone() && !strncmp(board_ti_get_rev(), "00A1", 4))
329 return;
Tom Rini52437072013-08-30 16:28:46 -0400330
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530331 if (i2c_probe(TPS65217_CHIP_PM))
332 return;
Tom Rini52437072013-08-30 16:28:46 -0400333
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530334 /*
335 * On Beaglebone White we need to ensure we have AC power
336 * before increasing the frequency.
337 */
Lokesh Vutla6302e532017-05-05 12:59:10 +0530338 if (bone_not_connected_to_ac_power())
339 freq = MPUPLL_M_600;
Tom Rini52437072013-08-30 16:28:46 -0400340
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530341 /*
342 * Override what we have detected since we know if we have
343 * a Beaglebone Black it supports 1GHz.
344 */
Jason Kridnerb56b5b32018-03-07 05:40:41 -0500345 if (board_is_pb() || board_is_bone_lt())
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530346 freq = MPUPLL_M_1000;
Tom Rini52437072013-08-30 16:28:46 -0400347
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530348 switch (freq) {
349 case MPUPLL_M_1000:
350 mpu_vdd = TPS65217_DCDC_VOLT_SEL_1325MV;
351 usb_cur_lim = TPS65217_USB_INPUT_CUR_LIMIT_1800MA;
352 break;
353 case MPUPLL_M_800:
354 mpu_vdd = TPS65217_DCDC_VOLT_SEL_1275MV;
Lokesh Vutlae29609a2017-06-10 13:22:56 +0530355 usb_cur_lim = TPS65217_USB_INPUT_CUR_LIMIT_1300MA;
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530356 break;
357 case MPUPLL_M_720:
358 mpu_vdd = TPS65217_DCDC_VOLT_SEL_1200MV;
Lokesh Vutlae29609a2017-06-10 13:22:56 +0530359 usb_cur_lim = TPS65217_USB_INPUT_CUR_LIMIT_1300MA;
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530360 break;
361 case MPUPLL_M_600:
362 case MPUPLL_M_500:
363 case MPUPLL_M_300:
Lokesh Vutlae29609a2017-06-10 13:22:56 +0530364 default:
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530365 mpu_vdd = TPS65217_DCDC_VOLT_SEL_1100MV;
366 usb_cur_lim = TPS65217_USB_INPUT_CUR_LIMIT_1300MA;
367 break;
368 }
Steve Kipisz5adac352013-08-14 10:51:31 -0400369
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530370 if (tps65217_reg_write(TPS65217_PROT_LEVEL_NONE,
371 TPS65217_POWER_PATH,
372 usb_cur_lim,
373 TPS65217_USB_INPUT_CUR_LIMIT_MASK))
374 puts("tps65217_reg_write failure\n");
Tom Rini52437072013-08-30 16:28:46 -0400375
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530376 /* Set DCDC3 (CORE) voltage to 1.10V */
377 if (tps65217_voltage_update(TPS65217_DEFDCDC3,
378 TPS65217_DCDC_VOLT_SEL_1100MV)) {
379 puts("tps65217_voltage_update failure\n");
380 return;
381 }
Tom Rini52437072013-08-30 16:28:46 -0400382
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530383 /* Set DCDC2 (MPU) voltage */
384 if (tps65217_voltage_update(TPS65217_DEFDCDC2, mpu_vdd)) {
385 puts("tps65217_voltage_update failure\n");
386 return;
387 }
Tom Rini52437072013-08-30 16:28:46 -0400388
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530389 /*
390 * Set LDO3, LDO4 output voltage to 3.3V for Beaglebone.
391 * Set LDO3 to 1.8V and LDO4 to 3.3V for Beaglebone Black.
392 */
393 if (board_is_bone()) {
Tom Rini52437072013-08-30 16:28:46 -0400394 if (tps65217_reg_write(TPS65217_PROT_LEVEL_2,
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530395 TPS65217_DEFLS1,
Tom Rini52437072013-08-30 16:28:46 -0400396 TPS65217_LDO_VOLTAGE_OUT_3_3,
397 TPS65217_LDO_MASK))
398 puts("tps65217_reg_write failure\n");
399 } else {
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530400 if (tps65217_reg_write(TPS65217_PROT_LEVEL_2,
401 TPS65217_DEFLS1,
402 TPS65217_LDO_VOLTAGE_OUT_1_8,
403 TPS65217_LDO_MASK))
404 puts("tps65217_reg_write failure\n");
405 }
Tom Rini52437072013-08-30 16:28:46 -0400406
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530407 if (tps65217_reg_write(TPS65217_PROT_LEVEL_2,
408 TPS65217_DEFLS2,
409 TPS65217_LDO_VOLTAGE_OUT_3_3,
410 TPS65217_LDO_MASK))
411 puts("tps65217_reg_write failure\n");
412}
Tom Rini52437072013-08-30 16:28:46 -0400413
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530414void scale_vcores_generic(int freq)
415{
416 int sil_rev, mpu_vdd;
Tom Rini52437072013-08-30 16:28:46 -0400417
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530418 /*
419 * The GP EVM, IDK and EVM SK use a TPS65910 PMIC. For all
420 * MPU frequencies we support we use a CORE voltage of
421 * 1.10V. For MPU voltage we need to switch based on
422 * the frequency we are running at.
423 */
424 if (i2c_probe(TPS65910_CTRL_I2C_ADDR))
425 return;
Tom Rini52437072013-08-30 16:28:46 -0400426
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530427 /*
428 * Depending on MPU clock and PG we will need a different
429 * VDD to drive at that speed.
430 */
431 sil_rev = readl(&cdev->deviceid) >> 28;
432 mpu_vdd = am335x_get_tps65910_mpu_vdd(sil_rev, freq);
Tom Rini52437072013-08-30 16:28:46 -0400433
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530434 /* Tell the TPS65910 to use i2c */
435 tps65910_set_i2c_control();
Steve Kipisz5adac352013-08-14 10:51:31 -0400436
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530437 /* First update MPU voltage. */
438 if (tps65910_voltage_update(MPU, mpu_vdd))
439 return;
Tom Rini52437072013-08-30 16:28:46 -0400440
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530441 /* Second, update the CORE voltage. */
442 if (tps65910_voltage_update(CORE, TPS65910_OP_REG_SEL_1_1_0))
443 return;
444
Tom Rini52437072013-08-30 16:28:46 -0400445}
446
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530447void gpi2c_init(void)
Lokesh Vutla89a83bf2013-07-30 10:48:52 +0530448{
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530449 /* When needed to be invoked prior to BSS initialization */
450 static bool first_time = true;
451
452 if (first_time) {
453 enable_i2c0_pin_mux();
454 i2c_init(CONFIG_SYS_OMAP24_I2C_SPEED,
455 CONFIG_SYS_OMAP24_I2C_SLAVE);
456 first_time = false;
457 }
458}
459
460void scale_vcores(void)
461{
462 int freq;
463
464 gpi2c_init();
465 freq = am335x_get_efuse_mpu_max_freq(cdev);
466
Lokesh Vutlae29609a2017-06-10 13:22:56 +0530467 if (board_is_beaglebonex())
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530468 scale_vcores_bone(freq);
Lokesh Vutla89a83bf2013-07-30 10:48:52 +0530469 else
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530470 scale_vcores_generic(freq);
Lokesh Vutla89a83bf2013-07-30 10:48:52 +0530471}
472
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530473void set_uart_mux_conf(void)
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000474{
Tom Rini986d7552014-08-01 09:53:24 -0400475#if CONFIG_CONS_INDEX == 1
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000476 enable_uart0_pin_mux();
Tom Rini986d7552014-08-01 09:53:24 -0400477#elif CONFIG_CONS_INDEX == 2
Andrew Bradford65c51ff2012-10-25 08:21:30 -0400478 enable_uart1_pin_mux();
Tom Rini986d7552014-08-01 09:53:24 -0400479#elif CONFIG_CONS_INDEX == 3
Andrew Bradford65c51ff2012-10-25 08:21:30 -0400480 enable_uart2_pin_mux();
Tom Rini986d7552014-08-01 09:53:24 -0400481#elif CONFIG_CONS_INDEX == 4
Andrew Bradford65c51ff2012-10-25 08:21:30 -0400482 enable_uart3_pin_mux();
Tom Rini986d7552014-08-01 09:53:24 -0400483#elif CONFIG_CONS_INDEX == 5
Andrew Bradford65c51ff2012-10-25 08:21:30 -0400484 enable_uart4_pin_mux();
Tom Rini986d7552014-08-01 09:53:24 -0400485#elif CONFIG_CONS_INDEX == 6
Andrew Bradford65c51ff2012-10-25 08:21:30 -0400486 enable_uart5_pin_mux();
Tom Rini986d7552014-08-01 09:53:24 -0400487#endif
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530488}
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000489
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530490void set_mux_conf_regs(void)
491{
Nishanth Menon2afa70d2016-02-24 12:30:55 -0600492 enable_board_pin_mux();
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530493}
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000494
Lokesh Vutla303b2672013-12-10 15:02:21 +0530495const struct ctrl_ioregs ioregs_evmsk = {
496 .cm0ioctl = MT41J128MJT125_IOCTRL_VALUE,
497 .cm1ioctl = MT41J128MJT125_IOCTRL_VALUE,
498 .cm2ioctl = MT41J128MJT125_IOCTRL_VALUE,
499 .dt0ioctl = MT41J128MJT125_IOCTRL_VALUE,
500 .dt1ioctl = MT41J128MJT125_IOCTRL_VALUE,
501};
502
503const struct ctrl_ioregs ioregs_bonelt = {
504 .cm0ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
505 .cm1ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
506 .cm2ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
507 .dt0ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
508 .dt1ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
509};
510
511const struct ctrl_ioregs ioregs_evm15 = {
512 .cm0ioctl = MT41J512M8RH125_IOCTRL_VALUE,
513 .cm1ioctl = MT41J512M8RH125_IOCTRL_VALUE,
514 .cm2ioctl = MT41J512M8RH125_IOCTRL_VALUE,
515 .dt0ioctl = MT41J512M8RH125_IOCTRL_VALUE,
516 .dt1ioctl = MT41J512M8RH125_IOCTRL_VALUE,
517};
518
519const struct ctrl_ioregs ioregs = {
520 .cm0ioctl = MT47H128M16RT25E_IOCTRL_VALUE,
521 .cm1ioctl = MT47H128M16RT25E_IOCTRL_VALUE,
522 .cm2ioctl = MT47H128M16RT25E_IOCTRL_VALUE,
523 .dt0ioctl = MT47H128M16RT25E_IOCTRL_VALUE,
524 .dt1ioctl = MT47H128M16RT25E_IOCTRL_VALUE,
525};
526
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530527void sdram_init(void)
528{
Nishanth Menon2afa70d2016-02-24 12:30:55 -0600529 if (board_is_evm_sk()) {
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000530 /*
531 * EVM SK 1.2A and later use gpio0_7 to enable DDR3.
532 * This is safe enough to do on older revs.
533 */
534 gpio_request(GPIO_DDR_VTT_EN, "ddr_vtt_en");
535 gpio_direction_output(GPIO_DDR_VTT_EN, 1);
536 }
537
Lokesh Vutla5837b902016-05-16 11:47:24 +0530538 if (board_is_icev2()) {
539 gpio_request(ICE_GPIO_DDR_VTT_EN, "ddr_vtt_en");
540 gpio_direction_output(ICE_GPIO_DDR_VTT_EN, 1);
541 }
542
Nishanth Menon2afa70d2016-02-24 12:30:55 -0600543 if (board_is_evm_sk())
Lokesh Vutla303b2672013-12-10 15:02:21 +0530544 config_ddr(303, &ioregs_evmsk, &ddr3_data,
Matt Porter65991ec2013-03-15 10:07:03 +0000545 &ddr3_cmd_ctrl_data, &ddr3_emif_reg_data, 0);
Jason Kridnerb56b5b32018-03-07 05:40:41 -0500546 else if (board_is_pb() || board_is_bone_lt())
Lokesh Vutla303b2672013-12-10 15:02:21 +0530547 config_ddr(400, &ioregs_bonelt,
Tom Rini385bc752013-03-21 04:30:02 +0000548 &ddr3_beagleblack_data,
549 &ddr3_beagleblack_cmd_ctrl_data,
550 &ddr3_beagleblack_emif_reg_data, 0);
Nishanth Menon2afa70d2016-02-24 12:30:55 -0600551 else if (board_is_evm_15_or_later())
Lokesh Vutla303b2672013-12-10 15:02:21 +0530552 config_ddr(303, &ioregs_evm15, &ddr3_evm_data,
Matt Porter65991ec2013-03-15 10:07:03 +0000553 &ddr3_evm_cmd_ctrl_data, &ddr3_evm_emif_reg_data, 0);
Lokesh Vutla5837b902016-05-16 11:47:24 +0530554 else if (board_is_icev2())
555 config_ddr(400, &ioregs_evmsk, &ddr3_icev2_data,
556 &ddr3_icev2_cmd_ctrl_data, &ddr3_icev2_emif_reg_data,
557 0);
Jyri Sarha8d2998b2016-12-09 12:29:13 +0200558 else if (board_is_gp_evm())
559 config_ddr(266, &ioregs, &ddr2_data,
560 &ddr2_cmd_ctrl_data, &ddr2_evm_emif_reg_data, 0);
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000561 else
Lokesh Vutla303b2672013-12-10 15:02:21 +0530562 config_ddr(266, &ioregs, &ddr2_data,
Matt Porter65991ec2013-03-15 10:07:03 +0000563 &ddr2_cmd_ctrl_data, &ddr2_emif_reg_data, 0);
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000564}
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530565#endif
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000566
Alex Kiernan20bba2e2018-04-01 09:22:37 +0000567#if defined(CONFIG_CLOCK_SYNTHESIZER) && (!defined(CONFIG_SPL_BUILD) || \
568 (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD)))
Roger Quadrosbcb4ee82016-08-24 15:35:50 +0300569static void request_and_set_gpio(int gpio, char *name, int val)
Lokesh Vutla0d144f52016-05-16 11:47:26 +0530570{
571 int ret;
572
573 ret = gpio_request(gpio, name);
574 if (ret < 0) {
575 printf("%s: Unable to request %s\n", __func__, name);
576 return;
577 }
578
579 ret = gpio_direction_output(gpio, 0);
580 if (ret < 0) {
581 printf("%s: Unable to set %s as output\n", __func__, name);
582 goto err_free_gpio;
583 }
584
Roger Quadrosbcb4ee82016-08-24 15:35:50 +0300585 gpio_set_value(gpio, val);
Lokesh Vutla0d144f52016-05-16 11:47:26 +0530586
587 return;
588
589err_free_gpio:
590 gpio_free(gpio);
591}
592
Roger Quadrosbcb4ee82016-08-24 15:35:50 +0300593#define REQUEST_AND_SET_GPIO(N) request_and_set_gpio(N, #N, 1);
594#define REQUEST_AND_CLR_GPIO(N) request_and_set_gpio(N, #N, 0);
Lokesh Vutla0d144f52016-05-16 11:47:26 +0530595
596/**
597 * RMII mode on ICEv2 board needs 50MHz clock. Given the clock
598 * synthesizer With a capacitor of 18pF, and 25MHz input clock cycle
599 * PLL1 gives an output of 100MHz. So, configuring the div2/3 as 2 to
600 * give 50MHz output for Eth0 and 1.
601 */
602static struct clk_synth cdce913_data = {
603 .id = 0x81,
604 .capacitor = 0x90,
605 .mux = 0x6d,
606 .pdiv2 = 0x2,
607 .pdiv3 = 0x2,
608};
609#endif
610
Sekhar Norif357b112018-08-23 17:11:30 +0530611#if defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_CONTROL) && \
612 defined(CONFIG_DM_ETH) && defined(CONFIG_DRIVER_TI_CPSW)
613
614#define MAX_CPSW_SLAVES 2
615
616/* At the moment, we do not want to stop booting for any failures here */
617int ft_board_setup(void *fdt, bd_t *bd)
618{
619 const char *slave_path, *enet_name;
620 int enetnode, slavenode, phynode;
621 struct udevice *ethdev;
622 char alias[16];
623 u32 phy_id[2];
624 int phy_addr;
625 int i, ret;
626
627 /* phy address fixup needed only on beagle bone family */
628 if (!board_is_beaglebonex())
629 goto done;
630
631 for (i = 0; i < MAX_CPSW_SLAVES; i++) {
632 sprintf(alias, "ethernet%d", i);
633
634 slave_path = fdt_get_alias(fdt, alias);
635 if (!slave_path)
636 continue;
637
638 slavenode = fdt_path_offset(fdt, slave_path);
639 if (slavenode < 0)
640 continue;
641
642 enetnode = fdt_parent_offset(fdt, slavenode);
643 enet_name = fdt_get_name(fdt, enetnode, NULL);
644
645 ethdev = eth_get_dev_by_name(enet_name);
646 if (!ethdev)
647 continue;
648
649 phy_addr = cpsw_get_slave_phy_addr(ethdev, i);
650
651 /* check for phy_id as well as phy-handle properties */
652 ret = fdtdec_get_int_array_count(fdt, slavenode, "phy_id",
653 phy_id, 2);
654 if (ret == 2) {
655 if (phy_id[1] != phy_addr) {
656 printf("fixing up phy_id for %s, old: %d, new: %d\n",
657 alias, phy_id[1], phy_addr);
658
659 phy_id[0] = cpu_to_fdt32(phy_id[0]);
660 phy_id[1] = cpu_to_fdt32(phy_addr);
661 do_fixup_by_path(fdt, slave_path, "phy_id",
662 phy_id, sizeof(phy_id), 0);
663 }
664 } else {
665 phynode = fdtdec_lookup_phandle(fdt, slavenode,
666 "phy-handle");
667 if (phynode < 0)
668 continue;
669
670 ret = fdtdec_get_int(fdt, phynode, "reg", -ENOENT);
671 if (ret < 0)
672 continue;
673
674 if (ret != phy_addr) {
675 printf("fixing up phy-handle for %s, old: %d, new: %d\n",
676 alias, ret, phy_addr);
677
678 fdt_setprop_u32(fdt, phynode, "reg",
679 cpu_to_fdt32(phy_addr));
680 }
681 }
682 }
683
684done:
685 return 0;
686}
687#endif
688
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000689/*
690 * Basic board specific setup. Pinmux has been handled already.
691 */
692int board_init(void)
693{
Tom Rini303bfe82013-10-01 12:32:04 -0400694#if defined(CONFIG_HW_WATCHDOG)
695 hw_watchdog_init();
696#endif
697
Tom Rinif3b6a1d2013-08-09 11:22:13 -0400698 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
pekon gupta53b4b322013-11-18 19:03:02 +0530699#if defined(CONFIG_NOR) || defined(CONFIG_NAND)
Ilya Yanok3d9725e2012-11-06 13:06:31 +0000700 gpmc_init();
Steve Kipiszbe9b6f82013-07-18 15:13:03 -0400701#endif
Lokesh Vutla0d144f52016-05-16 11:47:26 +0530702
Alex Kiernan20bba2e2018-04-01 09:22:37 +0000703#if defined(CONFIG_CLOCK_SYNTHESIZER) && (!defined(CONFIG_SPL_BUILD) || \
704 (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD)))
Lokesh Vutla0d144f52016-05-16 11:47:26 +0530705 if (board_is_icev2()) {
Roger Quadrosbcb4ee82016-08-24 15:35:50 +0300706 int rv;
707 u32 reg;
708
Lokesh Vutla0d144f52016-05-16 11:47:26 +0530709 REQUEST_AND_SET_GPIO(GPIO_PR1_MII_CTRL);
Roger Quadrosbcb4ee82016-08-24 15:35:50 +0300710 /* Make J19 status available on GPIO1_26 */
711 REQUEST_AND_CLR_GPIO(GPIO_MUX_MII_CTRL);
712
Lokesh Vutla0d144f52016-05-16 11:47:26 +0530713 REQUEST_AND_SET_GPIO(GPIO_FET_SWITCH_CTRL);
Roger Quadrosbcb4ee82016-08-24 15:35:50 +0300714 /*
715 * Both ports can be set as RMII-CPSW or MII-PRU-ETH using
716 * jumpers near the port. Read the jumper value and set
717 * the pinmux, external mux and PHY clock accordingly.
718 * As jumper line is overridden by PHY RX_DV pin immediately
719 * after bootstrap (power-up/reset), we need to sample
720 * it during PHY reset using GPIO rising edge detection.
721 */
Lokesh Vutla0d144f52016-05-16 11:47:26 +0530722 REQUEST_AND_SET_GPIO(GPIO_PHY_RESET);
Roger Quadrosbcb4ee82016-08-24 15:35:50 +0300723 /* Enable rising edge IRQ on GPIO0_11 and GPIO 1_26 */
724 reg = readl(GPIO0_RISINGDETECT) | BIT(11);
725 writel(reg, GPIO0_RISINGDETECT);
726 reg = readl(GPIO1_RISINGDETECT) | BIT(26);
727 writel(reg, GPIO1_RISINGDETECT);
728 /* Reset PHYs to capture the Jumper setting */
729 gpio_set_value(GPIO_PHY_RESET, 0);
730 udelay(2); /* PHY datasheet states 1uS min. */
731 gpio_set_value(GPIO_PHY_RESET, 1);
732
733 reg = readl(GPIO0_IRQSTATUSRAW) & BIT(11);
734 if (reg) {
735 writel(reg, GPIO0_IRQSTATUS1); /* clear irq */
736 /* RMII mode */
737 printf("ETH0, CPSW\n");
738 } else {
739 /* MII mode */
740 printf("ETH0, PRU\n");
741 cdce913_data.pdiv3 = 4; /* 25MHz PHY clk */
742 }
743
744 reg = readl(GPIO1_IRQSTATUSRAW) & BIT(26);
745 if (reg) {
746 writel(reg, GPIO1_IRQSTATUS1); /* clear irq */
747 /* RMII mode */
748 printf("ETH1, CPSW\n");
749 gpio_set_value(GPIO_MUX_MII_CTRL, 1);
750 } else {
751 /* MII mode */
752 printf("ETH1, PRU\n");
753 cdce913_data.pdiv2 = 4; /* 25MHz PHY clk */
754 }
755
756 /* disable rising edge IRQs */
757 reg = readl(GPIO0_RISINGDETECT) & ~BIT(11);
758 writel(reg, GPIO0_RISINGDETECT);
759 reg = readl(GPIO1_RISINGDETECT) & ~BIT(26);
760 writel(reg, GPIO1_RISINGDETECT);
Lokesh Vutla0d144f52016-05-16 11:47:26 +0530761
762 rv = setup_clock_synthesizer(&cdce913_data);
763 if (rv) {
764 printf("Clock synthesizer setup failed %d\n", rv);
765 return rv;
766 }
Roger Quadrosbcb4ee82016-08-24 15:35:50 +0300767
768 /* reset PHYs */
769 gpio_set_value(GPIO_PHY_RESET, 0);
770 udelay(2); /* PHY datasheet states 1uS min. */
771 gpio_set_value(GPIO_PHY_RESET, 1);
Lokesh Vutla0d144f52016-05-16 11:47:26 +0530772 }
773#endif
774
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000775 return 0;
776}
777
Tom Rini40271852012-10-24 07:28:17 +0000778#ifdef CONFIG_BOARD_LATE_INIT
779int board_late_init(void)
780{
Roger Quadros7c9d3782016-08-24 15:35:51 +0300781#if !defined(CONFIG_SPL_BUILD)
782 uint8_t mac_addr[6];
783 uint32_t mac_hi, mac_lo;
784#endif
785
Tom Rini40271852012-10-24 07:28:17 +0000786#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
Nishanth Menon2afa70d2016-02-24 12:30:55 -0600787 char *name = NULL;
Tom Rini4021fd92013-07-18 15:13:01 -0400788
robertcnelson@gmail.comc5d7d222017-03-30 14:29:52 -0500789 if (board_is_bone_lt()) {
790 /* BeagleBoard.org BeagleBone Black Wireless: */
791 if (!strncmp(board_ti_get_rev(), "BWA", 3)) {
792 name = "BBBW";
793 }
robertcnelson@gmail.comb55cd7a2017-03-30 14:29:53 -0500794 /* SeeedStudio BeagleBone Green Wireless */
795 if (!strncmp(board_ti_get_rev(), "GW1", 3)) {
796 name = "BBGW";
797 }
robertcnelson@gmail.com89ef1d62017-03-30 14:29:54 -0500798 /* BeagleBoard.org BeagleBone Blue */
799 if (!strncmp(board_ti_get_rev(), "BLA", 3)) {
800 name = "BBBL";
801 }
robertcnelson@gmail.comc5d7d222017-03-30 14:29:52 -0500802 }
803
Nishanth Menon2afa70d2016-02-24 12:30:55 -0600804 if (board_is_bbg1())
805 name = "BBG1";
Koen Kooi8a157862018-07-18 10:13:59 +0200806 if (board_is_bben())
807 name = "BBEN";
Nishanth Menon2afa70d2016-02-24 12:30:55 -0600808 set_board_info_env(name);
Lokesh Vutla1eb0f542016-11-29 11:58:03 +0530809
810 /*
811 * Default FIT boot on HS devices. Non FIT images are not allowed
812 * on HS devices.
813 */
814 if (get_device_type() == HS_DEVICE)
Simon Glass6a38e412017-08-03 12:22:09 -0600815 env_set("boot_fit", "1");
Tom Rini40271852012-10-24 07:28:17 +0000816#endif
817
Roger Quadros7c9d3782016-08-24 15:35:51 +0300818#if !defined(CONFIG_SPL_BUILD)
819 /* try reading mac address from efuse */
820 mac_lo = readl(&cdev->macid0l);
821 mac_hi = readl(&cdev->macid0h);
822 mac_addr[0] = mac_hi & 0xFF;
823 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
824 mac_addr[2] = (mac_hi & 0xFF0000) >> 16;
825 mac_addr[3] = (mac_hi & 0xFF000000) >> 24;
826 mac_addr[4] = mac_lo & 0xFF;
827 mac_addr[5] = (mac_lo & 0xFF00) >> 8;
828
Simon Glass64b723f2017-08-03 12:22:12 -0600829 if (!env_get("ethaddr")) {
Roger Quadros7c9d3782016-08-24 15:35:51 +0300830 printf("<ethaddr> not set. Validating first E-fuse MAC\n");
831
832 if (is_valid_ethaddr(mac_addr))
Simon Glass8551d552017-08-03 12:22:11 -0600833 eth_env_set_enetaddr("ethaddr", mac_addr);
Roger Quadros7c9d3782016-08-24 15:35:51 +0300834 }
835
836 mac_lo = readl(&cdev->macid1l);
837 mac_hi = readl(&cdev->macid1h);
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("eth1addr")) {
Roger Quadros7c9d3782016-08-24 15:35:51 +0300846 if (is_valid_ethaddr(mac_addr))
Simon Glass8551d552017-08-03 12:22:11 -0600847 eth_env_set_enetaddr("eth1addr", mac_addr);
Roger Quadros7c9d3782016-08-24 15:35:51 +0300848 }
849#endif
850
Sam Protsenkoa31ca622018-02-28 00:26:15 +0200851 if (!env_get("serial#")) {
852 char *board_serial = env_get("board_serial");
853 char *ethaddr = env_get("ethaddr");
854
855 if (!board_serial || !strncmp(board_serial, "unknown", 7))
856 env_set("serial#", ethaddr);
857 else
858 env_set("serial#", board_serial);
859 }
860
Tom Rini40271852012-10-24 07:28:17 +0000861 return 0;
862}
863#endif
864
Mugunthan V Ndf7a99f2015-09-07 14:22:18 +0530865#ifndef CONFIG_DM_ETH
866
Ilya Yanok0760a0d2013-02-05 11:36:26 +0000867#if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) || \
868 (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD))
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000869static void cpsw_control(int enabled)
870{
871 /* VTP can be added here */
872
873 return;
874}
875
876static struct cpsw_slave_data cpsw_slaves[] = {
877 {
878 .slave_reg_ofs = 0x208,
879 .sliver_reg_ofs = 0xd80,
Mugunthan V N4944f372014-02-18 07:31:52 -0500880 .phy_addr = 0,
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000881 },
882 {
883 .slave_reg_ofs = 0x308,
884 .sliver_reg_ofs = 0xdc0,
Mugunthan V N4944f372014-02-18 07:31:52 -0500885 .phy_addr = 1,
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000886 },
887};
888
889static struct cpsw_platform_data cpsw_data = {
Matt Portere24646f2013-03-15 10:07:02 +0000890 .mdio_base = CPSW_MDIO_BASE,
891 .cpsw_base = CPSW_BASE,
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000892 .mdio_div = 0xff,
893 .channels = 8,
894 .cpdma_reg_ofs = 0x800,
895 .slaves = 1,
896 .slave_data = cpsw_slaves,
897 .ale_reg_ofs = 0xd00,
898 .ale_entries = 1024,
899 .host_port_reg_ofs = 0x108,
900 .hw_stats_reg_ofs = 0x900,
Mugunthan V Nff559872013-07-08 16:04:37 +0530901 .bd_ram_ofs = 0x2000,
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000902 .mac_control = (1 << 5),
903 .control = cpsw_control,
904 .host_port_num = 0,
905 .version = CPSW_CTRL_VERSION_2,
906};
Ilya Yanok44a2c072012-11-06 13:48:24 +0000907#endif
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000908
Faiz Abbasc01553b2018-02-16 21:17:44 +0530909#if ((defined(CONFIG_SPL_ETH_SUPPORT) || defined(CONFIG_SPL_USB_ETHER)) &&\
Lokesh Vutla0d144f52016-05-16 11:47:26 +0530910 defined(CONFIG_SPL_BUILD)) || \
911 ((defined(CONFIG_DRIVER_TI_CPSW) || \
912 defined(CONFIG_USB_ETHER) && defined(CONFIG_MUSB_GADGET)) && \
913 !defined(CONFIG_SPL_BUILD))
914
Tom Rini60fcaaa2014-03-26 15:53:12 -0400915/*
916 * This function will:
917 * Read the eFuse for MAC addresses, and set ethaddr/eth1addr/usbnet_devaddr
918 * in the environment
919 * Perform fixups to the PHY present on certain boards. We only need this
920 * function in:
921 * - SPL with either CPSW or USB ethernet support
922 * - Full U-Boot, with either CPSW or USB ethernet
923 * Build in only these cases to avoid warnings about unused variables
924 * when we build an SPL that has neither option but full U-Boot will.
925 */
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000926int board_eth_init(bd_t *bis)
927{
Ilya Yanok44a2c072012-11-06 13:48:24 +0000928 int rv, n = 0;
Roger Quadros7c9d3782016-08-24 15:35:51 +0300929#if defined(CONFIG_USB_ETHER) && \
Faiz Abbasc01553b2018-02-16 21:17:44 +0530930 (!defined(CONFIG_SPL_BUILD) || defined(CONFIG_SPL_USB_ETHER))
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000931 uint8_t mac_addr[6];
932 uint32_t mac_hi, mac_lo;
933
Roger Quadros7c9d3782016-08-24 15:35:51 +0300934 /*
935 * use efuse mac address for USB ethernet as we know that
936 * both CPSW and USB ethernet will never be active at the same time
937 */
Ilya Yanok0760a0d2013-02-05 11:36:26 +0000938 mac_lo = readl(&cdev->macid0l);
939 mac_hi = readl(&cdev->macid0h);
940 mac_addr[0] = mac_hi & 0xFF;
941 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
942 mac_addr[2] = (mac_hi & 0xFF0000) >> 16;
943 mac_addr[3] = (mac_hi & 0xFF000000) >> 24;
944 mac_addr[4] = mac_lo & 0xFF;
945 mac_addr[5] = (mac_lo & 0xFF00) >> 8;
Roger Quadros7c9d3782016-08-24 15:35:51 +0300946#endif
947
Ilya Yanok0760a0d2013-02-05 11:36:26 +0000948
949#if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) || \
950 (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD))
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000951
Joel A Fernandesf7488542013-05-07 05:52:55 +0000952#ifdef CONFIG_DRIVER_TI_CPSW
Koen Kooi8a157862018-07-18 10:13:59 +0200953 if (board_is_bone() || board_is_bone_lt() || board_is_bben() ||
Nishanth Menon2afa70d2016-02-24 12:30:55 -0600954 board_is_idk()) {
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000955 writel(MII_MODE_ENABLE, &cdev->miisel);
956 cpsw_slaves[0].phy_if = cpsw_slaves[1].phy_if =
957 PHY_INTERFACE_MODE_MII;
Lokesh Vutla0d144f52016-05-16 11:47:26 +0530958 } else if (board_is_icev2()) {
959 writel(RMII_MODE_ENABLE | RMII_CHIPCKL_ENABLE, &cdev->miisel);
960 cpsw_slaves[0].phy_if = PHY_INTERFACE_MODE_RMII;
961 cpsw_slaves[1].phy_if = PHY_INTERFACE_MODE_RMII;
962 cpsw_slaves[0].phy_addr = 1;
963 cpsw_slaves[1].phy_addr = 3;
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000964 } else {
Heiko Schocherc4fea292013-08-19 16:38:56 +0200965 writel((RGMII_MODE_ENABLE | RGMII_INT_DELAY), &cdev->miisel);
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000966 cpsw_slaves[0].phy_if = cpsw_slaves[1].phy_if =
967 PHY_INTERFACE_MODE_RGMII;
968 }
969
Ilya Yanok44a2c072012-11-06 13:48:24 +0000970 rv = cpsw_register(&cpsw_data);
971 if (rv < 0)
972 printf("Error %d registering CPSW switch\n", rv);
973 else
974 n += rv;
Joel A Fernandesf7488542013-05-07 05:52:55 +0000975#endif
Tom Rini183943d2013-02-12 14:59:23 -0500976
977 /*
978 *
979 * CPSW RGMII Internal Delay Mode is not supported in all PVT
980 * operating points. So we must set the TX clock delay feature
981 * in the AR8051 PHY. Since we only support a single ethernet
982 * device in U-Boot, we only do this for the first instance.
983 */
984#define AR8051_PHY_DEBUG_ADDR_REG 0x1d
985#define AR8051_PHY_DEBUG_DATA_REG 0x1e
986#define AR8051_DEBUG_RGMII_CLK_DLY_REG 0x5
987#define AR8051_RGMII_TX_CLK_DLY 0x100
988
Koen Kooi8a157862018-07-18 10:13:59 +0200989 if (board_is_evm_sk() || board_is_gp_evm() || board_is_bben()) {
Tom Rini183943d2013-02-12 14:59:23 -0500990 const char *devname;
991 devname = miiphy_get_current_dev();
992
993 miiphy_write(devname, 0x0, AR8051_PHY_DEBUG_ADDR_REG,
994 AR8051_DEBUG_RGMII_CLK_DLY_REG);
995 miiphy_write(devname, 0x0, AR8051_PHY_DEBUG_DATA_REG,
996 AR8051_RGMII_TX_CLK_DLY);
997 }
Ilya Yanok44a2c072012-11-06 13:48:24 +0000998#endif
Ilya Yanok0760a0d2013-02-05 11:36:26 +0000999#if defined(CONFIG_USB_ETHER) && \
Faiz Abbasc01553b2018-02-16 21:17:44 +05301000 (!defined(CONFIG_SPL_BUILD) || defined(CONFIG_SPL_USB_ETHER))
Joe Hershberger8ecdbed2015-04-08 01:41:04 -05001001 if (is_valid_ethaddr(mac_addr))
Simon Glass8551d552017-08-03 12:22:11 -06001002 eth_env_set_enetaddr("usbnet_devaddr", mac_addr);
Ilya Yanok0760a0d2013-02-05 11:36:26 +00001003
Ilya Yanok44a2c072012-11-06 13:48:24 +00001004 rv = usb_eth_initialize(bis);
1005 if (rv < 0)
1006 printf("Error %d registering USB_ETHER\n", rv);
1007 else
1008 n += rv;
1009#endif
1010 return n;
Peter Korsgaard85ec2db2012-10-18 01:21:09 +00001011}
1012#endif
Mugunthan V Ndf7a99f2015-09-07 14:22:18 +05301013
1014#endif /* CONFIG_DM_ETH */
Lokesh Vutla89b9f302016-05-16 11:24:24 +05301015
1016#ifdef CONFIG_SPL_LOAD_FIT
1017int board_fit_config_name_match(const char *name)
1018{
1019 if (board_is_gp_evm() && !strcmp(name, "am335x-evm"))
1020 return 0;
1021 else if (board_is_bone() && !strcmp(name, "am335x-bone"))
1022 return 0;
1023 else if (board_is_bone_lt() && !strcmp(name, "am335x-boneblack"))
1024 return 0;
Jason Kridnerb56b5b32018-03-07 05:40:41 -05001025 else if (board_is_pb() && !strcmp(name, "am335x-pocketbeagle"))
1026 return 0;
Lokesh Vutla5a954ba2016-05-16 11:24:28 +05301027 else if (board_is_evm_sk() && !strcmp(name, "am335x-evmsk"))
1028 return 0;
Lokesh Vutla1edfcaf2016-05-16 11:24:29 +05301029 else if (board_is_bbg1() && !strcmp(name, "am335x-bonegreen"))
1030 return 0;
Lokesh Vutla7ecf1962016-05-16 11:47:28 +05301031 else if (board_is_icev2() && !strcmp(name, "am335x-icev2"))
1032 return 0;
Lokesh Vutla89b9f302016-05-16 11:24:24 +05301033 else
1034 return -1;
1035}
1036#endif
Andrew F. Davisbd249152016-08-30 14:06:24 -05001037
1038#ifdef CONFIG_TI_SECURE_DEVICE
1039void board_fit_image_post_process(void **p_image, size_t *p_size)
1040{
1041 secure_boot_verify_image(p_image, p_size);
1042}
1043#endif
Lokesh Vutla2fe7c792017-04-26 13:37:08 +05301044
1045#if !CONFIG_IS_ENABLED(OF_CONTROL)
1046static const struct omap_hsmmc_plat am335x_mmc0_platdata = {
1047 .base_addr = (struct hsmmc *)OMAP_HSMMC1_BASE,
1048 .cfg.host_caps = MMC_MODE_HS_52MHz | MMC_MODE_HS | MMC_MODE_4BIT,
1049 .cfg.f_min = 400000,
1050 .cfg.f_max = 52000000,
1051 .cfg.voltages = MMC_VDD_32_33 | MMC_VDD_33_34 | MMC_VDD_165_195,
1052 .cfg.b_max = CONFIG_SYS_MMC_MAX_BLK_COUNT,
1053};
1054
1055U_BOOT_DEVICE(am335x_mmc0) = {
1056 .name = "omap_hsmmc",
1057 .platdata = &am335x_mmc0_platdata,
1058};
1059
1060static const struct omap_hsmmc_plat am335x_mmc1_platdata = {
1061 .base_addr = (struct hsmmc *)OMAP_HSMMC2_BASE,
1062 .cfg.host_caps = MMC_MODE_HS_52MHz | MMC_MODE_HS | MMC_MODE_8BIT,
1063 .cfg.f_min = 400000,
1064 .cfg.f_max = 52000000,
1065 .cfg.voltages = MMC_VDD_32_33 | MMC_VDD_33_34 | MMC_VDD_165_195,
1066 .cfg.b_max = CONFIG_SYS_MMC_MAX_BLK_COUNT,
1067};
1068
1069U_BOOT_DEVICE(am335x_mmc1) = {
1070 .name = "omap_hsmmc",
1071 .platdata = &am335x_mmc1_platdata,
1072};
1073#endif