blob: 5959ff73dc45460e5cad5fdb547122beee683fb9 [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 Glass2dc9c342020-05-10 11:40:01 -060014#include <image.h>
Simon Glassa7b51302019-11-14 12:57:46 -070015#include <init.h>
Simon Glass9bc15642020-02-03 07:36:16 -070016#include <malloc.h>
Simon Glass274e0b02020-05-10 11:39:56 -060017#include <net.h>
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000018#include <spl.h>
Lokesh Vutlaabb44e62016-05-16 11:47:29 +053019#include <serial.h>
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000020#include <asm/arch/cpu.h>
21#include <asm/arch/hardware.h>
22#include <asm/arch/omap.h>
23#include <asm/arch/ddr_defs.h>
24#include <asm/arch/clock.h>
Lokesh Vutla0d144f52016-05-16 11:47:26 +053025#include <asm/arch/clk_synthesizer.h>
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000026#include <asm/arch/gpio.h>
27#include <asm/arch/mmc_host_def.h>
28#include <asm/arch/sys_proto.h>
Steve Kipiszbe9b6f82013-07-18 15:13:03 -040029#include <asm/arch/mem.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060030#include <asm/global_data.h>
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000031#include <asm/io.h>
32#include <asm/emif.h>
33#include <asm/gpio.h>
Semen Protsenkoa8cb0222017-06-02 18:00:00 +030034#include <asm/omap_common.h>
Andrew F. Davisbd249152016-08-30 14:06:24 -050035#include <asm/omap_sec_common.h>
Lokesh Vutla2fe7c792017-04-26 13:37:08 +053036#include <asm/omap_mmc.h>
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000037#include <i2c.h>
38#include <miiphy.h>
39#include <cpsw.h>
Simon Glass4dcacfc2020-05-10 11:40:13 -060040#include <linux/bitops.h>
Simon Glassdbd79542020-05-10 11:40:11 -060041#include <linux/delay.h>
Tom Rini52437072013-08-30 16:28:46 -040042#include <power/tps65217.h>
43#include <power/tps65910.h>
Simon Glass9d1f6192019-08-02 09:44:25 -060044#include <env_internal.h>
Tom Rini303bfe82013-10-01 12:32:04 -040045#include <watchdog.h>
Nishanth Menon2afa70d2016-02-24 12:30:55 -060046#include "../common/board_detect.h"
Kory Maincent169bf972021-05-04 19:31:30 +020047#include "../common/cape_detect.h"
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000048#include "board.h"
49
50DECLARE_GLOBAL_DATA_PTR;
51
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000052/* GPIO that controls power to DDR on EVM-SK */
Lokesh Vutla0d144f52016-05-16 11:47:26 +053053#define GPIO_TO_PIN(bank, gpio) (32 * (bank) + (gpio))
54#define GPIO_DDR_VTT_EN GPIO_TO_PIN(0, 7)
55#define ICE_GPIO_DDR_VTT_EN GPIO_TO_PIN(0, 18)
56#define GPIO_PR1_MII_CTRL GPIO_TO_PIN(3, 4)
57#define GPIO_MUX_MII_CTRL GPIO_TO_PIN(3, 10)
58#define GPIO_FET_SWITCH_CTRL GPIO_TO_PIN(0, 7)
59#define GPIO_PHY_RESET GPIO_TO_PIN(2, 5)
Roger Quadrosbcb4ee82016-08-24 15:35:50 +030060#define GPIO_ETH0_MODE GPIO_TO_PIN(0, 11)
61#define GPIO_ETH1_MODE GPIO_TO_PIN(1, 26)
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000062
63static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
64
Roger Quadrosbcb4ee82016-08-24 15:35:50 +030065#define GPIO0_RISINGDETECT (AM33XX_GPIO0_BASE + OMAP_GPIO_RISINGDETECT)
66#define GPIO1_RISINGDETECT (AM33XX_GPIO1_BASE + OMAP_GPIO_RISINGDETECT)
67
68#define GPIO0_IRQSTATUS1 (AM33XX_GPIO0_BASE + OMAP_GPIO_IRQSTATUS1)
69#define GPIO1_IRQSTATUS1 (AM33XX_GPIO1_BASE + OMAP_GPIO_IRQSTATUS1)
70
71#define GPIO0_IRQSTATUSRAW (AM33XX_GPIO0_BASE + 0x024)
72#define GPIO1_IRQSTATUSRAW (AM33XX_GPIO1_BASE + 0x024)
73
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000074/*
75 * Read header information from EEPROM into global structure.
76 */
Lokesh Vutla93e0f5b2016-10-14 10:35:25 +053077#ifdef CONFIG_TI_I2C_BOARD_DETECT
78void do_board_detect(void)
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000079{
Lokesh Vutla93e0f5b2016-10-14 10:35:25 +053080 enable_i2c0_pin_mux();
Kory Maincent4c1a71d2021-05-04 19:31:29 +020081 enable_i2c2_pin_mux();
Igor Opaniukf7c91762021-02-09 13:52:45 +020082#if !CONFIG_IS_ENABLED(DM_I2C)
Lokesh Vutla93e0f5b2016-10-14 10:35:25 +053083 i2c_init(CONFIG_SYS_OMAP24_I2C_SPEED, CONFIG_SYS_OMAP24_I2C_SLAVE);
Kory Maincent4c1a71d2021-05-04 19:31:29 +020084 i2c_init(CONFIG_SYS_OMAP24_I2C_SPEED2, CONFIG_SYS_OMAP24_I2C_SLAVE2);
Jean-Jacques Hiblot52a51512018-12-07 14:50:49 +010085#endif
Simon Glass4df67572017-05-12 21:09:55 -060086 if (ti_i2c_eeprom_am_get(CONFIG_EEPROM_BUS_ADDRESS,
87 CONFIG_EEPROM_CHIP_ADDRESS))
Lokesh Vutla93e0f5b2016-10-14 10:35:25 +053088 printf("ti_i2c_eeprom_init failed\n");
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000089}
Lokesh Vutla93e0f5b2016-10-14 10:35:25 +053090#endif
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000091
Lokesh Vutlaabb44e62016-05-16 11:47:29 +053092#ifndef CONFIG_DM_SERIAL
93struct serial_device *default_serial_console(void)
94{
95 if (board_is_icev2())
96 return &eserial4_device;
97 else
98 return &eserial1_device;
99}
100#endif
101
Tom Rini8de09df2014-04-09 08:25:57 -0400102#ifndef CONFIG_SKIP_LOWLEVEL_INIT
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000103static const struct ddr_data ddr2_data = {
Tom Rini7f50a572014-07-07 21:40:16 -0400104 .datardsratio0 = MT47H128M16RT25E_RD_DQS,
105 .datafwsratio0 = MT47H128M16RT25E_PHY_FIFO_WE,
106 .datawrsratio0 = MT47H128M16RT25E_PHY_WR_DATA,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000107};
108
109static const struct cmd_control ddr2_cmd_ctrl_data = {
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000110 .cmd0csratio = MT47H128M16RT25E_RATIO,
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000111
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000112 .cmd1csratio = MT47H128M16RT25E_RATIO,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000113
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000114 .cmd2csratio = MT47H128M16RT25E_RATIO,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000115};
116
117static const struct emif_regs ddr2_emif_reg_data = {
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000118 .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 .emif_ddr_phy_ctlr_1 = MT47H128M16RT25E_EMIF_READ_LATENCY,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000124};
125
Jyri Sarha8d2998b2016-12-09 12:29:13 +0200126static const struct emif_regs ddr2_evm_emif_reg_data = {
127 .sdram_config = MT47H128M16RT25E_EMIF_SDCFG,
128 .ref_ctrl = MT47H128M16RT25E_EMIF_SDREF,
129 .sdram_tim1 = MT47H128M16RT25E_EMIF_TIM1,
130 .sdram_tim2 = MT47H128M16RT25E_EMIF_TIM2,
131 .sdram_tim3 = MT47H128M16RT25E_EMIF_TIM3,
132 .ocp_config = EMIF_OCP_CONFIG_AM335X_EVM,
133 .emif_ddr_phy_ctlr_1 = MT47H128M16RT25E_EMIF_READ_LATENCY,
134};
135
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000136static const struct ddr_data ddr3_data = {
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000137 .datardsratio0 = MT41J128MJT125_RD_DQS,
138 .datawdsratio0 = MT41J128MJT125_WR_DQS,
139 .datafwsratio0 = MT41J128MJT125_PHY_FIFO_WE,
140 .datawrsratio0 = MT41J128MJT125_PHY_WR_DATA,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000141};
142
Tom Rini385bc752013-03-21 04:30:02 +0000143static const struct ddr_data ddr3_beagleblack_data = {
144 .datardsratio0 = MT41K256M16HA125E_RD_DQS,
145 .datawdsratio0 = MT41K256M16HA125E_WR_DQS,
146 .datafwsratio0 = MT41K256M16HA125E_PHY_FIFO_WE,
147 .datawrsratio0 = MT41K256M16HA125E_PHY_WR_DATA,
Tom Rini385bc752013-03-21 04:30:02 +0000148};
149
Jeff Lance7c03a222013-01-14 05:32:20 +0000150static const struct ddr_data ddr3_evm_data = {
151 .datardsratio0 = MT41J512M8RH125_RD_DQS,
152 .datawdsratio0 = MT41J512M8RH125_WR_DQS,
153 .datafwsratio0 = MT41J512M8RH125_PHY_FIFO_WE,
154 .datawrsratio0 = MT41J512M8RH125_PHY_WR_DATA,
Jeff Lance7c03a222013-01-14 05:32:20 +0000155};
156
Lokesh Vutla5837b902016-05-16 11:47:24 +0530157static const struct ddr_data ddr3_icev2_data = {
158 .datardsratio0 = MT41J128MJT125_RD_DQS_400MHz,
159 .datawdsratio0 = MT41J128MJT125_WR_DQS_400MHz,
160 .datafwsratio0 = MT41J128MJT125_PHY_FIFO_WE_400MHz,
161 .datawrsratio0 = MT41J128MJT125_PHY_WR_DATA_400MHz,
162};
163
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000164static const struct cmd_control ddr3_cmd_ctrl_data = {
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000165 .cmd0csratio = MT41J128MJT125_RATIO,
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000166 .cmd0iclkout = MT41J128MJT125_INVERT_CLKOUT,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000167
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000168 .cmd1csratio = MT41J128MJT125_RATIO,
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000169 .cmd1iclkout = MT41J128MJT125_INVERT_CLKOUT,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000170
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000171 .cmd2csratio = MT41J128MJT125_RATIO,
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000172 .cmd2iclkout = MT41J128MJT125_INVERT_CLKOUT,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000173};
174
Tom Rini385bc752013-03-21 04:30:02 +0000175static const struct cmd_control ddr3_beagleblack_cmd_ctrl_data = {
176 .cmd0csratio = MT41K256M16HA125E_RATIO,
Tom Rini385bc752013-03-21 04:30:02 +0000177 .cmd0iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
178
179 .cmd1csratio = MT41K256M16HA125E_RATIO,
Tom Rini385bc752013-03-21 04:30:02 +0000180 .cmd1iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
181
182 .cmd2csratio = MT41K256M16HA125E_RATIO,
Tom Rini385bc752013-03-21 04:30:02 +0000183 .cmd2iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
184};
185
Jeff Lance7c03a222013-01-14 05:32:20 +0000186static const struct cmd_control ddr3_evm_cmd_ctrl_data = {
187 .cmd0csratio = MT41J512M8RH125_RATIO,
Jeff Lance7c03a222013-01-14 05:32:20 +0000188 .cmd0iclkout = MT41J512M8RH125_INVERT_CLKOUT,
189
190 .cmd1csratio = MT41J512M8RH125_RATIO,
Jeff Lance7c03a222013-01-14 05:32:20 +0000191 .cmd1iclkout = MT41J512M8RH125_INVERT_CLKOUT,
192
193 .cmd2csratio = MT41J512M8RH125_RATIO,
Jeff Lance7c03a222013-01-14 05:32:20 +0000194 .cmd2iclkout = MT41J512M8RH125_INVERT_CLKOUT,
195};
196
Lokesh Vutla5837b902016-05-16 11:47:24 +0530197static const struct cmd_control ddr3_icev2_cmd_ctrl_data = {
198 .cmd0csratio = MT41J128MJT125_RATIO_400MHz,
199 .cmd0iclkout = MT41J128MJT125_INVERT_CLKOUT_400MHz,
200
201 .cmd1csratio = MT41J128MJT125_RATIO_400MHz,
202 .cmd1iclkout = MT41J128MJT125_INVERT_CLKOUT_400MHz,
203
204 .cmd2csratio = MT41J128MJT125_RATIO_400MHz,
205 .cmd2iclkout = MT41J128MJT125_INVERT_CLKOUT_400MHz,
206};
207
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000208static struct emif_regs ddr3_emif_reg_data = {
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000209 .sdram_config = MT41J128MJT125_EMIF_SDCFG,
210 .ref_ctrl = MT41J128MJT125_EMIF_SDREF,
211 .sdram_tim1 = MT41J128MJT125_EMIF_TIM1,
212 .sdram_tim2 = MT41J128MJT125_EMIF_TIM2,
213 .sdram_tim3 = MT41J128MJT125_EMIF_TIM3,
214 .zq_config = MT41J128MJT125_ZQ_CFG,
Vaibhav Hiremathc30d57b2013-03-14 21:11:16 +0000215 .emif_ddr_phy_ctlr_1 = MT41J128MJT125_EMIF_READ_LATENCY |
216 PHY_EN_DYN_PWRDN,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000217};
Jeff Lance7c03a222013-01-14 05:32:20 +0000218
Tom Rini385bc752013-03-21 04:30:02 +0000219static struct emif_regs ddr3_beagleblack_emif_reg_data = {
220 .sdram_config = MT41K256M16HA125E_EMIF_SDCFG,
221 .ref_ctrl = MT41K256M16HA125E_EMIF_SDREF,
222 .sdram_tim1 = MT41K256M16HA125E_EMIF_TIM1,
223 .sdram_tim2 = MT41K256M16HA125E_EMIF_TIM2,
224 .sdram_tim3 = MT41K256M16HA125E_EMIF_TIM3,
Jyri Sarha8d2998b2016-12-09 12:29:13 +0200225 .ocp_config = EMIF_OCP_CONFIG_BEAGLEBONE_BLACK,
Tom Rini385bc752013-03-21 04:30:02 +0000226 .zq_config = MT41K256M16HA125E_ZQ_CFG,
227 .emif_ddr_phy_ctlr_1 = MT41K256M16HA125E_EMIF_READ_LATENCY,
228};
229
Jeff Lance7c03a222013-01-14 05:32:20 +0000230static struct emif_regs ddr3_evm_emif_reg_data = {
231 .sdram_config = MT41J512M8RH125_EMIF_SDCFG,
232 .ref_ctrl = MT41J512M8RH125_EMIF_SDREF,
233 .sdram_tim1 = MT41J512M8RH125_EMIF_TIM1,
234 .sdram_tim2 = MT41J512M8RH125_EMIF_TIM2,
235 .sdram_tim3 = MT41J512M8RH125_EMIF_TIM3,
Jyri Sarha8d2998b2016-12-09 12:29:13 +0200236 .ocp_config = EMIF_OCP_CONFIG_AM335X_EVM,
Jeff Lance7c03a222013-01-14 05:32:20 +0000237 .zq_config = MT41J512M8RH125_ZQ_CFG,
Vaibhav Hiremathc30d57b2013-03-14 21:11:16 +0000238 .emif_ddr_phy_ctlr_1 = MT41J512M8RH125_EMIF_READ_LATENCY |
239 PHY_EN_DYN_PWRDN,
Jeff Lance7c03a222013-01-14 05:32:20 +0000240};
Peter Korsgaardeb204db2013-05-13 08:36:30 +0000241
Lokesh Vutla5837b902016-05-16 11:47:24 +0530242static struct emif_regs ddr3_icev2_emif_reg_data = {
243 .sdram_config = MT41J128MJT125_EMIF_SDCFG_400MHz,
244 .ref_ctrl = MT41J128MJT125_EMIF_SDREF_400MHz,
245 .sdram_tim1 = MT41J128MJT125_EMIF_TIM1_400MHz,
246 .sdram_tim2 = MT41J128MJT125_EMIF_TIM2_400MHz,
247 .sdram_tim3 = MT41J128MJT125_EMIF_TIM3_400MHz,
248 .zq_config = MT41J128MJT125_ZQ_CFG_400MHz,
249 .emif_ddr_phy_ctlr_1 = MT41J128MJT125_EMIF_READ_LATENCY_400MHz |
250 PHY_EN_DYN_PWRDN,
251};
252
Peter Korsgaardeb204db2013-05-13 08:36:30 +0000253#ifdef CONFIG_SPL_OS_BOOT
254int spl_start_uboot(void)
255{
Alex Kiernandf0df672018-04-19 04:32:53 +0000256#ifdef CONFIG_SPL_SERIAL_SUPPORT
Peter Korsgaardeb204db2013-05-13 08:36:30 +0000257 /* break into full u-boot on 'c' */
Tom Rini810b5812014-03-28 12:03:38 -0400258 if (serial_tstc() && serial_getc() == 'c')
259 return 1;
Alex Kiernandf0df672018-04-19 04:32:53 +0000260#endif
Tom Rini810b5812014-03-28 12:03:38 -0400261
262#ifdef CONFIG_SPL_ENV_SUPPORT
263 env_init();
Simon Glass17539572017-08-03 12:22:07 -0600264 env_load();
Simon Glass22c34c22017-08-03 12:22:13 -0600265 if (env_get_yesno("boot_os") != 1)
Tom Rini810b5812014-03-28 12:03:38 -0400266 return 1;
267#endif
268
269 return 0;
Peter Korsgaardeb204db2013-05-13 08:36:30 +0000270}
271#endif
272
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530273const struct dpll_params *get_dpll_ddr_params(void)
Tom Rini52437072013-08-30 16:28:46 -0400274{
Lokesh Vutla6302e532017-05-05 12:59:10 +0530275 int ind = get_sys_clk_index();
276
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530277 if (board_is_evm_sk())
Lokesh Vutla6302e532017-05-05 12:59:10 +0530278 return &dpll_ddr3_303MHz[ind];
Jason Kridnerb56b5b32018-03-07 05:40:41 -0500279 else if (board_is_pb() || board_is_bone_lt() || board_is_icev2())
Lokesh Vutla6302e532017-05-05 12:59:10 +0530280 return &dpll_ddr3_400MHz[ind];
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530281 else if (board_is_evm_15_or_later())
Lokesh Vutla6302e532017-05-05 12:59:10 +0530282 return &dpll_ddr3_303MHz[ind];
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530283 else
Lokesh Vutla6302e532017-05-05 12:59:10 +0530284 return &dpll_ddr2_266MHz[ind];
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530285}
Tom Rini52437072013-08-30 16:28:46 -0400286
Lokesh Vutla6302e532017-05-05 12:59:10 +0530287static u8 bone_not_connected_to_ac_power(void)
288{
289 if (board_is_bone()) {
290 uchar pmic_status_reg;
291 if (tps65217_reg_read(TPS65217_STATUS,
292 &pmic_status_reg))
293 return 1;
294 if (!(pmic_status_reg & TPS65217_PWR_SRC_AC_BITMASK)) {
295 puts("No AC power, switching to default OPP\n");
296 return 1;
297 }
298 }
299 return 0;
300}
301
302const struct dpll_params *get_dpll_mpu_params(void)
303{
304 int ind = get_sys_clk_index();
305 int freq = am335x_get_efuse_mpu_max_freq(cdev);
306
307 if (bone_not_connected_to_ac_power())
308 freq = MPUPLL_M_600;
309
Jason Kridnerb56b5b32018-03-07 05:40:41 -0500310 if (board_is_pb() || board_is_bone_lt())
Lokesh Vutla6302e532017-05-05 12:59:10 +0530311 freq = MPUPLL_M_1000;
312
313 switch (freq) {
314 case MPUPLL_M_1000:
315 return &dpll_mpu_opp[ind][5];
316 case MPUPLL_M_800:
317 return &dpll_mpu_opp[ind][4];
318 case MPUPLL_M_720:
319 return &dpll_mpu_opp[ind][3];
320 case MPUPLL_M_600:
321 return &dpll_mpu_opp[ind][2];
322 case MPUPLL_M_500:
323 return &dpll_mpu_opp100;
324 case MPUPLL_M_300:
325 return &dpll_mpu_opp[ind][0];
326 }
327
328 return &dpll_mpu_opp[ind][0];
329}
330
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530331static void scale_vcores_bone(int freq)
332{
333 int usb_cur_lim, mpu_vdd;
Tom Rini52437072013-08-30 16:28:46 -0400334
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530335 /*
336 * Only perform PMIC configurations if board rev > A1
337 * on Beaglebone White
338 */
339 if (board_is_bone() && !strncmp(board_ti_get_rev(), "00A1", 4))
340 return;
Tom Rini52437072013-08-30 16:28:46 -0400341
Igor Opaniukf7c91762021-02-09 13:52:45 +0200342#if !CONFIG_IS_ENABLED(DM_I2C)
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530343 if (i2c_probe(TPS65217_CHIP_PM))
344 return;
Jean-Jacques Hiblot52a51512018-12-07 14:50:49 +0100345#else
346 if (power_tps65217_init(0))
347 return;
348#endif
349
Tom Rini52437072013-08-30 16:28:46 -0400350
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530351 /*
352 * On Beaglebone White we need to ensure we have AC power
353 * before increasing the frequency.
354 */
Lokesh Vutla6302e532017-05-05 12:59:10 +0530355 if (bone_not_connected_to_ac_power())
356 freq = MPUPLL_M_600;
Tom Rini52437072013-08-30 16:28:46 -0400357
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530358 /*
359 * Override what we have detected since we know if we have
360 * a Beaglebone Black it supports 1GHz.
361 */
Jason Kridnerb56b5b32018-03-07 05:40:41 -0500362 if (board_is_pb() || board_is_bone_lt())
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530363 freq = MPUPLL_M_1000;
Tom Rini52437072013-08-30 16:28:46 -0400364
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530365 switch (freq) {
366 case MPUPLL_M_1000:
367 mpu_vdd = TPS65217_DCDC_VOLT_SEL_1325MV;
368 usb_cur_lim = TPS65217_USB_INPUT_CUR_LIMIT_1800MA;
369 break;
370 case MPUPLL_M_800:
371 mpu_vdd = TPS65217_DCDC_VOLT_SEL_1275MV;
Lokesh Vutlae29609a2017-06-10 13:22:56 +0530372 usb_cur_lim = TPS65217_USB_INPUT_CUR_LIMIT_1300MA;
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530373 break;
374 case MPUPLL_M_720:
375 mpu_vdd = TPS65217_DCDC_VOLT_SEL_1200MV;
Lokesh Vutlae29609a2017-06-10 13:22:56 +0530376 usb_cur_lim = TPS65217_USB_INPUT_CUR_LIMIT_1300MA;
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530377 break;
378 case MPUPLL_M_600:
379 case MPUPLL_M_500:
380 case MPUPLL_M_300:
Lokesh Vutlae29609a2017-06-10 13:22:56 +0530381 default:
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530382 mpu_vdd = TPS65217_DCDC_VOLT_SEL_1100MV;
383 usb_cur_lim = TPS65217_USB_INPUT_CUR_LIMIT_1300MA;
384 break;
385 }
Steve Kipisz5adac352013-08-14 10:51:31 -0400386
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530387 if (tps65217_reg_write(TPS65217_PROT_LEVEL_NONE,
388 TPS65217_POWER_PATH,
389 usb_cur_lim,
390 TPS65217_USB_INPUT_CUR_LIMIT_MASK))
391 puts("tps65217_reg_write failure\n");
Tom Rini52437072013-08-30 16:28:46 -0400392
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530393 /* Set DCDC3 (CORE) voltage to 1.10V */
394 if (tps65217_voltage_update(TPS65217_DEFDCDC3,
395 TPS65217_DCDC_VOLT_SEL_1100MV)) {
396 puts("tps65217_voltage_update failure\n");
397 return;
398 }
Tom Rini52437072013-08-30 16:28:46 -0400399
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530400 /* Set DCDC2 (MPU) voltage */
401 if (tps65217_voltage_update(TPS65217_DEFDCDC2, mpu_vdd)) {
402 puts("tps65217_voltage_update failure\n");
403 return;
404 }
Tom Rini52437072013-08-30 16:28:46 -0400405
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530406 /*
407 * Set LDO3, LDO4 output voltage to 3.3V for Beaglebone.
408 * Set LDO3 to 1.8V and LDO4 to 3.3V for Beaglebone Black.
409 */
410 if (board_is_bone()) {
Tom Rini52437072013-08-30 16:28:46 -0400411 if (tps65217_reg_write(TPS65217_PROT_LEVEL_2,
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530412 TPS65217_DEFLS1,
Tom Rini52437072013-08-30 16:28:46 -0400413 TPS65217_LDO_VOLTAGE_OUT_3_3,
414 TPS65217_LDO_MASK))
415 puts("tps65217_reg_write failure\n");
416 } else {
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530417 if (tps65217_reg_write(TPS65217_PROT_LEVEL_2,
418 TPS65217_DEFLS1,
419 TPS65217_LDO_VOLTAGE_OUT_1_8,
420 TPS65217_LDO_MASK))
421 puts("tps65217_reg_write failure\n");
422 }
Tom Rini52437072013-08-30 16:28:46 -0400423
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530424 if (tps65217_reg_write(TPS65217_PROT_LEVEL_2,
425 TPS65217_DEFLS2,
426 TPS65217_LDO_VOLTAGE_OUT_3_3,
427 TPS65217_LDO_MASK))
428 puts("tps65217_reg_write failure\n");
429}
Tom Rini52437072013-08-30 16:28:46 -0400430
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530431void scale_vcores_generic(int freq)
432{
433 int sil_rev, mpu_vdd;
Tom Rini52437072013-08-30 16:28:46 -0400434
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530435 /*
436 * The GP EVM, IDK and EVM SK use a TPS65910 PMIC. For all
437 * MPU frequencies we support we use a CORE voltage of
438 * 1.10V. For MPU voltage we need to switch based on
439 * the frequency we are running at.
440 */
Igor Opaniukf7c91762021-02-09 13:52:45 +0200441#if !CONFIG_IS_ENABLED(DM_I2C)
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530442 if (i2c_probe(TPS65910_CTRL_I2C_ADDR))
443 return;
Jean-Jacques Hiblot52a51512018-12-07 14:50:49 +0100444#else
445 if (power_tps65910_init(0))
446 return;
447#endif
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530448 /*
449 * Depending on MPU clock and PG we will need a different
450 * VDD to drive at that speed.
451 */
452 sil_rev = readl(&cdev->deviceid) >> 28;
453 mpu_vdd = am335x_get_tps65910_mpu_vdd(sil_rev, freq);
Tom Rini52437072013-08-30 16:28:46 -0400454
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530455 /* Tell the TPS65910 to use i2c */
456 tps65910_set_i2c_control();
Steve Kipisz5adac352013-08-14 10:51:31 -0400457
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530458 /* First update MPU voltage. */
459 if (tps65910_voltage_update(MPU, mpu_vdd))
460 return;
Tom Rini52437072013-08-30 16:28:46 -0400461
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530462 /* Second, update the CORE voltage. */
463 if (tps65910_voltage_update(CORE, TPS65910_OP_REG_SEL_1_1_0))
464 return;
465
Tom Rini52437072013-08-30 16:28:46 -0400466}
467
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530468void gpi2c_init(void)
Lokesh Vutla89a83bf2013-07-30 10:48:52 +0530469{
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530470 /* When needed to be invoked prior to BSS initialization */
471 static bool first_time = true;
472
473 if (first_time) {
474 enable_i2c0_pin_mux();
Igor Opaniukf7c91762021-02-09 13:52:45 +0200475#if !CONFIG_IS_ENABLED(DM_I2C)
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530476 i2c_init(CONFIG_SYS_OMAP24_I2C_SPEED,
477 CONFIG_SYS_OMAP24_I2C_SLAVE);
Jean-Jacques Hiblot52a51512018-12-07 14:50:49 +0100478#endif
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530479 first_time = false;
480 }
481}
482
483void scale_vcores(void)
484{
485 int freq;
486
487 gpi2c_init();
488 freq = am335x_get_efuse_mpu_max_freq(cdev);
489
Lokesh Vutlae29609a2017-06-10 13:22:56 +0530490 if (board_is_beaglebonex())
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530491 scale_vcores_bone(freq);
Lokesh Vutla89a83bf2013-07-30 10:48:52 +0530492 else
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530493 scale_vcores_generic(freq);
Lokesh Vutla89a83bf2013-07-30 10:48:52 +0530494}
495
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530496void set_uart_mux_conf(void)
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000497{
Tom Rini986d7552014-08-01 09:53:24 -0400498#if CONFIG_CONS_INDEX == 1
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000499 enable_uart0_pin_mux();
Tom Rini986d7552014-08-01 09:53:24 -0400500#elif CONFIG_CONS_INDEX == 2
Andrew Bradford65c51ff2012-10-25 08:21:30 -0400501 enable_uart1_pin_mux();
Tom Rini986d7552014-08-01 09:53:24 -0400502#elif CONFIG_CONS_INDEX == 3
Andrew Bradford65c51ff2012-10-25 08:21:30 -0400503 enable_uart2_pin_mux();
Tom Rini986d7552014-08-01 09:53:24 -0400504#elif CONFIG_CONS_INDEX == 4
Andrew Bradford65c51ff2012-10-25 08:21:30 -0400505 enable_uart3_pin_mux();
Tom Rini986d7552014-08-01 09:53:24 -0400506#elif CONFIG_CONS_INDEX == 5
Andrew Bradford65c51ff2012-10-25 08:21:30 -0400507 enable_uart4_pin_mux();
Tom Rini986d7552014-08-01 09:53:24 -0400508#elif CONFIG_CONS_INDEX == 6
Andrew Bradford65c51ff2012-10-25 08:21:30 -0400509 enable_uart5_pin_mux();
Tom Rini986d7552014-08-01 09:53:24 -0400510#endif
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530511}
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000512
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530513void set_mux_conf_regs(void)
514{
Nishanth Menon2afa70d2016-02-24 12:30:55 -0600515 enable_board_pin_mux();
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530516}
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000517
Lokesh Vutla303b2672013-12-10 15:02:21 +0530518const struct ctrl_ioregs ioregs_evmsk = {
519 .cm0ioctl = MT41J128MJT125_IOCTRL_VALUE,
520 .cm1ioctl = MT41J128MJT125_IOCTRL_VALUE,
521 .cm2ioctl = MT41J128MJT125_IOCTRL_VALUE,
522 .dt0ioctl = MT41J128MJT125_IOCTRL_VALUE,
523 .dt1ioctl = MT41J128MJT125_IOCTRL_VALUE,
524};
525
526const struct ctrl_ioregs ioregs_bonelt = {
527 .cm0ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
528 .cm1ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
529 .cm2ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
530 .dt0ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
531 .dt1ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
532};
533
534const struct ctrl_ioregs ioregs_evm15 = {
535 .cm0ioctl = MT41J512M8RH125_IOCTRL_VALUE,
536 .cm1ioctl = MT41J512M8RH125_IOCTRL_VALUE,
537 .cm2ioctl = MT41J512M8RH125_IOCTRL_VALUE,
538 .dt0ioctl = MT41J512M8RH125_IOCTRL_VALUE,
539 .dt1ioctl = MT41J512M8RH125_IOCTRL_VALUE,
540};
541
542const struct ctrl_ioregs ioregs = {
543 .cm0ioctl = MT47H128M16RT25E_IOCTRL_VALUE,
544 .cm1ioctl = MT47H128M16RT25E_IOCTRL_VALUE,
545 .cm2ioctl = MT47H128M16RT25E_IOCTRL_VALUE,
546 .dt0ioctl = MT47H128M16RT25E_IOCTRL_VALUE,
547 .dt1ioctl = MT47H128M16RT25E_IOCTRL_VALUE,
548};
549
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530550void sdram_init(void)
551{
Nishanth Menon2afa70d2016-02-24 12:30:55 -0600552 if (board_is_evm_sk()) {
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000553 /*
554 * EVM SK 1.2A and later use gpio0_7 to enable DDR3.
555 * This is safe enough to do on older revs.
556 */
557 gpio_request(GPIO_DDR_VTT_EN, "ddr_vtt_en");
558 gpio_direction_output(GPIO_DDR_VTT_EN, 1);
559 }
560
Lokesh Vutla5837b902016-05-16 11:47:24 +0530561 if (board_is_icev2()) {
562 gpio_request(ICE_GPIO_DDR_VTT_EN, "ddr_vtt_en");
563 gpio_direction_output(ICE_GPIO_DDR_VTT_EN, 1);
564 }
565
Nishanth Menon2afa70d2016-02-24 12:30:55 -0600566 if (board_is_evm_sk())
Lokesh Vutla303b2672013-12-10 15:02:21 +0530567 config_ddr(303, &ioregs_evmsk, &ddr3_data,
Matt Porter65991ec2013-03-15 10:07:03 +0000568 &ddr3_cmd_ctrl_data, &ddr3_emif_reg_data, 0);
Jason Kridnerb56b5b32018-03-07 05:40:41 -0500569 else if (board_is_pb() || board_is_bone_lt())
Lokesh Vutla303b2672013-12-10 15:02:21 +0530570 config_ddr(400, &ioregs_bonelt,
Tom Rini385bc752013-03-21 04:30:02 +0000571 &ddr3_beagleblack_data,
572 &ddr3_beagleblack_cmd_ctrl_data,
573 &ddr3_beagleblack_emif_reg_data, 0);
Nishanth Menon2afa70d2016-02-24 12:30:55 -0600574 else if (board_is_evm_15_or_later())
Lokesh Vutla303b2672013-12-10 15:02:21 +0530575 config_ddr(303, &ioregs_evm15, &ddr3_evm_data,
Matt Porter65991ec2013-03-15 10:07:03 +0000576 &ddr3_evm_cmd_ctrl_data, &ddr3_evm_emif_reg_data, 0);
Lokesh Vutla5837b902016-05-16 11:47:24 +0530577 else if (board_is_icev2())
578 config_ddr(400, &ioregs_evmsk, &ddr3_icev2_data,
579 &ddr3_icev2_cmd_ctrl_data, &ddr3_icev2_emif_reg_data,
580 0);
Jyri Sarha8d2998b2016-12-09 12:29:13 +0200581 else if (board_is_gp_evm())
582 config_ddr(266, &ioregs, &ddr2_data,
583 &ddr2_cmd_ctrl_data, &ddr2_evm_emif_reg_data, 0);
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000584 else
Lokesh Vutla303b2672013-12-10 15:02:21 +0530585 config_ddr(266, &ioregs, &ddr2_data,
Matt Porter65991ec2013-03-15 10:07:03 +0000586 &ddr2_cmd_ctrl_data, &ddr2_emif_reg_data, 0);
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000587}
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530588#endif
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000589
Alex Kiernan20bba2e2018-04-01 09:22:37 +0000590#if defined(CONFIG_CLOCK_SYNTHESIZER) && (!defined(CONFIG_SPL_BUILD) || \
591 (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD)))
Roger Quadrosbcb4ee82016-08-24 15:35:50 +0300592static void request_and_set_gpio(int gpio, char *name, int val)
Lokesh Vutla0d144f52016-05-16 11:47:26 +0530593{
594 int ret;
595
596 ret = gpio_request(gpio, name);
597 if (ret < 0) {
598 printf("%s: Unable to request %s\n", __func__, name);
599 return;
600 }
601
602 ret = gpio_direction_output(gpio, 0);
603 if (ret < 0) {
604 printf("%s: Unable to set %s as output\n", __func__, name);
605 goto err_free_gpio;
606 }
607
Roger Quadrosbcb4ee82016-08-24 15:35:50 +0300608 gpio_set_value(gpio, val);
Lokesh Vutla0d144f52016-05-16 11:47:26 +0530609
610 return;
611
612err_free_gpio:
613 gpio_free(gpio);
614}
615
Roger Quadrosbcb4ee82016-08-24 15:35:50 +0300616#define REQUEST_AND_SET_GPIO(N) request_and_set_gpio(N, #N, 1);
617#define REQUEST_AND_CLR_GPIO(N) request_and_set_gpio(N, #N, 0);
Lokesh Vutla0d144f52016-05-16 11:47:26 +0530618
619/**
620 * RMII mode on ICEv2 board needs 50MHz clock. Given the clock
621 * synthesizer With a capacitor of 18pF, and 25MHz input clock cycle
622 * PLL1 gives an output of 100MHz. So, configuring the div2/3 as 2 to
623 * give 50MHz output for Eth0 and 1.
624 */
625static struct clk_synth cdce913_data = {
626 .id = 0x81,
627 .capacitor = 0x90,
628 .mux = 0x6d,
629 .pdiv2 = 0x2,
630 .pdiv3 = 0x2,
631};
632#endif
633
Sekhar Norif357b112018-08-23 17:11:30 +0530634#if defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_CONTROL) && \
635 defined(CONFIG_DM_ETH) && defined(CONFIG_DRIVER_TI_CPSW)
636
637#define MAX_CPSW_SLAVES 2
638
639/* At the moment, we do not want to stop booting for any failures here */
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900640int ft_board_setup(void *fdt, struct bd_info *bd)
Sekhar Norif357b112018-08-23 17:11:30 +0530641{
642 const char *slave_path, *enet_name;
643 int enetnode, slavenode, phynode;
644 struct udevice *ethdev;
645 char alias[16];
646 u32 phy_id[2];
647 int phy_addr;
648 int i, ret;
649
650 /* phy address fixup needed only on beagle bone family */
651 if (!board_is_beaglebonex())
652 goto done;
653
654 for (i = 0; i < MAX_CPSW_SLAVES; i++) {
655 sprintf(alias, "ethernet%d", i);
656
657 slave_path = fdt_get_alias(fdt, alias);
658 if (!slave_path)
659 continue;
660
661 slavenode = fdt_path_offset(fdt, slave_path);
662 if (slavenode < 0)
663 continue;
664
665 enetnode = fdt_parent_offset(fdt, slavenode);
666 enet_name = fdt_get_name(fdt, enetnode, NULL);
667
668 ethdev = eth_get_dev_by_name(enet_name);
669 if (!ethdev)
670 continue;
671
672 phy_addr = cpsw_get_slave_phy_addr(ethdev, i);
673
674 /* check for phy_id as well as phy-handle properties */
675 ret = fdtdec_get_int_array_count(fdt, slavenode, "phy_id",
676 phy_id, 2);
677 if (ret == 2) {
678 if (phy_id[1] != phy_addr) {
679 printf("fixing up phy_id for %s, old: %d, new: %d\n",
680 alias, phy_id[1], phy_addr);
681
682 phy_id[0] = cpu_to_fdt32(phy_id[0]);
683 phy_id[1] = cpu_to_fdt32(phy_addr);
684 do_fixup_by_path(fdt, slave_path, "phy_id",
685 phy_id, sizeof(phy_id), 0);
686 }
687 } else {
688 phynode = fdtdec_lookup_phandle(fdt, slavenode,
689 "phy-handle");
690 if (phynode < 0)
691 continue;
692
693 ret = fdtdec_get_int(fdt, phynode, "reg", -ENOENT);
694 if (ret < 0)
695 continue;
696
697 if (ret != phy_addr) {
698 printf("fixing up phy-handle for %s, old: %d, new: %d\n",
699 alias, ret, phy_addr);
700
701 fdt_setprop_u32(fdt, phynode, "reg",
702 cpu_to_fdt32(phy_addr));
703 }
704 }
705 }
706
707done:
708 return 0;
709}
710#endif
711
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000712/*
713 * Basic board specific setup. Pinmux has been handled already.
714 */
715int board_init(void)
716{
Tom Rini303bfe82013-10-01 12:32:04 -0400717#if defined(CONFIG_HW_WATCHDOG)
718 hw_watchdog_init();
719#endif
720
Tom Rinif3b6a1d2013-08-09 11:22:13 -0400721 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
Miquel Raynald0935362019-10-03 19:50:03 +0200722#if defined(CONFIG_NOR) || defined(CONFIG_MTD_RAW_NAND)
Ilya Yanok3d9725e2012-11-06 13:06:31 +0000723 gpmc_init();
Steve Kipiszbe9b6f82013-07-18 15:13:03 -0400724#endif
Lokesh Vutla0d144f52016-05-16 11:47:26 +0530725
Alex Kiernan20bba2e2018-04-01 09:22:37 +0000726#if defined(CONFIG_CLOCK_SYNTHESIZER) && (!defined(CONFIG_SPL_BUILD) || \
727 (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD)))
Lokesh Vutla0d144f52016-05-16 11:47:26 +0530728 if (board_is_icev2()) {
Roger Quadrosbcb4ee82016-08-24 15:35:50 +0300729 int rv;
730 u32 reg;
731
Lokesh Vutla0d144f52016-05-16 11:47:26 +0530732 REQUEST_AND_SET_GPIO(GPIO_PR1_MII_CTRL);
Roger Quadrosbcb4ee82016-08-24 15:35:50 +0300733 /* Make J19 status available on GPIO1_26 */
734 REQUEST_AND_CLR_GPIO(GPIO_MUX_MII_CTRL);
735
Lokesh Vutla0d144f52016-05-16 11:47:26 +0530736 REQUEST_AND_SET_GPIO(GPIO_FET_SWITCH_CTRL);
Roger Quadrosbcb4ee82016-08-24 15:35:50 +0300737 /*
738 * Both ports can be set as RMII-CPSW or MII-PRU-ETH using
739 * jumpers near the port. Read the jumper value and set
740 * the pinmux, external mux and PHY clock accordingly.
741 * As jumper line is overridden by PHY RX_DV pin immediately
742 * after bootstrap (power-up/reset), we need to sample
743 * it during PHY reset using GPIO rising edge detection.
744 */
Lokesh Vutla0d144f52016-05-16 11:47:26 +0530745 REQUEST_AND_SET_GPIO(GPIO_PHY_RESET);
Roger Quadrosbcb4ee82016-08-24 15:35:50 +0300746 /* Enable rising edge IRQ on GPIO0_11 and GPIO 1_26 */
747 reg = readl(GPIO0_RISINGDETECT) | BIT(11);
748 writel(reg, GPIO0_RISINGDETECT);
749 reg = readl(GPIO1_RISINGDETECT) | BIT(26);
750 writel(reg, GPIO1_RISINGDETECT);
751 /* Reset PHYs to capture the Jumper setting */
752 gpio_set_value(GPIO_PHY_RESET, 0);
753 udelay(2); /* PHY datasheet states 1uS min. */
754 gpio_set_value(GPIO_PHY_RESET, 1);
755
756 reg = readl(GPIO0_IRQSTATUSRAW) & BIT(11);
757 if (reg) {
758 writel(reg, GPIO0_IRQSTATUS1); /* clear irq */
759 /* RMII mode */
760 printf("ETH0, CPSW\n");
761 } else {
762 /* MII mode */
763 printf("ETH0, PRU\n");
764 cdce913_data.pdiv3 = 4; /* 25MHz PHY clk */
765 }
766
767 reg = readl(GPIO1_IRQSTATUSRAW) & BIT(26);
768 if (reg) {
769 writel(reg, GPIO1_IRQSTATUS1); /* clear irq */
770 /* RMII mode */
771 printf("ETH1, CPSW\n");
772 gpio_set_value(GPIO_MUX_MII_CTRL, 1);
773 } else {
774 /* MII mode */
775 printf("ETH1, PRU\n");
776 cdce913_data.pdiv2 = 4; /* 25MHz PHY clk */
777 }
778
779 /* disable rising edge IRQs */
780 reg = readl(GPIO0_RISINGDETECT) & ~BIT(11);
781 writel(reg, GPIO0_RISINGDETECT);
782 reg = readl(GPIO1_RISINGDETECT) & ~BIT(26);
783 writel(reg, GPIO1_RISINGDETECT);
Lokesh Vutla0d144f52016-05-16 11:47:26 +0530784
785 rv = setup_clock_synthesizer(&cdce913_data);
786 if (rv) {
787 printf("Clock synthesizer setup failed %d\n", rv);
788 return rv;
789 }
Roger Quadrosbcb4ee82016-08-24 15:35:50 +0300790
791 /* reset PHYs */
792 gpio_set_value(GPIO_PHY_RESET, 0);
793 udelay(2); /* PHY datasheet states 1uS min. */
794 gpio_set_value(GPIO_PHY_RESET, 1);
Lokesh Vutla0d144f52016-05-16 11:47:26 +0530795 }
796#endif
797
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000798 return 0;
799}
800
Tom Rini40271852012-10-24 07:28:17 +0000801#ifdef CONFIG_BOARD_LATE_INIT
802int board_late_init(void)
803{
Tero Kristo67f79e72019-09-27 19:14:29 +0300804 struct udevice *dev;
Roger Quadros7c9d3782016-08-24 15:35:51 +0300805#if !defined(CONFIG_SPL_BUILD)
806 uint8_t mac_addr[6];
807 uint32_t mac_hi, mac_lo;
808#endif
809
Tom Rini40271852012-10-24 07:28:17 +0000810#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
Nishanth Menon2afa70d2016-02-24 12:30:55 -0600811 char *name = NULL;
Tom Rini4021fd92013-07-18 15:13:01 -0400812
robertcnelson@gmail.comc5d7d222017-03-30 14:29:52 -0500813 if (board_is_bone_lt()) {
814 /* BeagleBoard.org BeagleBone Black Wireless: */
815 if (!strncmp(board_ti_get_rev(), "BWA", 3)) {
816 name = "BBBW";
817 }
robertcnelson@gmail.comb55cd7a2017-03-30 14:29:53 -0500818 /* SeeedStudio BeagleBone Green Wireless */
819 if (!strncmp(board_ti_get_rev(), "GW1", 3)) {
820 name = "BBGW";
821 }
robertcnelson@gmail.com89ef1d62017-03-30 14:29:54 -0500822 /* BeagleBoard.org BeagleBone Blue */
823 if (!strncmp(board_ti_get_rev(), "BLA", 3)) {
824 name = "BBBL";
825 }
robertcnelson@gmail.comc5d7d222017-03-30 14:29:52 -0500826 }
827
Nishanth Menon2afa70d2016-02-24 12:30:55 -0600828 if (board_is_bbg1())
829 name = "BBG1";
Koen Kooi8a157862018-07-18 10:13:59 +0200830 if (board_is_bben())
831 name = "BBEN";
Nishanth Menon2afa70d2016-02-24 12:30:55 -0600832 set_board_info_env(name);
Lokesh Vutla1eb0f542016-11-29 11:58:03 +0530833
834 /*
835 * Default FIT boot on HS devices. Non FIT images are not allowed
836 * on HS devices.
837 */
838 if (get_device_type() == HS_DEVICE)
Simon Glass6a38e412017-08-03 12:22:09 -0600839 env_set("boot_fit", "1");
Tom Rini40271852012-10-24 07:28:17 +0000840#endif
841
Roger Quadros7c9d3782016-08-24 15:35:51 +0300842#if !defined(CONFIG_SPL_BUILD)
843 /* try reading mac address from efuse */
844 mac_lo = readl(&cdev->macid0l);
845 mac_hi = readl(&cdev->macid0h);
846 mac_addr[0] = mac_hi & 0xFF;
847 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
848 mac_addr[2] = (mac_hi & 0xFF0000) >> 16;
849 mac_addr[3] = (mac_hi & 0xFF000000) >> 24;
850 mac_addr[4] = mac_lo & 0xFF;
851 mac_addr[5] = (mac_lo & 0xFF00) >> 8;
852
Simon Glass64b723f2017-08-03 12:22:12 -0600853 if (!env_get("ethaddr")) {
Roger Quadros7c9d3782016-08-24 15:35:51 +0300854 printf("<ethaddr> not set. Validating first E-fuse MAC\n");
855
856 if (is_valid_ethaddr(mac_addr))
Simon Glass8551d552017-08-03 12:22:11 -0600857 eth_env_set_enetaddr("ethaddr", mac_addr);
Roger Quadros7c9d3782016-08-24 15:35:51 +0300858 }
859
860 mac_lo = readl(&cdev->macid1l);
861 mac_hi = readl(&cdev->macid1h);
862 mac_addr[0] = mac_hi & 0xFF;
863 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
864 mac_addr[2] = (mac_hi & 0xFF0000) >> 16;
865 mac_addr[3] = (mac_hi & 0xFF000000) >> 24;
866 mac_addr[4] = mac_lo & 0xFF;
867 mac_addr[5] = (mac_lo & 0xFF00) >> 8;
868
Simon Glass64b723f2017-08-03 12:22:12 -0600869 if (!env_get("eth1addr")) {
Roger Quadros7c9d3782016-08-24 15:35:51 +0300870 if (is_valid_ethaddr(mac_addr))
Simon Glass8551d552017-08-03 12:22:11 -0600871 eth_env_set_enetaddr("eth1addr", mac_addr);
Roger Quadros7c9d3782016-08-24 15:35:51 +0300872 }
873#endif
874
Sam Protsenkoa31ca622018-02-28 00:26:15 +0200875 if (!env_get("serial#")) {
876 char *board_serial = env_get("board_serial");
877 char *ethaddr = env_get("ethaddr");
878
879 if (!board_serial || !strncmp(board_serial, "unknown", 7))
880 env_set("serial#", ethaddr);
881 else
882 env_set("serial#", board_serial);
883 }
884
Tero Kristo67f79e72019-09-27 19:14:29 +0300885 /* Just probe the potentially supported cdce913 device */
Dario Binacchic2de9d42020-12-30 00:16:32 +0100886 uclass_get_device_by_name(UCLASS_CLK, "cdce913@65", &dev);
Tero Kristo67f79e72019-09-27 19:14:29 +0300887
Tom Rini40271852012-10-24 07:28:17 +0000888 return 0;
889}
890#endif
891
Simon Glass71fa5b42020-12-03 16:55:18 -0700892/* CPSW plat */
Faiz Abbas27866262019-03-18 13:54:37 +0530893#if !CONFIG_IS_ENABLED(OF_CONTROL)
894struct cpsw_slave_data slave_data[] = {
895 {
896 .slave_reg_ofs = CPSW_SLAVE0_OFFSET,
897 .sliver_reg_ofs = CPSW_SLIVER0_OFFSET,
898 .phy_addr = 0,
899 },
900 {
901 .slave_reg_ofs = CPSW_SLAVE1_OFFSET,
902 .sliver_reg_ofs = CPSW_SLIVER1_OFFSET,
903 .phy_addr = 1,
904 },
905};
906
907struct cpsw_platform_data am335_eth_data = {
908 .cpsw_base = CPSW_BASE,
909 .version = CPSW_CTRL_VERSION_2,
910 .bd_ram_ofs = CPSW_BD_OFFSET,
911 .ale_reg_ofs = CPSW_ALE_OFFSET,
912 .cpdma_reg_ofs = CPSW_CPDMA_OFFSET,
913 .mdio_div = CPSW_MDIO_DIV,
914 .host_port_reg_ofs = CPSW_HOST_PORT_OFFSET,
915 .channels = 8,
916 .slaves = 2,
917 .slave_data = slave_data,
918 .ale_entries = 1024,
Faiz Abbas27866262019-03-18 13:54:37 +0530919 .mac_control = 0x20,
920 .active_slave = 0,
921 .mdio_base = 0x4a101000,
922 .gmii_sel = 0x44e10650,
923 .phy_sel_compat = "ti,am3352-cpsw-phy-sel",
924 .syscon_addr = 0x44e10630,
925 .macid_sel_compat = "cpsw,am33xx",
926};
927
928struct eth_pdata cpsw_pdata = {
929 .iobase = 0x4a100000,
930 .phy_interface = 0,
931 .priv_pdata = &am335_eth_data,
932};
933
Simon Glass1d8364a2020-12-28 20:34:54 -0700934U_BOOT_DRVINFO(am335x_eth) = {
Faiz Abbas27866262019-03-18 13:54:37 +0530935 .name = "eth_cpsw",
Simon Glass71fa5b42020-12-03 16:55:18 -0700936 .plat = &cpsw_pdata,
Faiz Abbas27866262019-03-18 13:54:37 +0530937};
938#endif
939
Lokesh Vutla89b9f302016-05-16 11:24:24 +0530940#ifdef CONFIG_SPL_LOAD_FIT
941int board_fit_config_name_match(const char *name)
942{
943 if (board_is_gp_evm() && !strcmp(name, "am335x-evm"))
944 return 0;
945 else if (board_is_bone() && !strcmp(name, "am335x-bone"))
946 return 0;
947 else if (board_is_bone_lt() && !strcmp(name, "am335x-boneblack"))
948 return 0;
Jason Kridnerb56b5b32018-03-07 05:40:41 -0500949 else if (board_is_pb() && !strcmp(name, "am335x-pocketbeagle"))
950 return 0;
Lokesh Vutla5a954ba2016-05-16 11:24:28 +0530951 else if (board_is_evm_sk() && !strcmp(name, "am335x-evmsk"))
952 return 0;
Lokesh Vutla1edfcaf2016-05-16 11:24:29 +0530953 else if (board_is_bbg1() && !strcmp(name, "am335x-bonegreen"))
954 return 0;
Lokesh Vutla7ecf1962016-05-16 11:47:28 +0530955 else if (board_is_icev2() && !strcmp(name, "am335x-icev2"))
956 return 0;
Lokesh Vutla89b9f302016-05-16 11:24:24 +0530957 else
958 return -1;
959}
960#endif
Andrew F. Davisbd249152016-08-30 14:06:24 -0500961
962#ifdef CONFIG_TI_SECURE_DEVICE
963void board_fit_image_post_process(void **p_image, size_t *p_size)
964{
965 secure_boot_verify_image(p_image, p_size);
966}
967#endif
Lokesh Vutla2fe7c792017-04-26 13:37:08 +0530968
969#if !CONFIG_IS_ENABLED(OF_CONTROL)
Simon Glassb75b15b2020-12-03 16:55:23 -0700970static const struct omap_hsmmc_plat am335x_mmc0_plat = {
Lokesh Vutla2fe7c792017-04-26 13:37:08 +0530971 .base_addr = (struct hsmmc *)OMAP_HSMMC1_BASE,
972 .cfg.host_caps = MMC_MODE_HS_52MHz | MMC_MODE_HS | MMC_MODE_4BIT,
973 .cfg.f_min = 400000,
974 .cfg.f_max = 52000000,
975 .cfg.voltages = MMC_VDD_32_33 | MMC_VDD_33_34 | MMC_VDD_165_195,
976 .cfg.b_max = CONFIG_SYS_MMC_MAX_BLK_COUNT,
977};
978
Simon Glass1d8364a2020-12-28 20:34:54 -0700979U_BOOT_DRVINFO(am335x_mmc0) = {
Lokesh Vutla2fe7c792017-04-26 13:37:08 +0530980 .name = "omap_hsmmc",
Simon Glassb75b15b2020-12-03 16:55:23 -0700981 .plat = &am335x_mmc0_plat,
Lokesh Vutla2fe7c792017-04-26 13:37:08 +0530982};
983
Simon Glassb75b15b2020-12-03 16:55:23 -0700984static const struct omap_hsmmc_plat am335x_mmc1_plat = {
Lokesh Vutla2fe7c792017-04-26 13:37:08 +0530985 .base_addr = (struct hsmmc *)OMAP_HSMMC2_BASE,
986 .cfg.host_caps = MMC_MODE_HS_52MHz | MMC_MODE_HS | MMC_MODE_8BIT,
987 .cfg.f_min = 400000,
988 .cfg.f_max = 52000000,
989 .cfg.voltages = MMC_VDD_32_33 | MMC_VDD_33_34 | MMC_VDD_165_195,
990 .cfg.b_max = CONFIG_SYS_MMC_MAX_BLK_COUNT,
991};
992
Simon Glass1d8364a2020-12-28 20:34:54 -0700993U_BOOT_DRVINFO(am335x_mmc1) = {
Lokesh Vutla2fe7c792017-04-26 13:37:08 +0530994 .name = "omap_hsmmc",
Simon Glassb75b15b2020-12-03 16:55:23 -0700995 .plat = &am335x_mmc1_plat,
Lokesh Vutla2fe7c792017-04-26 13:37:08 +0530996};
997#endif