blob: c7476b3a8cf062d09b4b094fe3f3bfa81ce207de [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"
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000047#include "board.h"
48
49DECLARE_GLOBAL_DATA_PTR;
50
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000051/* GPIO that controls power to DDR on EVM-SK */
Lokesh Vutla0d144f52016-05-16 11:47:26 +053052#define GPIO_TO_PIN(bank, gpio) (32 * (bank) + (gpio))
53#define GPIO_DDR_VTT_EN GPIO_TO_PIN(0, 7)
54#define ICE_GPIO_DDR_VTT_EN GPIO_TO_PIN(0, 18)
55#define GPIO_PR1_MII_CTRL GPIO_TO_PIN(3, 4)
56#define GPIO_MUX_MII_CTRL GPIO_TO_PIN(3, 10)
57#define GPIO_FET_SWITCH_CTRL GPIO_TO_PIN(0, 7)
58#define GPIO_PHY_RESET GPIO_TO_PIN(2, 5)
Roger Quadrosbcb4ee82016-08-24 15:35:50 +030059#define GPIO_ETH0_MODE GPIO_TO_PIN(0, 11)
60#define GPIO_ETH1_MODE GPIO_TO_PIN(1, 26)
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000061
62static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
63
Roger Quadrosbcb4ee82016-08-24 15:35:50 +030064#define GPIO0_RISINGDETECT (AM33XX_GPIO0_BASE + OMAP_GPIO_RISINGDETECT)
65#define GPIO1_RISINGDETECT (AM33XX_GPIO1_BASE + OMAP_GPIO_RISINGDETECT)
66
67#define GPIO0_IRQSTATUS1 (AM33XX_GPIO0_BASE + OMAP_GPIO_IRQSTATUS1)
68#define GPIO1_IRQSTATUS1 (AM33XX_GPIO1_BASE + OMAP_GPIO_IRQSTATUS1)
69
70#define GPIO0_IRQSTATUSRAW (AM33XX_GPIO0_BASE + 0x024)
71#define GPIO1_IRQSTATUSRAW (AM33XX_GPIO1_BASE + 0x024)
72
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000073/*
74 * Read header information from EEPROM into global structure.
75 */
Lokesh Vutla93e0f5b2016-10-14 10:35:25 +053076#ifdef CONFIG_TI_I2C_BOARD_DETECT
77void do_board_detect(void)
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000078{
Lokesh Vutla93e0f5b2016-10-14 10:35:25 +053079 enable_i2c0_pin_mux();
Kory Maincent4c1a71d2021-05-04 19:31:29 +020080 enable_i2c2_pin_mux();
Igor Opaniukf7c91762021-02-09 13:52:45 +020081#if !CONFIG_IS_ENABLED(DM_I2C)
Lokesh Vutla93e0f5b2016-10-14 10:35:25 +053082 i2c_init(CONFIG_SYS_OMAP24_I2C_SPEED, CONFIG_SYS_OMAP24_I2C_SLAVE);
Kory Maincent4c1a71d2021-05-04 19:31:29 +020083 i2c_init(CONFIG_SYS_OMAP24_I2C_SPEED2, CONFIG_SYS_OMAP24_I2C_SLAVE2);
Jean-Jacques Hiblot52a51512018-12-07 14:50:49 +010084#endif
Simon Glass4df67572017-05-12 21:09:55 -060085 if (ti_i2c_eeprom_am_get(CONFIG_EEPROM_BUS_ADDRESS,
86 CONFIG_EEPROM_CHIP_ADDRESS))
Lokesh Vutla93e0f5b2016-10-14 10:35:25 +053087 printf("ti_i2c_eeprom_init failed\n");
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000088}
Lokesh Vutla93e0f5b2016-10-14 10:35:25 +053089#endif
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000090
Lokesh Vutlaabb44e62016-05-16 11:47:29 +053091#ifndef CONFIG_DM_SERIAL
92struct serial_device *default_serial_console(void)
93{
94 if (board_is_icev2())
95 return &eserial4_device;
96 else
97 return &eserial1_device;
98}
99#endif
100
Tom Rini8de09df2014-04-09 08:25:57 -0400101#ifndef CONFIG_SKIP_LOWLEVEL_INIT
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000102static const struct ddr_data ddr2_data = {
Tom Rini7f50a572014-07-07 21:40:16 -0400103 .datardsratio0 = MT47H128M16RT25E_RD_DQS,
104 .datafwsratio0 = MT47H128M16RT25E_PHY_FIFO_WE,
105 .datawrsratio0 = MT47H128M16RT25E_PHY_WR_DATA,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000106};
107
108static const struct cmd_control ddr2_cmd_ctrl_data = {
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000109 .cmd0csratio = MT47H128M16RT25E_RATIO,
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000110
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000111 .cmd1csratio = MT47H128M16RT25E_RATIO,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000112
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000113 .cmd2csratio = MT47H128M16RT25E_RATIO,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000114};
115
116static const struct emif_regs ddr2_emif_reg_data = {
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000117 .sdram_config = MT47H128M16RT25E_EMIF_SDCFG,
118 .ref_ctrl = MT47H128M16RT25E_EMIF_SDREF,
119 .sdram_tim1 = MT47H128M16RT25E_EMIF_TIM1,
120 .sdram_tim2 = MT47H128M16RT25E_EMIF_TIM2,
121 .sdram_tim3 = MT47H128M16RT25E_EMIF_TIM3,
122 .emif_ddr_phy_ctlr_1 = MT47H128M16RT25E_EMIF_READ_LATENCY,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000123};
124
Jyri Sarha8d2998b2016-12-09 12:29:13 +0200125static const struct emif_regs ddr2_evm_emif_reg_data = {
126 .sdram_config = MT47H128M16RT25E_EMIF_SDCFG,
127 .ref_ctrl = MT47H128M16RT25E_EMIF_SDREF,
128 .sdram_tim1 = MT47H128M16RT25E_EMIF_TIM1,
129 .sdram_tim2 = MT47H128M16RT25E_EMIF_TIM2,
130 .sdram_tim3 = MT47H128M16RT25E_EMIF_TIM3,
131 .ocp_config = EMIF_OCP_CONFIG_AM335X_EVM,
132 .emif_ddr_phy_ctlr_1 = MT47H128M16RT25E_EMIF_READ_LATENCY,
133};
134
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000135static const struct ddr_data ddr3_data = {
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000136 .datardsratio0 = MT41J128MJT125_RD_DQS,
137 .datawdsratio0 = MT41J128MJT125_WR_DQS,
138 .datafwsratio0 = MT41J128MJT125_PHY_FIFO_WE,
139 .datawrsratio0 = MT41J128MJT125_PHY_WR_DATA,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000140};
141
Tom Rini385bc752013-03-21 04:30:02 +0000142static const struct ddr_data ddr3_beagleblack_data = {
143 .datardsratio0 = MT41K256M16HA125E_RD_DQS,
144 .datawdsratio0 = MT41K256M16HA125E_WR_DQS,
145 .datafwsratio0 = MT41K256M16HA125E_PHY_FIFO_WE,
146 .datawrsratio0 = MT41K256M16HA125E_PHY_WR_DATA,
Tom Rini385bc752013-03-21 04:30:02 +0000147};
148
Jeff Lance7c03a222013-01-14 05:32:20 +0000149static const struct ddr_data ddr3_evm_data = {
150 .datardsratio0 = MT41J512M8RH125_RD_DQS,
151 .datawdsratio0 = MT41J512M8RH125_WR_DQS,
152 .datafwsratio0 = MT41J512M8RH125_PHY_FIFO_WE,
153 .datawrsratio0 = MT41J512M8RH125_PHY_WR_DATA,
Jeff Lance7c03a222013-01-14 05:32:20 +0000154};
155
Lokesh Vutla5837b902016-05-16 11:47:24 +0530156static const struct ddr_data ddr3_icev2_data = {
157 .datardsratio0 = MT41J128MJT125_RD_DQS_400MHz,
158 .datawdsratio0 = MT41J128MJT125_WR_DQS_400MHz,
159 .datafwsratio0 = MT41J128MJT125_PHY_FIFO_WE_400MHz,
160 .datawrsratio0 = MT41J128MJT125_PHY_WR_DATA_400MHz,
161};
162
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000163static const struct cmd_control ddr3_cmd_ctrl_data = {
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000164 .cmd0csratio = MT41J128MJT125_RATIO,
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000165 .cmd0iclkout = MT41J128MJT125_INVERT_CLKOUT,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000166
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000167 .cmd1csratio = MT41J128MJT125_RATIO,
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000168 .cmd1iclkout = MT41J128MJT125_INVERT_CLKOUT,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000169
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000170 .cmd2csratio = MT41J128MJT125_RATIO,
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000171 .cmd2iclkout = MT41J128MJT125_INVERT_CLKOUT,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000172};
173
Tom Rini385bc752013-03-21 04:30:02 +0000174static const struct cmd_control ddr3_beagleblack_cmd_ctrl_data = {
175 .cmd0csratio = MT41K256M16HA125E_RATIO,
Tom Rini385bc752013-03-21 04:30:02 +0000176 .cmd0iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
177
178 .cmd1csratio = MT41K256M16HA125E_RATIO,
Tom Rini385bc752013-03-21 04:30:02 +0000179 .cmd1iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
180
181 .cmd2csratio = MT41K256M16HA125E_RATIO,
Tom Rini385bc752013-03-21 04:30:02 +0000182 .cmd2iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
183};
184
Jeff Lance7c03a222013-01-14 05:32:20 +0000185static const struct cmd_control ddr3_evm_cmd_ctrl_data = {
186 .cmd0csratio = MT41J512M8RH125_RATIO,
Jeff Lance7c03a222013-01-14 05:32:20 +0000187 .cmd0iclkout = MT41J512M8RH125_INVERT_CLKOUT,
188
189 .cmd1csratio = MT41J512M8RH125_RATIO,
Jeff Lance7c03a222013-01-14 05:32:20 +0000190 .cmd1iclkout = MT41J512M8RH125_INVERT_CLKOUT,
191
192 .cmd2csratio = MT41J512M8RH125_RATIO,
Jeff Lance7c03a222013-01-14 05:32:20 +0000193 .cmd2iclkout = MT41J512M8RH125_INVERT_CLKOUT,
194};
195
Lokesh Vutla5837b902016-05-16 11:47:24 +0530196static const struct cmd_control ddr3_icev2_cmd_ctrl_data = {
197 .cmd0csratio = MT41J128MJT125_RATIO_400MHz,
198 .cmd0iclkout = MT41J128MJT125_INVERT_CLKOUT_400MHz,
199
200 .cmd1csratio = MT41J128MJT125_RATIO_400MHz,
201 .cmd1iclkout = MT41J128MJT125_INVERT_CLKOUT_400MHz,
202
203 .cmd2csratio = MT41J128MJT125_RATIO_400MHz,
204 .cmd2iclkout = MT41J128MJT125_INVERT_CLKOUT_400MHz,
205};
206
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000207static struct emif_regs ddr3_emif_reg_data = {
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000208 .sdram_config = MT41J128MJT125_EMIF_SDCFG,
209 .ref_ctrl = MT41J128MJT125_EMIF_SDREF,
210 .sdram_tim1 = MT41J128MJT125_EMIF_TIM1,
211 .sdram_tim2 = MT41J128MJT125_EMIF_TIM2,
212 .sdram_tim3 = MT41J128MJT125_EMIF_TIM3,
213 .zq_config = MT41J128MJT125_ZQ_CFG,
Vaibhav Hiremathc30d57b2013-03-14 21:11:16 +0000214 .emif_ddr_phy_ctlr_1 = MT41J128MJT125_EMIF_READ_LATENCY |
215 PHY_EN_DYN_PWRDN,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000216};
Jeff Lance7c03a222013-01-14 05:32:20 +0000217
Tom Rini385bc752013-03-21 04:30:02 +0000218static struct emif_regs ddr3_beagleblack_emif_reg_data = {
219 .sdram_config = MT41K256M16HA125E_EMIF_SDCFG,
220 .ref_ctrl = MT41K256M16HA125E_EMIF_SDREF,
221 .sdram_tim1 = MT41K256M16HA125E_EMIF_TIM1,
222 .sdram_tim2 = MT41K256M16HA125E_EMIF_TIM2,
223 .sdram_tim3 = MT41K256M16HA125E_EMIF_TIM3,
Jyri Sarha8d2998b2016-12-09 12:29:13 +0200224 .ocp_config = EMIF_OCP_CONFIG_BEAGLEBONE_BLACK,
Tom Rini385bc752013-03-21 04:30:02 +0000225 .zq_config = MT41K256M16HA125E_ZQ_CFG,
226 .emif_ddr_phy_ctlr_1 = MT41K256M16HA125E_EMIF_READ_LATENCY,
227};
228
Jeff Lance7c03a222013-01-14 05:32:20 +0000229static struct emif_regs ddr3_evm_emif_reg_data = {
230 .sdram_config = MT41J512M8RH125_EMIF_SDCFG,
231 .ref_ctrl = MT41J512M8RH125_EMIF_SDREF,
232 .sdram_tim1 = MT41J512M8RH125_EMIF_TIM1,
233 .sdram_tim2 = MT41J512M8RH125_EMIF_TIM2,
234 .sdram_tim3 = MT41J512M8RH125_EMIF_TIM3,
Jyri Sarha8d2998b2016-12-09 12:29:13 +0200235 .ocp_config = EMIF_OCP_CONFIG_AM335X_EVM,
Jeff Lance7c03a222013-01-14 05:32:20 +0000236 .zq_config = MT41J512M8RH125_ZQ_CFG,
Vaibhav Hiremathc30d57b2013-03-14 21:11:16 +0000237 .emif_ddr_phy_ctlr_1 = MT41J512M8RH125_EMIF_READ_LATENCY |
238 PHY_EN_DYN_PWRDN,
Jeff Lance7c03a222013-01-14 05:32:20 +0000239};
Peter Korsgaardeb204db2013-05-13 08:36:30 +0000240
Lokesh Vutla5837b902016-05-16 11:47:24 +0530241static struct emif_regs ddr3_icev2_emif_reg_data = {
242 .sdram_config = MT41J128MJT125_EMIF_SDCFG_400MHz,
243 .ref_ctrl = MT41J128MJT125_EMIF_SDREF_400MHz,
244 .sdram_tim1 = MT41J128MJT125_EMIF_TIM1_400MHz,
245 .sdram_tim2 = MT41J128MJT125_EMIF_TIM2_400MHz,
246 .sdram_tim3 = MT41J128MJT125_EMIF_TIM3_400MHz,
247 .zq_config = MT41J128MJT125_ZQ_CFG_400MHz,
248 .emif_ddr_phy_ctlr_1 = MT41J128MJT125_EMIF_READ_LATENCY_400MHz |
249 PHY_EN_DYN_PWRDN,
250};
251
Peter Korsgaardeb204db2013-05-13 08:36:30 +0000252#ifdef CONFIG_SPL_OS_BOOT
253int spl_start_uboot(void)
254{
Alex Kiernandf0df672018-04-19 04:32:53 +0000255#ifdef CONFIG_SPL_SERIAL_SUPPORT
Peter Korsgaardeb204db2013-05-13 08:36:30 +0000256 /* break into full u-boot on 'c' */
Tom Rini810b5812014-03-28 12:03:38 -0400257 if (serial_tstc() && serial_getc() == 'c')
258 return 1;
Alex Kiernandf0df672018-04-19 04:32:53 +0000259#endif
Tom Rini810b5812014-03-28 12:03:38 -0400260
261#ifdef CONFIG_SPL_ENV_SUPPORT
262 env_init();
Simon Glass17539572017-08-03 12:22:07 -0600263 env_load();
Simon Glass22c34c22017-08-03 12:22:13 -0600264 if (env_get_yesno("boot_os") != 1)
Tom Rini810b5812014-03-28 12:03:38 -0400265 return 1;
266#endif
267
268 return 0;
Peter Korsgaardeb204db2013-05-13 08:36:30 +0000269}
270#endif
271
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530272const struct dpll_params *get_dpll_ddr_params(void)
Tom Rini52437072013-08-30 16:28:46 -0400273{
Lokesh Vutla6302e532017-05-05 12:59:10 +0530274 int ind = get_sys_clk_index();
275
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530276 if (board_is_evm_sk())
Lokesh Vutla6302e532017-05-05 12:59:10 +0530277 return &dpll_ddr3_303MHz[ind];
Jason Kridnerb56b5b32018-03-07 05:40:41 -0500278 else if (board_is_pb() || board_is_bone_lt() || board_is_icev2())
Lokesh Vutla6302e532017-05-05 12:59:10 +0530279 return &dpll_ddr3_400MHz[ind];
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530280 else if (board_is_evm_15_or_later())
Lokesh Vutla6302e532017-05-05 12:59:10 +0530281 return &dpll_ddr3_303MHz[ind];
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530282 else
Lokesh Vutla6302e532017-05-05 12:59:10 +0530283 return &dpll_ddr2_266MHz[ind];
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530284}
Tom Rini52437072013-08-30 16:28:46 -0400285
Lokesh Vutla6302e532017-05-05 12:59:10 +0530286static u8 bone_not_connected_to_ac_power(void)
287{
288 if (board_is_bone()) {
289 uchar pmic_status_reg;
290 if (tps65217_reg_read(TPS65217_STATUS,
291 &pmic_status_reg))
292 return 1;
293 if (!(pmic_status_reg & TPS65217_PWR_SRC_AC_BITMASK)) {
294 puts("No AC power, switching to default OPP\n");
295 return 1;
296 }
297 }
298 return 0;
299}
300
301const struct dpll_params *get_dpll_mpu_params(void)
302{
303 int ind = get_sys_clk_index();
304 int freq = am335x_get_efuse_mpu_max_freq(cdev);
305
306 if (bone_not_connected_to_ac_power())
307 freq = MPUPLL_M_600;
308
Jason Kridnerb56b5b32018-03-07 05:40:41 -0500309 if (board_is_pb() || board_is_bone_lt())
Lokesh Vutla6302e532017-05-05 12:59:10 +0530310 freq = MPUPLL_M_1000;
311
312 switch (freq) {
313 case MPUPLL_M_1000:
314 return &dpll_mpu_opp[ind][5];
315 case MPUPLL_M_800:
316 return &dpll_mpu_opp[ind][4];
317 case MPUPLL_M_720:
318 return &dpll_mpu_opp[ind][3];
319 case MPUPLL_M_600:
320 return &dpll_mpu_opp[ind][2];
321 case MPUPLL_M_500:
322 return &dpll_mpu_opp100;
323 case MPUPLL_M_300:
324 return &dpll_mpu_opp[ind][0];
325 }
326
327 return &dpll_mpu_opp[ind][0];
328}
329
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530330static void scale_vcores_bone(int freq)
331{
332 int usb_cur_lim, mpu_vdd;
Tom Rini52437072013-08-30 16:28:46 -0400333
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530334 /*
335 * Only perform PMIC configurations if board rev > A1
336 * on Beaglebone White
337 */
338 if (board_is_bone() && !strncmp(board_ti_get_rev(), "00A1", 4))
339 return;
Tom Rini52437072013-08-30 16:28:46 -0400340
Igor Opaniukf7c91762021-02-09 13:52:45 +0200341#if !CONFIG_IS_ENABLED(DM_I2C)
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530342 if (i2c_probe(TPS65217_CHIP_PM))
343 return;
Jean-Jacques Hiblot52a51512018-12-07 14:50:49 +0100344#else
345 if (power_tps65217_init(0))
346 return;
347#endif
348
Tom Rini52437072013-08-30 16:28:46 -0400349
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530350 /*
351 * On Beaglebone White we need to ensure we have AC power
352 * before increasing the frequency.
353 */
Lokesh Vutla6302e532017-05-05 12:59:10 +0530354 if (bone_not_connected_to_ac_power())
355 freq = MPUPLL_M_600;
Tom Rini52437072013-08-30 16:28:46 -0400356
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530357 /*
358 * Override what we have detected since we know if we have
359 * a Beaglebone Black it supports 1GHz.
360 */
Jason Kridnerb56b5b32018-03-07 05:40:41 -0500361 if (board_is_pb() || board_is_bone_lt())
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530362 freq = MPUPLL_M_1000;
Tom Rini52437072013-08-30 16:28:46 -0400363
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530364 switch (freq) {
365 case MPUPLL_M_1000:
366 mpu_vdd = TPS65217_DCDC_VOLT_SEL_1325MV;
367 usb_cur_lim = TPS65217_USB_INPUT_CUR_LIMIT_1800MA;
368 break;
369 case MPUPLL_M_800:
370 mpu_vdd = TPS65217_DCDC_VOLT_SEL_1275MV;
Lokesh Vutlae29609a2017-06-10 13:22:56 +0530371 usb_cur_lim = TPS65217_USB_INPUT_CUR_LIMIT_1300MA;
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530372 break;
373 case MPUPLL_M_720:
374 mpu_vdd = TPS65217_DCDC_VOLT_SEL_1200MV;
Lokesh Vutlae29609a2017-06-10 13:22:56 +0530375 usb_cur_lim = TPS65217_USB_INPUT_CUR_LIMIT_1300MA;
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530376 break;
377 case MPUPLL_M_600:
378 case MPUPLL_M_500:
379 case MPUPLL_M_300:
Lokesh Vutlae29609a2017-06-10 13:22:56 +0530380 default:
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530381 mpu_vdd = TPS65217_DCDC_VOLT_SEL_1100MV;
382 usb_cur_lim = TPS65217_USB_INPUT_CUR_LIMIT_1300MA;
383 break;
384 }
Steve Kipisz5adac352013-08-14 10:51:31 -0400385
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530386 if (tps65217_reg_write(TPS65217_PROT_LEVEL_NONE,
387 TPS65217_POWER_PATH,
388 usb_cur_lim,
389 TPS65217_USB_INPUT_CUR_LIMIT_MASK))
390 puts("tps65217_reg_write failure\n");
Tom Rini52437072013-08-30 16:28:46 -0400391
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530392 /* Set DCDC3 (CORE) voltage to 1.10V */
393 if (tps65217_voltage_update(TPS65217_DEFDCDC3,
394 TPS65217_DCDC_VOLT_SEL_1100MV)) {
395 puts("tps65217_voltage_update failure\n");
396 return;
397 }
Tom Rini52437072013-08-30 16:28:46 -0400398
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530399 /* Set DCDC2 (MPU) voltage */
400 if (tps65217_voltage_update(TPS65217_DEFDCDC2, mpu_vdd)) {
401 puts("tps65217_voltage_update failure\n");
402 return;
403 }
Tom Rini52437072013-08-30 16:28:46 -0400404
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530405 /*
406 * Set LDO3, LDO4 output voltage to 3.3V for Beaglebone.
407 * Set LDO3 to 1.8V and LDO4 to 3.3V for Beaglebone Black.
408 */
409 if (board_is_bone()) {
Tom Rini52437072013-08-30 16:28:46 -0400410 if (tps65217_reg_write(TPS65217_PROT_LEVEL_2,
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530411 TPS65217_DEFLS1,
Tom Rini52437072013-08-30 16:28:46 -0400412 TPS65217_LDO_VOLTAGE_OUT_3_3,
413 TPS65217_LDO_MASK))
414 puts("tps65217_reg_write failure\n");
415 } else {
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530416 if (tps65217_reg_write(TPS65217_PROT_LEVEL_2,
417 TPS65217_DEFLS1,
418 TPS65217_LDO_VOLTAGE_OUT_1_8,
419 TPS65217_LDO_MASK))
420 puts("tps65217_reg_write failure\n");
421 }
Tom Rini52437072013-08-30 16:28:46 -0400422
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530423 if (tps65217_reg_write(TPS65217_PROT_LEVEL_2,
424 TPS65217_DEFLS2,
425 TPS65217_LDO_VOLTAGE_OUT_3_3,
426 TPS65217_LDO_MASK))
427 puts("tps65217_reg_write failure\n");
428}
Tom Rini52437072013-08-30 16:28:46 -0400429
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530430void scale_vcores_generic(int freq)
431{
432 int sil_rev, mpu_vdd;
Tom Rini52437072013-08-30 16:28:46 -0400433
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530434 /*
435 * The GP EVM, IDK and EVM SK use a TPS65910 PMIC. For all
436 * MPU frequencies we support we use a CORE voltage of
437 * 1.10V. For MPU voltage we need to switch based on
438 * the frequency we are running at.
439 */
Igor Opaniukf7c91762021-02-09 13:52:45 +0200440#if !CONFIG_IS_ENABLED(DM_I2C)
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530441 if (i2c_probe(TPS65910_CTRL_I2C_ADDR))
442 return;
Jean-Jacques Hiblot52a51512018-12-07 14:50:49 +0100443#else
444 if (power_tps65910_init(0))
445 return;
446#endif
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530447 /*
448 * Depending on MPU clock and PG we will need a different
449 * VDD to drive at that speed.
450 */
451 sil_rev = readl(&cdev->deviceid) >> 28;
452 mpu_vdd = am335x_get_tps65910_mpu_vdd(sil_rev, freq);
Tom Rini52437072013-08-30 16:28:46 -0400453
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530454 /* Tell the TPS65910 to use i2c */
455 tps65910_set_i2c_control();
Steve Kipisz5adac352013-08-14 10:51:31 -0400456
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530457 /* First update MPU voltage. */
458 if (tps65910_voltage_update(MPU, mpu_vdd))
459 return;
Tom Rini52437072013-08-30 16:28:46 -0400460
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530461 /* Second, update the CORE voltage. */
462 if (tps65910_voltage_update(CORE, TPS65910_OP_REG_SEL_1_1_0))
463 return;
464
Tom Rini52437072013-08-30 16:28:46 -0400465}
466
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530467void gpi2c_init(void)
Lokesh Vutla89a83bf2013-07-30 10:48:52 +0530468{
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530469 /* When needed to be invoked prior to BSS initialization */
470 static bool first_time = true;
471
472 if (first_time) {
473 enable_i2c0_pin_mux();
Igor Opaniukf7c91762021-02-09 13:52:45 +0200474#if !CONFIG_IS_ENABLED(DM_I2C)
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530475 i2c_init(CONFIG_SYS_OMAP24_I2C_SPEED,
476 CONFIG_SYS_OMAP24_I2C_SLAVE);
Jean-Jacques Hiblot52a51512018-12-07 14:50:49 +0100477#endif
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530478 first_time = false;
479 }
480}
481
482void scale_vcores(void)
483{
484 int freq;
485
486 gpi2c_init();
487 freq = am335x_get_efuse_mpu_max_freq(cdev);
488
Lokesh Vutlae29609a2017-06-10 13:22:56 +0530489 if (board_is_beaglebonex())
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530490 scale_vcores_bone(freq);
Lokesh Vutla89a83bf2013-07-30 10:48:52 +0530491 else
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530492 scale_vcores_generic(freq);
Lokesh Vutla89a83bf2013-07-30 10:48:52 +0530493}
494
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530495void set_uart_mux_conf(void)
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000496{
Tom Rini986d7552014-08-01 09:53:24 -0400497#if CONFIG_CONS_INDEX == 1
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000498 enable_uart0_pin_mux();
Tom Rini986d7552014-08-01 09:53:24 -0400499#elif CONFIG_CONS_INDEX == 2
Andrew Bradford65c51ff2012-10-25 08:21:30 -0400500 enable_uart1_pin_mux();
Tom Rini986d7552014-08-01 09:53:24 -0400501#elif CONFIG_CONS_INDEX == 3
Andrew Bradford65c51ff2012-10-25 08:21:30 -0400502 enable_uart2_pin_mux();
Tom Rini986d7552014-08-01 09:53:24 -0400503#elif CONFIG_CONS_INDEX == 4
Andrew Bradford65c51ff2012-10-25 08:21:30 -0400504 enable_uart3_pin_mux();
Tom Rini986d7552014-08-01 09:53:24 -0400505#elif CONFIG_CONS_INDEX == 5
Andrew Bradford65c51ff2012-10-25 08:21:30 -0400506 enable_uart4_pin_mux();
Tom Rini986d7552014-08-01 09:53:24 -0400507#elif CONFIG_CONS_INDEX == 6
Andrew Bradford65c51ff2012-10-25 08:21:30 -0400508 enable_uart5_pin_mux();
Tom Rini986d7552014-08-01 09:53:24 -0400509#endif
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530510}
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000511
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530512void set_mux_conf_regs(void)
513{
Nishanth Menon2afa70d2016-02-24 12:30:55 -0600514 enable_board_pin_mux();
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530515}
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000516
Lokesh Vutla303b2672013-12-10 15:02:21 +0530517const struct ctrl_ioregs ioregs_evmsk = {
518 .cm0ioctl = MT41J128MJT125_IOCTRL_VALUE,
519 .cm1ioctl = MT41J128MJT125_IOCTRL_VALUE,
520 .cm2ioctl = MT41J128MJT125_IOCTRL_VALUE,
521 .dt0ioctl = MT41J128MJT125_IOCTRL_VALUE,
522 .dt1ioctl = MT41J128MJT125_IOCTRL_VALUE,
523};
524
525const struct ctrl_ioregs ioregs_bonelt = {
526 .cm0ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
527 .cm1ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
528 .cm2ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
529 .dt0ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
530 .dt1ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
531};
532
533const struct ctrl_ioregs ioregs_evm15 = {
534 .cm0ioctl = MT41J512M8RH125_IOCTRL_VALUE,
535 .cm1ioctl = MT41J512M8RH125_IOCTRL_VALUE,
536 .cm2ioctl = MT41J512M8RH125_IOCTRL_VALUE,
537 .dt0ioctl = MT41J512M8RH125_IOCTRL_VALUE,
538 .dt1ioctl = MT41J512M8RH125_IOCTRL_VALUE,
539};
540
541const struct ctrl_ioregs ioregs = {
542 .cm0ioctl = MT47H128M16RT25E_IOCTRL_VALUE,
543 .cm1ioctl = MT47H128M16RT25E_IOCTRL_VALUE,
544 .cm2ioctl = MT47H128M16RT25E_IOCTRL_VALUE,
545 .dt0ioctl = MT47H128M16RT25E_IOCTRL_VALUE,
546 .dt1ioctl = MT47H128M16RT25E_IOCTRL_VALUE,
547};
548
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530549void sdram_init(void)
550{
Nishanth Menon2afa70d2016-02-24 12:30:55 -0600551 if (board_is_evm_sk()) {
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000552 /*
553 * EVM SK 1.2A and later use gpio0_7 to enable DDR3.
554 * This is safe enough to do on older revs.
555 */
556 gpio_request(GPIO_DDR_VTT_EN, "ddr_vtt_en");
557 gpio_direction_output(GPIO_DDR_VTT_EN, 1);
558 }
559
Lokesh Vutla5837b902016-05-16 11:47:24 +0530560 if (board_is_icev2()) {
561 gpio_request(ICE_GPIO_DDR_VTT_EN, "ddr_vtt_en");
562 gpio_direction_output(ICE_GPIO_DDR_VTT_EN, 1);
563 }
564
Nishanth Menon2afa70d2016-02-24 12:30:55 -0600565 if (board_is_evm_sk())
Lokesh Vutla303b2672013-12-10 15:02:21 +0530566 config_ddr(303, &ioregs_evmsk, &ddr3_data,
Matt Porter65991ec2013-03-15 10:07:03 +0000567 &ddr3_cmd_ctrl_data, &ddr3_emif_reg_data, 0);
Jason Kridnerb56b5b32018-03-07 05:40:41 -0500568 else if (board_is_pb() || board_is_bone_lt())
Lokesh Vutla303b2672013-12-10 15:02:21 +0530569 config_ddr(400, &ioregs_bonelt,
Tom Rini385bc752013-03-21 04:30:02 +0000570 &ddr3_beagleblack_data,
571 &ddr3_beagleblack_cmd_ctrl_data,
572 &ddr3_beagleblack_emif_reg_data, 0);
Nishanth Menon2afa70d2016-02-24 12:30:55 -0600573 else if (board_is_evm_15_or_later())
Lokesh Vutla303b2672013-12-10 15:02:21 +0530574 config_ddr(303, &ioregs_evm15, &ddr3_evm_data,
Matt Porter65991ec2013-03-15 10:07:03 +0000575 &ddr3_evm_cmd_ctrl_data, &ddr3_evm_emif_reg_data, 0);
Lokesh Vutla5837b902016-05-16 11:47:24 +0530576 else if (board_is_icev2())
577 config_ddr(400, &ioregs_evmsk, &ddr3_icev2_data,
578 &ddr3_icev2_cmd_ctrl_data, &ddr3_icev2_emif_reg_data,
579 0);
Jyri Sarha8d2998b2016-12-09 12:29:13 +0200580 else if (board_is_gp_evm())
581 config_ddr(266, &ioregs, &ddr2_data,
582 &ddr2_cmd_ctrl_data, &ddr2_evm_emif_reg_data, 0);
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000583 else
Lokesh Vutla303b2672013-12-10 15:02:21 +0530584 config_ddr(266, &ioregs, &ddr2_data,
Matt Porter65991ec2013-03-15 10:07:03 +0000585 &ddr2_cmd_ctrl_data, &ddr2_emif_reg_data, 0);
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000586}
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530587#endif
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000588
Alex Kiernan20bba2e2018-04-01 09:22:37 +0000589#if defined(CONFIG_CLOCK_SYNTHESIZER) && (!defined(CONFIG_SPL_BUILD) || \
590 (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD)))
Roger Quadrosbcb4ee82016-08-24 15:35:50 +0300591static void request_and_set_gpio(int gpio, char *name, int val)
Lokesh Vutla0d144f52016-05-16 11:47:26 +0530592{
593 int ret;
594
595 ret = gpio_request(gpio, name);
596 if (ret < 0) {
597 printf("%s: Unable to request %s\n", __func__, name);
598 return;
599 }
600
601 ret = gpio_direction_output(gpio, 0);
602 if (ret < 0) {
603 printf("%s: Unable to set %s as output\n", __func__, name);
604 goto err_free_gpio;
605 }
606
Roger Quadrosbcb4ee82016-08-24 15:35:50 +0300607 gpio_set_value(gpio, val);
Lokesh Vutla0d144f52016-05-16 11:47:26 +0530608
609 return;
610
611err_free_gpio:
612 gpio_free(gpio);
613}
614
Roger Quadrosbcb4ee82016-08-24 15:35:50 +0300615#define REQUEST_AND_SET_GPIO(N) request_and_set_gpio(N, #N, 1);
616#define REQUEST_AND_CLR_GPIO(N) request_and_set_gpio(N, #N, 0);
Lokesh Vutla0d144f52016-05-16 11:47:26 +0530617
618/**
619 * RMII mode on ICEv2 board needs 50MHz clock. Given the clock
620 * synthesizer With a capacitor of 18pF, and 25MHz input clock cycle
621 * PLL1 gives an output of 100MHz. So, configuring the div2/3 as 2 to
622 * give 50MHz output for Eth0 and 1.
623 */
624static struct clk_synth cdce913_data = {
625 .id = 0x81,
626 .capacitor = 0x90,
627 .mux = 0x6d,
628 .pdiv2 = 0x2,
629 .pdiv3 = 0x2,
630};
631#endif
632
Sekhar Norif357b112018-08-23 17:11:30 +0530633#if defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_CONTROL) && \
634 defined(CONFIG_DM_ETH) && defined(CONFIG_DRIVER_TI_CPSW)
635
636#define MAX_CPSW_SLAVES 2
637
638/* At the moment, we do not want to stop booting for any failures here */
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900639int ft_board_setup(void *fdt, struct bd_info *bd)
Sekhar Norif357b112018-08-23 17:11:30 +0530640{
641 const char *slave_path, *enet_name;
642 int enetnode, slavenode, phynode;
643 struct udevice *ethdev;
644 char alias[16];
645 u32 phy_id[2];
646 int phy_addr;
647 int i, ret;
648
649 /* phy address fixup needed only on beagle bone family */
650 if (!board_is_beaglebonex())
651 goto done;
652
653 for (i = 0; i < MAX_CPSW_SLAVES; i++) {
654 sprintf(alias, "ethernet%d", i);
655
656 slave_path = fdt_get_alias(fdt, alias);
657 if (!slave_path)
658 continue;
659
660 slavenode = fdt_path_offset(fdt, slave_path);
661 if (slavenode < 0)
662 continue;
663
664 enetnode = fdt_parent_offset(fdt, slavenode);
665 enet_name = fdt_get_name(fdt, enetnode, NULL);
666
667 ethdev = eth_get_dev_by_name(enet_name);
668 if (!ethdev)
669 continue;
670
671 phy_addr = cpsw_get_slave_phy_addr(ethdev, i);
672
673 /* check for phy_id as well as phy-handle properties */
674 ret = fdtdec_get_int_array_count(fdt, slavenode, "phy_id",
675 phy_id, 2);
676 if (ret == 2) {
677 if (phy_id[1] != phy_addr) {
678 printf("fixing up phy_id for %s, old: %d, new: %d\n",
679 alias, phy_id[1], phy_addr);
680
681 phy_id[0] = cpu_to_fdt32(phy_id[0]);
682 phy_id[1] = cpu_to_fdt32(phy_addr);
683 do_fixup_by_path(fdt, slave_path, "phy_id",
684 phy_id, sizeof(phy_id), 0);
685 }
686 } else {
687 phynode = fdtdec_lookup_phandle(fdt, slavenode,
688 "phy-handle");
689 if (phynode < 0)
690 continue;
691
692 ret = fdtdec_get_int(fdt, phynode, "reg", -ENOENT);
693 if (ret < 0)
694 continue;
695
696 if (ret != phy_addr) {
697 printf("fixing up phy-handle for %s, old: %d, new: %d\n",
698 alias, ret, phy_addr);
699
700 fdt_setprop_u32(fdt, phynode, "reg",
701 cpu_to_fdt32(phy_addr));
702 }
703 }
704 }
705
706done:
707 return 0;
708}
709#endif
710
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000711/*
712 * Basic board specific setup. Pinmux has been handled already.
713 */
714int board_init(void)
715{
Tom Rini303bfe82013-10-01 12:32:04 -0400716#if defined(CONFIG_HW_WATCHDOG)
717 hw_watchdog_init();
718#endif
719
Tom Rinif3b6a1d2013-08-09 11:22:13 -0400720 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
Miquel Raynald0935362019-10-03 19:50:03 +0200721#if defined(CONFIG_NOR) || defined(CONFIG_MTD_RAW_NAND)
Ilya Yanok3d9725e2012-11-06 13:06:31 +0000722 gpmc_init();
Steve Kipiszbe9b6f82013-07-18 15:13:03 -0400723#endif
Lokesh Vutla0d144f52016-05-16 11:47:26 +0530724
Alex Kiernan20bba2e2018-04-01 09:22:37 +0000725#if defined(CONFIG_CLOCK_SYNTHESIZER) && (!defined(CONFIG_SPL_BUILD) || \
726 (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD)))
Lokesh Vutla0d144f52016-05-16 11:47:26 +0530727 if (board_is_icev2()) {
Roger Quadrosbcb4ee82016-08-24 15:35:50 +0300728 int rv;
729 u32 reg;
730
Lokesh Vutla0d144f52016-05-16 11:47:26 +0530731 REQUEST_AND_SET_GPIO(GPIO_PR1_MII_CTRL);
Roger Quadrosbcb4ee82016-08-24 15:35:50 +0300732 /* Make J19 status available on GPIO1_26 */
733 REQUEST_AND_CLR_GPIO(GPIO_MUX_MII_CTRL);
734
Lokesh Vutla0d144f52016-05-16 11:47:26 +0530735 REQUEST_AND_SET_GPIO(GPIO_FET_SWITCH_CTRL);
Roger Quadrosbcb4ee82016-08-24 15:35:50 +0300736 /*
737 * Both ports can be set as RMII-CPSW or MII-PRU-ETH using
738 * jumpers near the port. Read the jumper value and set
739 * the pinmux, external mux and PHY clock accordingly.
740 * As jumper line is overridden by PHY RX_DV pin immediately
741 * after bootstrap (power-up/reset), we need to sample
742 * it during PHY reset using GPIO rising edge detection.
743 */
Lokesh Vutla0d144f52016-05-16 11:47:26 +0530744 REQUEST_AND_SET_GPIO(GPIO_PHY_RESET);
Roger Quadrosbcb4ee82016-08-24 15:35:50 +0300745 /* Enable rising edge IRQ on GPIO0_11 and GPIO 1_26 */
746 reg = readl(GPIO0_RISINGDETECT) | BIT(11);
747 writel(reg, GPIO0_RISINGDETECT);
748 reg = readl(GPIO1_RISINGDETECT) | BIT(26);
749 writel(reg, GPIO1_RISINGDETECT);
750 /* Reset PHYs to capture the Jumper setting */
751 gpio_set_value(GPIO_PHY_RESET, 0);
752 udelay(2); /* PHY datasheet states 1uS min. */
753 gpio_set_value(GPIO_PHY_RESET, 1);
754
755 reg = readl(GPIO0_IRQSTATUSRAW) & BIT(11);
756 if (reg) {
757 writel(reg, GPIO0_IRQSTATUS1); /* clear irq */
758 /* RMII mode */
759 printf("ETH0, CPSW\n");
760 } else {
761 /* MII mode */
762 printf("ETH0, PRU\n");
763 cdce913_data.pdiv3 = 4; /* 25MHz PHY clk */
764 }
765
766 reg = readl(GPIO1_IRQSTATUSRAW) & BIT(26);
767 if (reg) {
768 writel(reg, GPIO1_IRQSTATUS1); /* clear irq */
769 /* RMII mode */
770 printf("ETH1, CPSW\n");
771 gpio_set_value(GPIO_MUX_MII_CTRL, 1);
772 } else {
773 /* MII mode */
774 printf("ETH1, PRU\n");
775 cdce913_data.pdiv2 = 4; /* 25MHz PHY clk */
776 }
777
778 /* disable rising edge IRQs */
779 reg = readl(GPIO0_RISINGDETECT) & ~BIT(11);
780 writel(reg, GPIO0_RISINGDETECT);
781 reg = readl(GPIO1_RISINGDETECT) & ~BIT(26);
782 writel(reg, GPIO1_RISINGDETECT);
Lokesh Vutla0d144f52016-05-16 11:47:26 +0530783
784 rv = setup_clock_synthesizer(&cdce913_data);
785 if (rv) {
786 printf("Clock synthesizer setup failed %d\n", rv);
787 return rv;
788 }
Roger Quadrosbcb4ee82016-08-24 15:35:50 +0300789
790 /* reset PHYs */
791 gpio_set_value(GPIO_PHY_RESET, 0);
792 udelay(2); /* PHY datasheet states 1uS min. */
793 gpio_set_value(GPIO_PHY_RESET, 1);
Lokesh Vutla0d144f52016-05-16 11:47:26 +0530794 }
795#endif
796
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000797 return 0;
798}
799
Tom Rini40271852012-10-24 07:28:17 +0000800#ifdef CONFIG_BOARD_LATE_INIT
801int board_late_init(void)
802{
Tero Kristo67f79e72019-09-27 19:14:29 +0300803 struct udevice *dev;
Roger Quadros7c9d3782016-08-24 15:35:51 +0300804#if !defined(CONFIG_SPL_BUILD)
805 uint8_t mac_addr[6];
806 uint32_t mac_hi, mac_lo;
807#endif
808
Tom Rini40271852012-10-24 07:28:17 +0000809#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
Nishanth Menon2afa70d2016-02-24 12:30:55 -0600810 char *name = NULL;
Tom Rini4021fd92013-07-18 15:13:01 -0400811
robertcnelson@gmail.comc5d7d222017-03-30 14:29:52 -0500812 if (board_is_bone_lt()) {
813 /* BeagleBoard.org BeagleBone Black Wireless: */
814 if (!strncmp(board_ti_get_rev(), "BWA", 3)) {
815 name = "BBBW";
816 }
robertcnelson@gmail.comb55cd7a2017-03-30 14:29:53 -0500817 /* SeeedStudio BeagleBone Green Wireless */
818 if (!strncmp(board_ti_get_rev(), "GW1", 3)) {
819 name = "BBGW";
820 }
robertcnelson@gmail.com89ef1d62017-03-30 14:29:54 -0500821 /* BeagleBoard.org BeagleBone Blue */
822 if (!strncmp(board_ti_get_rev(), "BLA", 3)) {
823 name = "BBBL";
824 }
robertcnelson@gmail.comc5d7d222017-03-30 14:29:52 -0500825 }
826
Nishanth Menon2afa70d2016-02-24 12:30:55 -0600827 if (board_is_bbg1())
828 name = "BBG1";
Koen Kooi8a157862018-07-18 10:13:59 +0200829 if (board_is_bben())
830 name = "BBEN";
Nishanth Menon2afa70d2016-02-24 12:30:55 -0600831 set_board_info_env(name);
Lokesh Vutla1eb0f542016-11-29 11:58:03 +0530832
833 /*
834 * Default FIT boot on HS devices. Non FIT images are not allowed
835 * on HS devices.
836 */
837 if (get_device_type() == HS_DEVICE)
Simon Glass6a38e412017-08-03 12:22:09 -0600838 env_set("boot_fit", "1");
Tom Rini40271852012-10-24 07:28:17 +0000839#endif
840
Roger Quadros7c9d3782016-08-24 15:35:51 +0300841#if !defined(CONFIG_SPL_BUILD)
842 /* try reading mac address from efuse */
843 mac_lo = readl(&cdev->macid0l);
844 mac_hi = readl(&cdev->macid0h);
845 mac_addr[0] = mac_hi & 0xFF;
846 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
847 mac_addr[2] = (mac_hi & 0xFF0000) >> 16;
848 mac_addr[3] = (mac_hi & 0xFF000000) >> 24;
849 mac_addr[4] = mac_lo & 0xFF;
850 mac_addr[5] = (mac_lo & 0xFF00) >> 8;
851
Simon Glass64b723f2017-08-03 12:22:12 -0600852 if (!env_get("ethaddr")) {
Roger Quadros7c9d3782016-08-24 15:35:51 +0300853 printf("<ethaddr> not set. Validating first E-fuse MAC\n");
854
855 if (is_valid_ethaddr(mac_addr))
Simon Glass8551d552017-08-03 12:22:11 -0600856 eth_env_set_enetaddr("ethaddr", mac_addr);
Roger Quadros7c9d3782016-08-24 15:35:51 +0300857 }
858
859 mac_lo = readl(&cdev->macid1l);
860 mac_hi = readl(&cdev->macid1h);
861 mac_addr[0] = mac_hi & 0xFF;
862 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
863 mac_addr[2] = (mac_hi & 0xFF0000) >> 16;
864 mac_addr[3] = (mac_hi & 0xFF000000) >> 24;
865 mac_addr[4] = mac_lo & 0xFF;
866 mac_addr[5] = (mac_lo & 0xFF00) >> 8;
867
Simon Glass64b723f2017-08-03 12:22:12 -0600868 if (!env_get("eth1addr")) {
Roger Quadros7c9d3782016-08-24 15:35:51 +0300869 if (is_valid_ethaddr(mac_addr))
Simon Glass8551d552017-08-03 12:22:11 -0600870 eth_env_set_enetaddr("eth1addr", mac_addr);
Roger Quadros7c9d3782016-08-24 15:35:51 +0300871 }
872#endif
873
Sam Protsenkoa31ca622018-02-28 00:26:15 +0200874 if (!env_get("serial#")) {
875 char *board_serial = env_get("board_serial");
876 char *ethaddr = env_get("ethaddr");
877
878 if (!board_serial || !strncmp(board_serial, "unknown", 7))
879 env_set("serial#", ethaddr);
880 else
881 env_set("serial#", board_serial);
882 }
883
Tero Kristo67f79e72019-09-27 19:14:29 +0300884 /* Just probe the potentially supported cdce913 device */
Dario Binacchic2de9d42020-12-30 00:16:32 +0100885 uclass_get_device_by_name(UCLASS_CLK, "cdce913@65", &dev);
Tero Kristo67f79e72019-09-27 19:14:29 +0300886
Tom Rini40271852012-10-24 07:28:17 +0000887 return 0;
888}
889#endif
890
Simon Glass71fa5b42020-12-03 16:55:18 -0700891/* CPSW plat */
Faiz Abbas27866262019-03-18 13:54:37 +0530892#if !CONFIG_IS_ENABLED(OF_CONTROL)
893struct cpsw_slave_data slave_data[] = {
894 {
895 .slave_reg_ofs = CPSW_SLAVE0_OFFSET,
896 .sliver_reg_ofs = CPSW_SLIVER0_OFFSET,
897 .phy_addr = 0,
898 },
899 {
900 .slave_reg_ofs = CPSW_SLAVE1_OFFSET,
901 .sliver_reg_ofs = CPSW_SLIVER1_OFFSET,
902 .phy_addr = 1,
903 },
904};
905
906struct cpsw_platform_data am335_eth_data = {
907 .cpsw_base = CPSW_BASE,
908 .version = CPSW_CTRL_VERSION_2,
909 .bd_ram_ofs = CPSW_BD_OFFSET,
910 .ale_reg_ofs = CPSW_ALE_OFFSET,
911 .cpdma_reg_ofs = CPSW_CPDMA_OFFSET,
912 .mdio_div = CPSW_MDIO_DIV,
913 .host_port_reg_ofs = CPSW_HOST_PORT_OFFSET,
914 .channels = 8,
915 .slaves = 2,
916 .slave_data = slave_data,
917 .ale_entries = 1024,
Faiz Abbas27866262019-03-18 13:54:37 +0530918 .mac_control = 0x20,
919 .active_slave = 0,
920 .mdio_base = 0x4a101000,
921 .gmii_sel = 0x44e10650,
922 .phy_sel_compat = "ti,am3352-cpsw-phy-sel",
923 .syscon_addr = 0x44e10630,
924 .macid_sel_compat = "cpsw,am33xx",
925};
926
927struct eth_pdata cpsw_pdata = {
928 .iobase = 0x4a100000,
929 .phy_interface = 0,
930 .priv_pdata = &am335_eth_data,
931};
932
Simon Glass1d8364a2020-12-28 20:34:54 -0700933U_BOOT_DRVINFO(am335x_eth) = {
Faiz Abbas27866262019-03-18 13:54:37 +0530934 .name = "eth_cpsw",
Simon Glass71fa5b42020-12-03 16:55:18 -0700935 .plat = &cpsw_pdata,
Faiz Abbas27866262019-03-18 13:54:37 +0530936};
937#endif
938
Lokesh Vutla89b9f302016-05-16 11:24:24 +0530939#ifdef CONFIG_SPL_LOAD_FIT
940int board_fit_config_name_match(const char *name)
941{
942 if (board_is_gp_evm() && !strcmp(name, "am335x-evm"))
943 return 0;
944 else if (board_is_bone() && !strcmp(name, "am335x-bone"))
945 return 0;
946 else if (board_is_bone_lt() && !strcmp(name, "am335x-boneblack"))
947 return 0;
Jason Kridnerb56b5b32018-03-07 05:40:41 -0500948 else if (board_is_pb() && !strcmp(name, "am335x-pocketbeagle"))
949 return 0;
Lokesh Vutla5a954ba2016-05-16 11:24:28 +0530950 else if (board_is_evm_sk() && !strcmp(name, "am335x-evmsk"))
951 return 0;
Lokesh Vutla1edfcaf2016-05-16 11:24:29 +0530952 else if (board_is_bbg1() && !strcmp(name, "am335x-bonegreen"))
953 return 0;
Lokesh Vutla7ecf1962016-05-16 11:47:28 +0530954 else if (board_is_icev2() && !strcmp(name, "am335x-icev2"))
955 return 0;
Lokesh Vutla89b9f302016-05-16 11:24:24 +0530956 else
957 return -1;
958}
959#endif
Andrew F. Davisbd249152016-08-30 14:06:24 -0500960
961#ifdef CONFIG_TI_SECURE_DEVICE
962void board_fit_image_post_process(void **p_image, size_t *p_size)
963{
964 secure_boot_verify_image(p_image, p_size);
965}
966#endif
Lokesh Vutla2fe7c792017-04-26 13:37:08 +0530967
968#if !CONFIG_IS_ENABLED(OF_CONTROL)
Simon Glassb75b15b2020-12-03 16:55:23 -0700969static const struct omap_hsmmc_plat am335x_mmc0_plat = {
Lokesh Vutla2fe7c792017-04-26 13:37:08 +0530970 .base_addr = (struct hsmmc *)OMAP_HSMMC1_BASE,
971 .cfg.host_caps = MMC_MODE_HS_52MHz | MMC_MODE_HS | MMC_MODE_4BIT,
972 .cfg.f_min = 400000,
973 .cfg.f_max = 52000000,
974 .cfg.voltages = MMC_VDD_32_33 | MMC_VDD_33_34 | MMC_VDD_165_195,
975 .cfg.b_max = CONFIG_SYS_MMC_MAX_BLK_COUNT,
976};
977
Simon Glass1d8364a2020-12-28 20:34:54 -0700978U_BOOT_DRVINFO(am335x_mmc0) = {
Lokesh Vutla2fe7c792017-04-26 13:37:08 +0530979 .name = "omap_hsmmc",
Simon Glassb75b15b2020-12-03 16:55:23 -0700980 .plat = &am335x_mmc0_plat,
Lokesh Vutla2fe7c792017-04-26 13:37:08 +0530981};
982
Simon Glassb75b15b2020-12-03 16:55:23 -0700983static const struct omap_hsmmc_plat am335x_mmc1_plat = {
Lokesh Vutla2fe7c792017-04-26 13:37:08 +0530984 .base_addr = (struct hsmmc *)OMAP_HSMMC2_BASE,
985 .cfg.host_caps = MMC_MODE_HS_52MHz | MMC_MODE_HS | MMC_MODE_8BIT,
986 .cfg.f_min = 400000,
987 .cfg.f_max = 52000000,
988 .cfg.voltages = MMC_VDD_32_33 | MMC_VDD_33_34 | MMC_VDD_165_195,
989 .cfg.b_max = CONFIG_SYS_MMC_MAX_BLK_COUNT,
990};
991
Simon Glass1d8364a2020-12-28 20:34:54 -0700992U_BOOT_DRVINFO(am335x_mmc1) = {
Lokesh Vutla2fe7c792017-04-26 13:37:08 +0530993 .name = "omap_hsmmc",
Simon Glassb75b15b2020-12-03 16:55:23 -0700994 .plat = &am335x_mmc1_plat,
Lokesh Vutla2fe7c792017-04-26 13:37:08 +0530995};
996#endif