blob: 681002ba1dab554ac7cf84134bc4433718ace471 [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 *
Nishanth Menoneaa39c62023-11-01 15:56:03 -05007 * Copyright (C) 2011, Texas Instruments, Incorporated - https://www.ti.com/
Peter Korsgaard85ec2db2012-10-18 01:21:09 +00008 */
9
Tom Rinidec7ea02024-05-20 13:35:03 -060010#include <config.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>
Amjad Ouled-Ameur4d797722021-10-29 16:08:17 +020014#include <hang.h>
Simon Glass2dc9c342020-05-10 11:40:01 -060015#include <image.h>
Simon Glassa7b51302019-11-14 12:57:46 -070016#include <init.h>
Simon Glass9bc15642020-02-03 07:36:16 -070017#include <malloc.h>
Simon Glass274e0b02020-05-10 11:39:56 -060018#include <net.h>
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000019#include <spl.h>
Lokesh Vutlaabb44e62016-05-16 11:47:29 +053020#include <serial.h>
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000021#include <asm/arch/cpu.h>
22#include <asm/arch/hardware.h>
23#include <asm/arch/omap.h>
24#include <asm/arch/ddr_defs.h>
25#include <asm/arch/clock.h>
Lokesh Vutla0d144f52016-05-16 11:47:26 +053026#include <asm/arch/clk_synthesizer.h>
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000027#include <asm/arch/gpio.h>
28#include <asm/arch/mmc_host_def.h>
29#include <asm/arch/sys_proto.h>
Steve Kipiszbe9b6f82013-07-18 15:13:03 -040030#include <asm/arch/mem.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060031#include <asm/global_data.h>
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000032#include <asm/io.h>
33#include <asm/emif.h>
34#include <asm/gpio.h>
Semen Protsenkoa8cb0222017-06-02 18:00:00 +030035#include <asm/omap_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>
Amjad Ouled-Ameur4d797722021-10-29 16:08:17 +020041#include <linux/compiler.h>
Simon Glassdbd79542020-05-10 11:40:11 -060042#include <linux/delay.h>
Tom Rini52437072013-08-30 16:28:46 -040043#include <power/tps65217.h>
44#include <power/tps65910.h>
Simon Glass9d1f6192019-08-02 09:44:25 -060045#include <env_internal.h>
Tom Rini303bfe82013-10-01 12:32:04 -040046#include <watchdog.h>
Nishanth Menon2afa70d2016-02-24 12:30:55 -060047#include "../common/board_detect.h"
Kory Maincent169bf972021-05-04 19:31:30 +020048#include "../common/cape_detect.h"
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000049#include "board.h"
50
51DECLARE_GLOBAL_DATA_PTR;
52
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000053/* GPIO that controls power to DDR on EVM-SK */
Lokesh Vutla0d144f52016-05-16 11:47:26 +053054#define GPIO_TO_PIN(bank, gpio) (32 * (bank) + (gpio))
55#define GPIO_DDR_VTT_EN GPIO_TO_PIN(0, 7)
56#define ICE_GPIO_DDR_VTT_EN GPIO_TO_PIN(0, 18)
57#define GPIO_PR1_MII_CTRL GPIO_TO_PIN(3, 4)
58#define GPIO_MUX_MII_CTRL GPIO_TO_PIN(3, 10)
59#define GPIO_FET_SWITCH_CTRL GPIO_TO_PIN(0, 7)
60#define GPIO_PHY_RESET GPIO_TO_PIN(2, 5)
Roger Quadrosbcb4ee82016-08-24 15:35:50 +030061#define GPIO_ETH0_MODE GPIO_TO_PIN(0, 11)
62#define GPIO_ETH1_MODE GPIO_TO_PIN(1, 26)
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000063
64static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
65
Roger Quadrosbcb4ee82016-08-24 15:35:50 +030066#define GPIO0_RISINGDETECT (AM33XX_GPIO0_BASE + OMAP_GPIO_RISINGDETECT)
67#define GPIO1_RISINGDETECT (AM33XX_GPIO1_BASE + OMAP_GPIO_RISINGDETECT)
68
69#define GPIO0_IRQSTATUS1 (AM33XX_GPIO0_BASE + OMAP_GPIO_IRQSTATUS1)
70#define GPIO1_IRQSTATUS1 (AM33XX_GPIO1_BASE + OMAP_GPIO_IRQSTATUS1)
71
72#define GPIO0_IRQSTATUSRAW (AM33XX_GPIO0_BASE + 0x024)
73#define GPIO1_IRQSTATUSRAW (AM33XX_GPIO1_BASE + 0x024)
74
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000075/*
76 * Read header information from EEPROM into global structure.
77 */
Lokesh Vutla93e0f5b2016-10-14 10:35:25 +053078#ifdef CONFIG_TI_I2C_BOARD_DETECT
79void do_board_detect(void)
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000080{
Lokesh Vutla93e0f5b2016-10-14 10:35:25 +053081 enable_i2c0_pin_mux();
Kory Maincent4c1a71d2021-05-04 19:31:29 +020082 enable_i2c2_pin_mux();
Simon Glass4df67572017-05-12 21:09:55 -060083 if (ti_i2c_eeprom_am_get(CONFIG_EEPROM_BUS_ADDRESS,
84 CONFIG_EEPROM_CHIP_ADDRESS))
Lokesh Vutla93e0f5b2016-10-14 10:35:25 +053085 printf("ti_i2c_eeprom_init failed\n");
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000086}
Lokesh Vutla93e0f5b2016-10-14 10:35:25 +053087#endif
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000088
Lokesh Vutlaabb44e62016-05-16 11:47:29 +053089#ifndef CONFIG_DM_SERIAL
90struct serial_device *default_serial_console(void)
91{
92 if (board_is_icev2())
93 return &eserial4_device;
94 else
95 return &eserial1_device;
96}
97#endif
98
Tom Rinie1e85442021-08-27 21:18:30 -040099#if !CONFIG_IS_ENABLED(SKIP_LOWLEVEL_INIT)
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000100static const struct ddr_data ddr2_data = {
Tom Rini7f50a572014-07-07 21:40:16 -0400101 .datardsratio0 = MT47H128M16RT25E_RD_DQS,
102 .datafwsratio0 = MT47H128M16RT25E_PHY_FIFO_WE,
103 .datawrsratio0 = MT47H128M16RT25E_PHY_WR_DATA,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000104};
105
106static const struct cmd_control ddr2_cmd_ctrl_data = {
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000107 .cmd0csratio = MT47H128M16RT25E_RATIO,
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000108
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000109 .cmd1csratio = MT47H128M16RT25E_RATIO,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000110
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000111 .cmd2csratio = MT47H128M16RT25E_RATIO,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000112};
113
114static const struct emif_regs ddr2_emif_reg_data = {
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000115 .sdram_config = MT47H128M16RT25E_EMIF_SDCFG,
116 .ref_ctrl = MT47H128M16RT25E_EMIF_SDREF,
117 .sdram_tim1 = MT47H128M16RT25E_EMIF_TIM1,
118 .sdram_tim2 = MT47H128M16RT25E_EMIF_TIM2,
119 .sdram_tim3 = MT47H128M16RT25E_EMIF_TIM3,
120 .emif_ddr_phy_ctlr_1 = MT47H128M16RT25E_EMIF_READ_LATENCY,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000121};
122
Jyri Sarha8d2998b2016-12-09 12:29:13 +0200123static const struct emif_regs ddr2_evm_emif_reg_data = {
124 .sdram_config = MT47H128M16RT25E_EMIF_SDCFG,
125 .ref_ctrl = MT47H128M16RT25E_EMIF_SDREF,
126 .sdram_tim1 = MT47H128M16RT25E_EMIF_TIM1,
127 .sdram_tim2 = MT47H128M16RT25E_EMIF_TIM2,
128 .sdram_tim3 = MT47H128M16RT25E_EMIF_TIM3,
129 .ocp_config = EMIF_OCP_CONFIG_AM335X_EVM,
130 .emif_ddr_phy_ctlr_1 = MT47H128M16RT25E_EMIF_READ_LATENCY,
131};
132
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000133static const struct ddr_data ddr3_data = {
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000134 .datardsratio0 = MT41J128MJT125_RD_DQS,
135 .datawdsratio0 = MT41J128MJT125_WR_DQS,
136 .datafwsratio0 = MT41J128MJT125_PHY_FIFO_WE,
137 .datawrsratio0 = MT41J128MJT125_PHY_WR_DATA,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000138};
139
Tom Rini385bc752013-03-21 04:30:02 +0000140static const struct ddr_data ddr3_beagleblack_data = {
141 .datardsratio0 = MT41K256M16HA125E_RD_DQS,
142 .datawdsratio0 = MT41K256M16HA125E_WR_DQS,
143 .datafwsratio0 = MT41K256M16HA125E_PHY_FIFO_WE,
144 .datawrsratio0 = MT41K256M16HA125E_PHY_WR_DATA,
Tom Rini385bc752013-03-21 04:30:02 +0000145};
146
Jeff Lance7c03a222013-01-14 05:32:20 +0000147static const struct ddr_data ddr3_evm_data = {
148 .datardsratio0 = MT41J512M8RH125_RD_DQS,
149 .datawdsratio0 = MT41J512M8RH125_WR_DQS,
150 .datafwsratio0 = MT41J512M8RH125_PHY_FIFO_WE,
151 .datawrsratio0 = MT41J512M8RH125_PHY_WR_DATA,
Jeff Lance7c03a222013-01-14 05:32:20 +0000152};
153
Lokesh Vutla5837b902016-05-16 11:47:24 +0530154static const struct ddr_data ddr3_icev2_data = {
155 .datardsratio0 = MT41J128MJT125_RD_DQS_400MHz,
156 .datawdsratio0 = MT41J128MJT125_WR_DQS_400MHz,
157 .datafwsratio0 = MT41J128MJT125_PHY_FIFO_WE_400MHz,
158 .datawrsratio0 = MT41J128MJT125_PHY_WR_DATA_400MHz,
159};
160
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000161static const struct cmd_control ddr3_cmd_ctrl_data = {
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000162 .cmd0csratio = MT41J128MJT125_RATIO,
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000163 .cmd0iclkout = MT41J128MJT125_INVERT_CLKOUT,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000164
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000165 .cmd1csratio = MT41J128MJT125_RATIO,
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000166 .cmd1iclkout = MT41J128MJT125_INVERT_CLKOUT,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000167
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000168 .cmd2csratio = MT41J128MJT125_RATIO,
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000169 .cmd2iclkout = MT41J128MJT125_INVERT_CLKOUT,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000170};
171
Tom Rini385bc752013-03-21 04:30:02 +0000172static const struct cmd_control ddr3_beagleblack_cmd_ctrl_data = {
173 .cmd0csratio = MT41K256M16HA125E_RATIO,
Tom Rini385bc752013-03-21 04:30:02 +0000174 .cmd0iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
175
176 .cmd1csratio = MT41K256M16HA125E_RATIO,
Tom Rini385bc752013-03-21 04:30:02 +0000177 .cmd1iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
178
179 .cmd2csratio = MT41K256M16HA125E_RATIO,
Tom Rini385bc752013-03-21 04:30:02 +0000180 .cmd2iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
181};
182
Jeff Lance7c03a222013-01-14 05:32:20 +0000183static const struct cmd_control ddr3_evm_cmd_ctrl_data = {
184 .cmd0csratio = MT41J512M8RH125_RATIO,
Jeff Lance7c03a222013-01-14 05:32:20 +0000185 .cmd0iclkout = MT41J512M8RH125_INVERT_CLKOUT,
186
187 .cmd1csratio = MT41J512M8RH125_RATIO,
Jeff Lance7c03a222013-01-14 05:32:20 +0000188 .cmd1iclkout = MT41J512M8RH125_INVERT_CLKOUT,
189
190 .cmd2csratio = MT41J512M8RH125_RATIO,
Jeff Lance7c03a222013-01-14 05:32:20 +0000191 .cmd2iclkout = MT41J512M8RH125_INVERT_CLKOUT,
192};
193
Lokesh Vutla5837b902016-05-16 11:47:24 +0530194static const struct cmd_control ddr3_icev2_cmd_ctrl_data = {
195 .cmd0csratio = MT41J128MJT125_RATIO_400MHz,
196 .cmd0iclkout = MT41J128MJT125_INVERT_CLKOUT_400MHz,
197
198 .cmd1csratio = MT41J128MJT125_RATIO_400MHz,
199 .cmd1iclkout = MT41J128MJT125_INVERT_CLKOUT_400MHz,
200
201 .cmd2csratio = MT41J128MJT125_RATIO_400MHz,
202 .cmd2iclkout = MT41J128MJT125_INVERT_CLKOUT_400MHz,
203};
204
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000205static struct emif_regs ddr3_emif_reg_data = {
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000206 .sdram_config = MT41J128MJT125_EMIF_SDCFG,
207 .ref_ctrl = MT41J128MJT125_EMIF_SDREF,
208 .sdram_tim1 = MT41J128MJT125_EMIF_TIM1,
209 .sdram_tim2 = MT41J128MJT125_EMIF_TIM2,
210 .sdram_tim3 = MT41J128MJT125_EMIF_TIM3,
211 .zq_config = MT41J128MJT125_ZQ_CFG,
Vaibhav Hiremathc30d57b2013-03-14 21:11:16 +0000212 .emif_ddr_phy_ctlr_1 = MT41J128MJT125_EMIF_READ_LATENCY |
213 PHY_EN_DYN_PWRDN,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000214};
Jeff Lance7c03a222013-01-14 05:32:20 +0000215
Tom Rini385bc752013-03-21 04:30:02 +0000216static struct emif_regs ddr3_beagleblack_emif_reg_data = {
217 .sdram_config = MT41K256M16HA125E_EMIF_SDCFG,
218 .ref_ctrl = MT41K256M16HA125E_EMIF_SDREF,
219 .sdram_tim1 = MT41K256M16HA125E_EMIF_TIM1,
220 .sdram_tim2 = MT41K256M16HA125E_EMIF_TIM2,
221 .sdram_tim3 = MT41K256M16HA125E_EMIF_TIM3,
Jyri Sarha8d2998b2016-12-09 12:29:13 +0200222 .ocp_config = EMIF_OCP_CONFIG_BEAGLEBONE_BLACK,
Tom Rini385bc752013-03-21 04:30:02 +0000223 .zq_config = MT41K256M16HA125E_ZQ_CFG,
224 .emif_ddr_phy_ctlr_1 = MT41K256M16HA125E_EMIF_READ_LATENCY,
225};
226
Jeff Lance7c03a222013-01-14 05:32:20 +0000227static struct emif_regs ddr3_evm_emif_reg_data = {
228 .sdram_config = MT41J512M8RH125_EMIF_SDCFG,
229 .ref_ctrl = MT41J512M8RH125_EMIF_SDREF,
230 .sdram_tim1 = MT41J512M8RH125_EMIF_TIM1,
231 .sdram_tim2 = MT41J512M8RH125_EMIF_TIM2,
232 .sdram_tim3 = MT41J512M8RH125_EMIF_TIM3,
Jyri Sarha8d2998b2016-12-09 12:29:13 +0200233 .ocp_config = EMIF_OCP_CONFIG_AM335X_EVM,
Jeff Lance7c03a222013-01-14 05:32:20 +0000234 .zq_config = MT41J512M8RH125_ZQ_CFG,
Vaibhav Hiremathc30d57b2013-03-14 21:11:16 +0000235 .emif_ddr_phy_ctlr_1 = MT41J512M8RH125_EMIF_READ_LATENCY |
236 PHY_EN_DYN_PWRDN,
Jeff Lance7c03a222013-01-14 05:32:20 +0000237};
Peter Korsgaardeb204db2013-05-13 08:36:30 +0000238
Lokesh Vutla5837b902016-05-16 11:47:24 +0530239static struct emif_regs ddr3_icev2_emif_reg_data = {
240 .sdram_config = MT41J128MJT125_EMIF_SDCFG_400MHz,
241 .ref_ctrl = MT41J128MJT125_EMIF_SDREF_400MHz,
242 .sdram_tim1 = MT41J128MJT125_EMIF_TIM1_400MHz,
243 .sdram_tim2 = MT41J128MJT125_EMIF_TIM2_400MHz,
244 .sdram_tim3 = MT41J128MJT125_EMIF_TIM3_400MHz,
245 .zq_config = MT41J128MJT125_ZQ_CFG_400MHz,
246 .emif_ddr_phy_ctlr_1 = MT41J128MJT125_EMIF_READ_LATENCY_400MHz |
247 PHY_EN_DYN_PWRDN,
248};
249
Peter Korsgaardeb204db2013-05-13 08:36:30 +0000250#ifdef CONFIG_SPL_OS_BOOT
251int spl_start_uboot(void)
252{
Simon Glassf4d60392021-08-08 12:20:12 -0600253#ifdef CONFIG_SPL_SERIAL
Peter Korsgaardeb204db2013-05-13 08:36:30 +0000254 /* break into full u-boot on 'c' */
Tom Rini810b5812014-03-28 12:03:38 -0400255 if (serial_tstc() && serial_getc() == 'c')
256 return 1;
Alex Kiernandf0df672018-04-19 04:32:53 +0000257#endif
Tom Rini810b5812014-03-28 12:03:38 -0400258
259#ifdef CONFIG_SPL_ENV_SUPPORT
260 env_init();
Simon Glass17539572017-08-03 12:22:07 -0600261 env_load();
Simon Glass22c34c22017-08-03 12:22:13 -0600262 if (env_get_yesno("boot_os") != 1)
Tom Rini810b5812014-03-28 12:03:38 -0400263 return 1;
264#endif
265
266 return 0;
Peter Korsgaardeb204db2013-05-13 08:36:30 +0000267}
268#endif
269
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530270const struct dpll_params *get_dpll_ddr_params(void)
Tom Rini52437072013-08-30 16:28:46 -0400271{
Lokesh Vutla6302e532017-05-05 12:59:10 +0530272 int ind = get_sys_clk_index();
273
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530274 if (board_is_evm_sk())
Lokesh Vutla6302e532017-05-05 12:59:10 +0530275 return &dpll_ddr3_303MHz[ind];
Jason Kridnerb56b5b32018-03-07 05:40:41 -0500276 else if (board_is_pb() || board_is_bone_lt() || board_is_icev2())
Lokesh Vutla6302e532017-05-05 12:59:10 +0530277 return &dpll_ddr3_400MHz[ind];
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530278 else if (board_is_evm_15_or_later())
Lokesh Vutla6302e532017-05-05 12:59:10 +0530279 return &dpll_ddr3_303MHz[ind];
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530280 else
Lokesh Vutla6302e532017-05-05 12:59:10 +0530281 return &dpll_ddr2_266MHz[ind];
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530282}
Tom Rini52437072013-08-30 16:28:46 -0400283
Lokesh Vutla6302e532017-05-05 12:59:10 +0530284static u8 bone_not_connected_to_ac_power(void)
285{
286 if (board_is_bone()) {
287 uchar pmic_status_reg;
288 if (tps65217_reg_read(TPS65217_STATUS,
289 &pmic_status_reg))
290 return 1;
291 if (!(pmic_status_reg & TPS65217_PWR_SRC_AC_BITMASK)) {
292 puts("No AC power, switching to default OPP\n");
293 return 1;
294 }
295 }
296 return 0;
297}
298
299const struct dpll_params *get_dpll_mpu_params(void)
300{
301 int ind = get_sys_clk_index();
302 int freq = am335x_get_efuse_mpu_max_freq(cdev);
303
304 if (bone_not_connected_to_ac_power())
305 freq = MPUPLL_M_600;
306
Jason Kridnerb56b5b32018-03-07 05:40:41 -0500307 if (board_is_pb() || board_is_bone_lt())
Lokesh Vutla6302e532017-05-05 12:59:10 +0530308 freq = MPUPLL_M_1000;
309
310 switch (freq) {
311 case MPUPLL_M_1000:
312 return &dpll_mpu_opp[ind][5];
313 case MPUPLL_M_800:
314 return &dpll_mpu_opp[ind][4];
315 case MPUPLL_M_720:
316 return &dpll_mpu_opp[ind][3];
317 case MPUPLL_M_600:
318 return &dpll_mpu_opp[ind][2];
319 case MPUPLL_M_500:
320 return &dpll_mpu_opp100;
321 case MPUPLL_M_300:
322 return &dpll_mpu_opp[ind][0];
323 }
324
325 return &dpll_mpu_opp[ind][0];
326}
327
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530328static void scale_vcores_bone(int freq)
329{
330 int usb_cur_lim, mpu_vdd;
Tom Rini52437072013-08-30 16:28:46 -0400331
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530332 /*
333 * Only perform PMIC configurations if board rev > A1
334 * on Beaglebone White
335 */
336 if (board_is_bone() && !strncmp(board_ti_get_rev(), "00A1", 4))
337 return;
Tom Rini52437072013-08-30 16:28:46 -0400338
Jean-Jacques Hiblot52a51512018-12-07 14:50:49 +0100339 if (power_tps65217_init(0))
340 return;
Jean-Jacques Hiblot52a51512018-12-07 14:50:49 +0100341
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530342 /*
343 * On Beaglebone White we need to ensure we have AC power
344 * before increasing the frequency.
345 */
Lokesh Vutla6302e532017-05-05 12:59:10 +0530346 if (bone_not_connected_to_ac_power())
347 freq = MPUPLL_M_600;
Tom Rini52437072013-08-30 16:28:46 -0400348
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530349 /*
350 * Override what we have detected since we know if we have
351 * a Beaglebone Black it supports 1GHz.
352 */
Jason Kridnerb56b5b32018-03-07 05:40:41 -0500353 if (board_is_pb() || board_is_bone_lt())
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530354 freq = MPUPLL_M_1000;
Tom Rini52437072013-08-30 16:28:46 -0400355
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530356 switch (freq) {
357 case MPUPLL_M_1000:
358 mpu_vdd = TPS65217_DCDC_VOLT_SEL_1325MV;
359 usb_cur_lim = TPS65217_USB_INPUT_CUR_LIMIT_1800MA;
360 break;
361 case MPUPLL_M_800:
362 mpu_vdd = TPS65217_DCDC_VOLT_SEL_1275MV;
Lokesh Vutlae29609a2017-06-10 13:22:56 +0530363 usb_cur_lim = TPS65217_USB_INPUT_CUR_LIMIT_1300MA;
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530364 break;
365 case MPUPLL_M_720:
366 mpu_vdd = TPS65217_DCDC_VOLT_SEL_1200MV;
Lokesh Vutlae29609a2017-06-10 13:22:56 +0530367 usb_cur_lim = TPS65217_USB_INPUT_CUR_LIMIT_1300MA;
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530368 break;
369 case MPUPLL_M_600:
370 case MPUPLL_M_500:
371 case MPUPLL_M_300:
Lokesh Vutlae29609a2017-06-10 13:22:56 +0530372 default:
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530373 mpu_vdd = TPS65217_DCDC_VOLT_SEL_1100MV;
374 usb_cur_lim = TPS65217_USB_INPUT_CUR_LIMIT_1300MA;
375 break;
376 }
Steve Kipisz5adac352013-08-14 10:51:31 -0400377
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530378 if (tps65217_reg_write(TPS65217_PROT_LEVEL_NONE,
379 TPS65217_POWER_PATH,
380 usb_cur_lim,
381 TPS65217_USB_INPUT_CUR_LIMIT_MASK))
382 puts("tps65217_reg_write failure\n");
Tom Rini52437072013-08-30 16:28:46 -0400383
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530384 /* Set DCDC3 (CORE) voltage to 1.10V */
385 if (tps65217_voltage_update(TPS65217_DEFDCDC3,
386 TPS65217_DCDC_VOLT_SEL_1100MV)) {
387 puts("tps65217_voltage_update failure\n");
388 return;
389 }
Tom Rini52437072013-08-30 16:28:46 -0400390
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530391 /* Set DCDC2 (MPU) voltage */
392 if (tps65217_voltage_update(TPS65217_DEFDCDC2, mpu_vdd)) {
393 puts("tps65217_voltage_update failure\n");
394 return;
395 }
Tom Rini52437072013-08-30 16:28:46 -0400396
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530397 /*
398 * Set LDO3, LDO4 output voltage to 3.3V for Beaglebone.
399 * Set LDO3 to 1.8V and LDO4 to 3.3V for Beaglebone Black.
400 */
401 if (board_is_bone()) {
Tom Rini52437072013-08-30 16:28:46 -0400402 if (tps65217_reg_write(TPS65217_PROT_LEVEL_2,
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530403 TPS65217_DEFLS1,
Tom Rini52437072013-08-30 16:28:46 -0400404 TPS65217_LDO_VOLTAGE_OUT_3_3,
405 TPS65217_LDO_MASK))
406 puts("tps65217_reg_write failure\n");
407 } else {
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530408 if (tps65217_reg_write(TPS65217_PROT_LEVEL_2,
409 TPS65217_DEFLS1,
410 TPS65217_LDO_VOLTAGE_OUT_1_8,
411 TPS65217_LDO_MASK))
412 puts("tps65217_reg_write failure\n");
413 }
Tom Rini52437072013-08-30 16:28:46 -0400414
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530415 if (tps65217_reg_write(TPS65217_PROT_LEVEL_2,
416 TPS65217_DEFLS2,
417 TPS65217_LDO_VOLTAGE_OUT_3_3,
418 TPS65217_LDO_MASK))
419 puts("tps65217_reg_write failure\n");
420}
Tom Rini52437072013-08-30 16:28:46 -0400421
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530422void scale_vcores_generic(int freq)
423{
424 int sil_rev, mpu_vdd;
Tom Rini52437072013-08-30 16:28:46 -0400425
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530426 /*
427 * The GP EVM, IDK and EVM SK use a TPS65910 PMIC. For all
428 * MPU frequencies we support we use a CORE voltage of
429 * 1.10V. For MPU voltage we need to switch based on
430 * the frequency we are running at.
431 */
Jean-Jacques Hiblot52a51512018-12-07 14:50:49 +0100432 if (power_tps65910_init(0))
433 return;
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530434 /*
435 * Depending on MPU clock and PG we will need a different
436 * VDD to drive at that speed.
437 */
438 sil_rev = readl(&cdev->deviceid) >> 28;
439 mpu_vdd = am335x_get_tps65910_mpu_vdd(sil_rev, freq);
Tom Rini52437072013-08-30 16:28:46 -0400440
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530441 /* Tell the TPS65910 to use i2c */
442 tps65910_set_i2c_control();
Steve Kipisz5adac352013-08-14 10:51:31 -0400443
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530444 /* First update MPU voltage. */
445 if (tps65910_voltage_update(MPU, mpu_vdd))
446 return;
Tom Rini52437072013-08-30 16:28:46 -0400447
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530448 /* Second, update the CORE voltage. */
449 if (tps65910_voltage_update(CORE, TPS65910_OP_REG_SEL_1_1_0))
450 return;
451
Tom Rini52437072013-08-30 16:28:46 -0400452}
453
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530454void gpi2c_init(void)
Lokesh Vutla89a83bf2013-07-30 10:48:52 +0530455{
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530456 /* When needed to be invoked prior to BSS initialization */
457 static bool first_time = true;
458
459 if (first_time) {
460 enable_i2c0_pin_mux();
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530461 first_time = false;
462 }
463}
464
465void scale_vcores(void)
466{
467 int freq;
468
469 gpi2c_init();
470 freq = am335x_get_efuse_mpu_max_freq(cdev);
471
Lokesh Vutlae29609a2017-06-10 13:22:56 +0530472 if (board_is_beaglebonex())
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530473 scale_vcores_bone(freq);
Lokesh Vutla89a83bf2013-07-30 10:48:52 +0530474 else
Lokesh Vutla98f9d222017-05-05 12:59:09 +0530475 scale_vcores_generic(freq);
Lokesh Vutla89a83bf2013-07-30 10:48:52 +0530476}
477
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530478void set_uart_mux_conf(void)
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000479{
Tom Rini986d7552014-08-01 09:53:24 -0400480#if CONFIG_CONS_INDEX == 1
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000481 enable_uart0_pin_mux();
Tom Rini986d7552014-08-01 09:53:24 -0400482#elif CONFIG_CONS_INDEX == 2
Andrew Bradford65c51ff2012-10-25 08:21:30 -0400483 enable_uart1_pin_mux();
Tom Rini986d7552014-08-01 09:53:24 -0400484#elif CONFIG_CONS_INDEX == 3
Andrew Bradford65c51ff2012-10-25 08:21:30 -0400485 enable_uart2_pin_mux();
Tom Rini986d7552014-08-01 09:53:24 -0400486#elif CONFIG_CONS_INDEX == 4
Andrew Bradford65c51ff2012-10-25 08:21:30 -0400487 enable_uart3_pin_mux();
Tom Rini986d7552014-08-01 09:53:24 -0400488#elif CONFIG_CONS_INDEX == 5
Andrew Bradford65c51ff2012-10-25 08:21:30 -0400489 enable_uart4_pin_mux();
Tom Rini986d7552014-08-01 09:53:24 -0400490#elif CONFIG_CONS_INDEX == 6
Andrew Bradford65c51ff2012-10-25 08:21:30 -0400491 enable_uart5_pin_mux();
Tom Rini986d7552014-08-01 09:53:24 -0400492#endif
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530493}
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000494
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530495void set_mux_conf_regs(void)
496{
Nishanth Menon2afa70d2016-02-24 12:30:55 -0600497 enable_board_pin_mux();
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530498}
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000499
Lokesh Vutla303b2672013-12-10 15:02:21 +0530500const struct ctrl_ioregs ioregs_evmsk = {
501 .cm0ioctl = MT41J128MJT125_IOCTRL_VALUE,
502 .cm1ioctl = MT41J128MJT125_IOCTRL_VALUE,
503 .cm2ioctl = MT41J128MJT125_IOCTRL_VALUE,
504 .dt0ioctl = MT41J128MJT125_IOCTRL_VALUE,
505 .dt1ioctl = MT41J128MJT125_IOCTRL_VALUE,
506};
507
508const struct ctrl_ioregs ioregs_bonelt = {
509 .cm0ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
510 .cm1ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
511 .cm2ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
512 .dt0ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
513 .dt1ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
514};
515
516const struct ctrl_ioregs ioregs_evm15 = {
517 .cm0ioctl = MT41J512M8RH125_IOCTRL_VALUE,
518 .cm1ioctl = MT41J512M8RH125_IOCTRL_VALUE,
519 .cm2ioctl = MT41J512M8RH125_IOCTRL_VALUE,
520 .dt0ioctl = MT41J512M8RH125_IOCTRL_VALUE,
521 .dt1ioctl = MT41J512M8RH125_IOCTRL_VALUE,
522};
523
524const struct ctrl_ioregs ioregs = {
525 .cm0ioctl = MT47H128M16RT25E_IOCTRL_VALUE,
526 .cm1ioctl = MT47H128M16RT25E_IOCTRL_VALUE,
527 .cm2ioctl = MT47H128M16RT25E_IOCTRL_VALUE,
528 .dt0ioctl = MT47H128M16RT25E_IOCTRL_VALUE,
529 .dt1ioctl = MT47H128M16RT25E_IOCTRL_VALUE,
530};
531
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530532void sdram_init(void)
533{
Nishanth Menon2afa70d2016-02-24 12:30:55 -0600534 if (board_is_evm_sk()) {
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000535 /*
536 * EVM SK 1.2A and later use gpio0_7 to enable DDR3.
537 * This is safe enough to do on older revs.
538 */
539 gpio_request(GPIO_DDR_VTT_EN, "ddr_vtt_en");
540 gpio_direction_output(GPIO_DDR_VTT_EN, 1);
541 }
542
Lokesh Vutla5837b902016-05-16 11:47:24 +0530543 if (board_is_icev2()) {
544 gpio_request(ICE_GPIO_DDR_VTT_EN, "ddr_vtt_en");
545 gpio_direction_output(ICE_GPIO_DDR_VTT_EN, 1);
546 }
547
Nishanth Menon2afa70d2016-02-24 12:30:55 -0600548 if (board_is_evm_sk())
Lokesh Vutla303b2672013-12-10 15:02:21 +0530549 config_ddr(303, &ioregs_evmsk, &ddr3_data,
Matt Porter65991ec2013-03-15 10:07:03 +0000550 &ddr3_cmd_ctrl_data, &ddr3_emif_reg_data, 0);
Jason Kridnerb56b5b32018-03-07 05:40:41 -0500551 else if (board_is_pb() || board_is_bone_lt())
Lokesh Vutla303b2672013-12-10 15:02:21 +0530552 config_ddr(400, &ioregs_bonelt,
Tom Rini385bc752013-03-21 04:30:02 +0000553 &ddr3_beagleblack_data,
554 &ddr3_beagleblack_cmd_ctrl_data,
555 &ddr3_beagleblack_emif_reg_data, 0);
Nishanth Menon2afa70d2016-02-24 12:30:55 -0600556 else if (board_is_evm_15_or_later())
Lokesh Vutla303b2672013-12-10 15:02:21 +0530557 config_ddr(303, &ioregs_evm15, &ddr3_evm_data,
Matt Porter65991ec2013-03-15 10:07:03 +0000558 &ddr3_evm_cmd_ctrl_data, &ddr3_evm_emif_reg_data, 0);
Lokesh Vutla5837b902016-05-16 11:47:24 +0530559 else if (board_is_icev2())
560 config_ddr(400, &ioregs_evmsk, &ddr3_icev2_data,
561 &ddr3_icev2_cmd_ctrl_data, &ddr3_icev2_emif_reg_data,
562 0);
Jyri Sarha8d2998b2016-12-09 12:29:13 +0200563 else if (board_is_gp_evm())
564 config_ddr(266, &ioregs, &ddr2_data,
565 &ddr2_cmd_ctrl_data, &ddr2_evm_emif_reg_data, 0);
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000566 else
Lokesh Vutla303b2672013-12-10 15:02:21 +0530567 config_ddr(266, &ioregs, &ddr2_data,
Matt Porter65991ec2013-03-15 10:07:03 +0000568 &ddr2_cmd_ctrl_data, &ddr2_emif_reg_data, 0);
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000569}
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530570#endif
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000571
Alex Kiernan20bba2e2018-04-01 09:22:37 +0000572#if defined(CONFIG_CLOCK_SYNTHESIZER) && (!defined(CONFIG_SPL_BUILD) || \
Simon Glasse5cd9a42021-07-10 21:14:26 -0600573 (defined(CONFIG_SPL_ETH) && defined(CONFIG_SPL_BUILD)))
Roger Quadrosbcb4ee82016-08-24 15:35:50 +0300574static void request_and_set_gpio(int gpio, char *name, int val)
Lokesh Vutla0d144f52016-05-16 11:47:26 +0530575{
576 int ret;
577
578 ret = gpio_request(gpio, name);
579 if (ret < 0) {
580 printf("%s: Unable to request %s\n", __func__, name);
581 return;
582 }
583
584 ret = gpio_direction_output(gpio, 0);
585 if (ret < 0) {
586 printf("%s: Unable to set %s as output\n", __func__, name);
587 goto err_free_gpio;
588 }
589
Roger Quadrosbcb4ee82016-08-24 15:35:50 +0300590 gpio_set_value(gpio, val);
Lokesh Vutla0d144f52016-05-16 11:47:26 +0530591
592 return;
593
594err_free_gpio:
595 gpio_free(gpio);
596}
597
Roger Quadrosbcb4ee82016-08-24 15:35:50 +0300598#define REQUEST_AND_SET_GPIO(N) request_and_set_gpio(N, #N, 1);
599#define REQUEST_AND_CLR_GPIO(N) request_and_set_gpio(N, #N, 0);
Lokesh Vutla0d144f52016-05-16 11:47:26 +0530600
601/**
602 * RMII mode on ICEv2 board needs 50MHz clock. Given the clock
603 * synthesizer With a capacitor of 18pF, and 25MHz input clock cycle
604 * PLL1 gives an output of 100MHz. So, configuring the div2/3 as 2 to
605 * give 50MHz output for Eth0 and 1.
606 */
607static struct clk_synth cdce913_data = {
608 .id = 0x81,
609 .capacitor = 0x90,
610 .mux = 0x6d,
611 .pdiv2 = 0x2,
612 .pdiv3 = 0x2,
613};
614#endif
615
Sekhar Norif357b112018-08-23 17:11:30 +0530616#if defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_CONTROL) && \
617 defined(CONFIG_DM_ETH) && defined(CONFIG_DRIVER_TI_CPSW)
618
619#define MAX_CPSW_SLAVES 2
620
621/* At the moment, we do not want to stop booting for any failures here */
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900622int ft_board_setup(void *fdt, struct bd_info *bd)
Sekhar Norif357b112018-08-23 17:11:30 +0530623{
624 const char *slave_path, *enet_name;
625 int enetnode, slavenode, phynode;
626 struct udevice *ethdev;
627 char alias[16];
628 u32 phy_id[2];
629 int phy_addr;
630 int i, ret;
631
632 /* phy address fixup needed only on beagle bone family */
633 if (!board_is_beaglebonex())
634 goto done;
635
636 for (i = 0; i < MAX_CPSW_SLAVES; i++) {
637 sprintf(alias, "ethernet%d", i);
638
639 slave_path = fdt_get_alias(fdt, alias);
640 if (!slave_path)
641 continue;
642
643 slavenode = fdt_path_offset(fdt, slave_path);
644 if (slavenode < 0)
645 continue;
646
647 enetnode = fdt_parent_offset(fdt, slavenode);
648 enet_name = fdt_get_name(fdt, enetnode, NULL);
649
650 ethdev = eth_get_dev_by_name(enet_name);
651 if (!ethdev)
652 continue;
653
654 phy_addr = cpsw_get_slave_phy_addr(ethdev, i);
655
656 /* check for phy_id as well as phy-handle properties */
657 ret = fdtdec_get_int_array_count(fdt, slavenode, "phy_id",
658 phy_id, 2);
659 if (ret == 2) {
660 if (phy_id[1] != phy_addr) {
661 printf("fixing up phy_id for %s, old: %d, new: %d\n",
662 alias, phy_id[1], phy_addr);
663
664 phy_id[0] = cpu_to_fdt32(phy_id[0]);
665 phy_id[1] = cpu_to_fdt32(phy_addr);
666 do_fixup_by_path(fdt, slave_path, "phy_id",
667 phy_id, sizeof(phy_id), 0);
668 }
669 } else {
670 phynode = fdtdec_lookup_phandle(fdt, slavenode,
671 "phy-handle");
672 if (phynode < 0)
673 continue;
674
675 ret = fdtdec_get_int(fdt, phynode, "reg", -ENOENT);
676 if (ret < 0)
677 continue;
678
679 if (ret != phy_addr) {
680 printf("fixing up phy-handle for %s, old: %d, new: %d\n",
681 alias, ret, phy_addr);
682
683 fdt_setprop_u32(fdt, phynode, "reg",
684 cpu_to_fdt32(phy_addr));
685 }
686 }
687 }
688
689done:
690 return 0;
691}
692#endif
693
Amjad Ouled-Ameur4d797722021-10-29 16:08:17 +0200694static bool __maybe_unused prueth_is_mii = true;
695
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000696/*
697 * Basic board specific setup. Pinmux has been handled already.
698 */
699int board_init(void)
700{
Tom Rini303bfe82013-10-01 12:32:04 -0400701#if defined(CONFIG_HW_WATCHDOG)
702 hw_watchdog_init();
703#endif
704
Tom Rinibb4dd962022-11-16 13:10:37 -0500705 gd->bd->bi_boot_params = CFG_SYS_SDRAM_BASE + 0x100;
Miquel Raynald0935362019-10-03 19:50:03 +0200706#if defined(CONFIG_NOR) || defined(CONFIG_MTD_RAW_NAND)
Ilya Yanok3d9725e2012-11-06 13:06:31 +0000707 gpmc_init();
Steve Kipiszbe9b6f82013-07-18 15:13:03 -0400708#endif
Lokesh Vutla0d144f52016-05-16 11:47:26 +0530709
Alex Kiernan20bba2e2018-04-01 09:22:37 +0000710#if defined(CONFIG_CLOCK_SYNTHESIZER) && (!defined(CONFIG_SPL_BUILD) || \
Simon Glasse5cd9a42021-07-10 21:14:26 -0600711 (defined(CONFIG_SPL_ETH) && defined(CONFIG_SPL_BUILD)))
Lokesh Vutla0d144f52016-05-16 11:47:26 +0530712 if (board_is_icev2()) {
Roger Quadrosbcb4ee82016-08-24 15:35:50 +0300713 int rv;
714 u32 reg;
Amjad Ouled-Ameur4d797722021-10-29 16:08:17 +0200715 bool eth0_is_mii = true;
716 bool eth1_is_mii = true;
Roger Quadrosbcb4ee82016-08-24 15:35:50 +0300717
Lokesh Vutla0d144f52016-05-16 11:47:26 +0530718 REQUEST_AND_SET_GPIO(GPIO_PR1_MII_CTRL);
Roger Quadrosbcb4ee82016-08-24 15:35:50 +0300719 /* Make J19 status available on GPIO1_26 */
720 REQUEST_AND_CLR_GPIO(GPIO_MUX_MII_CTRL);
721
Lokesh Vutla0d144f52016-05-16 11:47:26 +0530722 REQUEST_AND_SET_GPIO(GPIO_FET_SWITCH_CTRL);
Roger Quadrosbcb4ee82016-08-24 15:35:50 +0300723 /*
724 * Both ports can be set as RMII-CPSW or MII-PRU-ETH using
725 * jumpers near the port. Read the jumper value and set
726 * the pinmux, external mux and PHY clock accordingly.
727 * As jumper line is overridden by PHY RX_DV pin immediately
728 * after bootstrap (power-up/reset), we need to sample
729 * it during PHY reset using GPIO rising edge detection.
730 */
Lokesh Vutla0d144f52016-05-16 11:47:26 +0530731 REQUEST_AND_SET_GPIO(GPIO_PHY_RESET);
Roger Quadrosbcb4ee82016-08-24 15:35:50 +0300732 /* Enable rising edge IRQ on GPIO0_11 and GPIO 1_26 */
733 reg = readl(GPIO0_RISINGDETECT) | BIT(11);
734 writel(reg, GPIO0_RISINGDETECT);
735 reg = readl(GPIO1_RISINGDETECT) | BIT(26);
736 writel(reg, GPIO1_RISINGDETECT);
737 /* Reset PHYs to capture the Jumper setting */
738 gpio_set_value(GPIO_PHY_RESET, 0);
739 udelay(2); /* PHY datasheet states 1uS min. */
740 gpio_set_value(GPIO_PHY_RESET, 1);
741
742 reg = readl(GPIO0_IRQSTATUSRAW) & BIT(11);
743 if (reg) {
744 writel(reg, GPIO0_IRQSTATUS1); /* clear irq */
745 /* RMII mode */
746 printf("ETH0, CPSW\n");
Amjad Ouled-Ameur4d797722021-10-29 16:08:17 +0200747 eth0_is_mii = false;
Roger Quadrosbcb4ee82016-08-24 15:35:50 +0300748 } else {
749 /* MII mode */
750 printf("ETH0, PRU\n");
751 cdce913_data.pdiv3 = 4; /* 25MHz PHY clk */
752 }
753
754 reg = readl(GPIO1_IRQSTATUSRAW) & BIT(26);
755 if (reg) {
756 writel(reg, GPIO1_IRQSTATUS1); /* clear irq */
757 /* RMII mode */
758 printf("ETH1, CPSW\n");
759 gpio_set_value(GPIO_MUX_MII_CTRL, 1);
Amjad Ouled-Ameur4d797722021-10-29 16:08:17 +0200760 eth1_is_mii = false;
Roger Quadrosbcb4ee82016-08-24 15:35:50 +0300761 } else {
762 /* MII mode */
763 printf("ETH1, PRU\n");
764 cdce913_data.pdiv2 = 4; /* 25MHz PHY clk */
765 }
766
Amjad Ouled-Ameur4d797722021-10-29 16:08:17 +0200767 if (eth0_is_mii != eth1_is_mii) {
768 printf("Unsupported Ethernet port configuration\n");
769 printf("Both ports must be set as RMII or MII\n");
770 hang();
771 }
772
773 prueth_is_mii = eth0_is_mii;
774
Roger Quadrosbcb4ee82016-08-24 15:35:50 +0300775 /* disable rising edge IRQs */
776 reg = readl(GPIO0_RISINGDETECT) & ~BIT(11);
777 writel(reg, GPIO0_RISINGDETECT);
778 reg = readl(GPIO1_RISINGDETECT) & ~BIT(26);
779 writel(reg, GPIO1_RISINGDETECT);
Lokesh Vutla0d144f52016-05-16 11:47:26 +0530780
781 rv = setup_clock_synthesizer(&cdce913_data);
782 if (rv) {
783 printf("Clock synthesizer setup failed %d\n", rv);
784 return rv;
785 }
Roger Quadrosbcb4ee82016-08-24 15:35:50 +0300786
787 /* reset PHYs */
788 gpio_set_value(GPIO_PHY_RESET, 0);
789 udelay(2); /* PHY datasheet states 1uS min. */
790 gpio_set_value(GPIO_PHY_RESET, 1);
Lokesh Vutla0d144f52016-05-16 11:47:26 +0530791 }
792#endif
793
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000794 return 0;
795}
796
Tom Rini40271852012-10-24 07:28:17 +0000797#ifdef CONFIG_BOARD_LATE_INIT
798int board_late_init(void)
799{
Tero Kristo67f79e72019-09-27 19:14:29 +0300800 struct udevice *dev;
Roger Quadros7c9d3782016-08-24 15:35:51 +0300801#if !defined(CONFIG_SPL_BUILD)
802 uint8_t mac_addr[6];
803 uint32_t mac_hi, mac_lo;
804#endif
805
Tom Rini40271852012-10-24 07:28:17 +0000806#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
Nishanth Menon2afa70d2016-02-24 12:30:55 -0600807 char *name = NULL;
Tom Rini4021fd92013-07-18 15:13:01 -0400808
robertcnelson@gmail.comc5d7d222017-03-30 14:29:52 -0500809 if (board_is_bone_lt()) {
810 /* BeagleBoard.org BeagleBone Black Wireless: */
811 if (!strncmp(board_ti_get_rev(), "BWA", 3)) {
812 name = "BBBW";
813 }
robertcnelson@gmail.comb55cd7a2017-03-30 14:29:53 -0500814 /* SeeedStudio BeagleBone Green Wireless */
815 if (!strncmp(board_ti_get_rev(), "GW1", 3)) {
816 name = "BBGW";
817 }
robertcnelson@gmail.com89ef1d62017-03-30 14:29:54 -0500818 /* BeagleBoard.org BeagleBone Blue */
819 if (!strncmp(board_ti_get_rev(), "BLA", 3)) {
820 name = "BBBL";
821 }
robertcnelson@gmail.comc5d7d222017-03-30 14:29:52 -0500822 }
823
Nishanth Menon2afa70d2016-02-24 12:30:55 -0600824 if (board_is_bbg1())
825 name = "BBG1";
Paul Barker10a59442022-04-11 15:42:00 +0000826 if (board_is_bben()) {
827 char subtype_id = board_ti_get_config()[1];
828
Paul Barker726ae6e2022-04-11 15:42:01 +0000829 switch (subtype_id) {
830 case 'L':
Paul Barker10a59442022-04-11 15:42:00 +0000831 name = "BBELITE";
Paul Barker726ae6e2022-04-11 15:42:01 +0000832 break;
833 case 'I':
834 name = "BBE_EX_WIFI";
835 break;
836 default:
Paul Barker10a59442022-04-11 15:42:00 +0000837 name = "BBEN";
Paul Barker726ae6e2022-04-11 15:42:01 +0000838 }
Paul Barker10a59442022-04-11 15:42:00 +0000839 }
Nishanth Menon2afa70d2016-02-24 12:30:55 -0600840 set_board_info_env(name);
Lokesh Vutla1eb0f542016-11-29 11:58:03 +0530841
842 /*
843 * Default FIT boot on HS devices. Non FIT images are not allowed
844 * on HS devices.
845 */
846 if (get_device_type() == HS_DEVICE)
Simon Glass6a38e412017-08-03 12:22:09 -0600847 env_set("boot_fit", "1");
Tom Rini40271852012-10-24 07:28:17 +0000848#endif
849
Roger Quadros7c9d3782016-08-24 15:35:51 +0300850#if !defined(CONFIG_SPL_BUILD)
851 /* try reading mac address from efuse */
852 mac_lo = readl(&cdev->macid0l);
853 mac_hi = readl(&cdev->macid0h);
854 mac_addr[0] = mac_hi & 0xFF;
855 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
856 mac_addr[2] = (mac_hi & 0xFF0000) >> 16;
857 mac_addr[3] = (mac_hi & 0xFF000000) >> 24;
858 mac_addr[4] = mac_lo & 0xFF;
859 mac_addr[5] = (mac_lo & 0xFF00) >> 8;
860
Simon Glass64b723f2017-08-03 12:22:12 -0600861 if (!env_get("ethaddr")) {
Roger Quadros7c9d3782016-08-24 15:35:51 +0300862 printf("<ethaddr> not set. Validating first E-fuse MAC\n");
863
864 if (is_valid_ethaddr(mac_addr))
Simon Glass8551d552017-08-03 12:22:11 -0600865 eth_env_set_enetaddr("ethaddr", mac_addr);
Roger Quadros7c9d3782016-08-24 15:35:51 +0300866 }
867
868 mac_lo = readl(&cdev->macid1l);
869 mac_hi = readl(&cdev->macid1h);
870 mac_addr[0] = mac_hi & 0xFF;
871 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
872 mac_addr[2] = (mac_hi & 0xFF0000) >> 16;
873 mac_addr[3] = (mac_hi & 0xFF000000) >> 24;
874 mac_addr[4] = mac_lo & 0xFF;
875 mac_addr[5] = (mac_lo & 0xFF00) >> 8;
876
Simon Glass64b723f2017-08-03 12:22:12 -0600877 if (!env_get("eth1addr")) {
Roger Quadros7c9d3782016-08-24 15:35:51 +0300878 if (is_valid_ethaddr(mac_addr))
Simon Glass8551d552017-08-03 12:22:11 -0600879 eth_env_set_enetaddr("eth1addr", mac_addr);
Roger Quadros7c9d3782016-08-24 15:35:51 +0300880 }
Amjad Ouled-Ameur4d797722021-10-29 16:08:17 +0200881
882 env_set("ice_mii", prueth_is_mii ? "mii" : "rmii");
Roger Quadros7c9d3782016-08-24 15:35:51 +0300883#endif
884
Sam Protsenkoa31ca622018-02-28 00:26:15 +0200885 if (!env_get("serial#")) {
886 char *board_serial = env_get("board_serial");
887 char *ethaddr = env_get("ethaddr");
888
889 if (!board_serial || !strncmp(board_serial, "unknown", 7))
890 env_set("serial#", ethaddr);
891 else
892 env_set("serial#", board_serial);
893 }
894
Tero Kristo67f79e72019-09-27 19:14:29 +0300895 /* Just probe the potentially supported cdce913 device */
Dario Binacchic2de9d42020-12-30 00:16:32 +0100896 uclass_get_device_by_name(UCLASS_CLK, "cdce913@65", &dev);
Tero Kristo67f79e72019-09-27 19:14:29 +0300897
Tom Rini40271852012-10-24 07:28:17 +0000898 return 0;
899}
900#endif
901
Simon Glass71fa5b42020-12-03 16:55:18 -0700902/* CPSW plat */
Corentin LABBE58cbef52022-06-14 08:44:07 +0000903#if CONFIG_IS_ENABLED(NET) && !CONFIG_IS_ENABLED(OF_CONTROL)
Faiz Abbas27866262019-03-18 13:54:37 +0530904struct cpsw_slave_data slave_data[] = {
905 {
906 .slave_reg_ofs = CPSW_SLAVE0_OFFSET,
907 .sliver_reg_ofs = CPSW_SLIVER0_OFFSET,
908 .phy_addr = 0,
909 },
910 {
911 .slave_reg_ofs = CPSW_SLAVE1_OFFSET,
912 .sliver_reg_ofs = CPSW_SLIVER1_OFFSET,
913 .phy_addr = 1,
914 },
915};
916
917struct cpsw_platform_data am335_eth_data = {
918 .cpsw_base = CPSW_BASE,
919 .version = CPSW_CTRL_VERSION_2,
920 .bd_ram_ofs = CPSW_BD_OFFSET,
921 .ale_reg_ofs = CPSW_ALE_OFFSET,
922 .cpdma_reg_ofs = CPSW_CPDMA_OFFSET,
923 .mdio_div = CPSW_MDIO_DIV,
924 .host_port_reg_ofs = CPSW_HOST_PORT_OFFSET,
925 .channels = 8,
926 .slaves = 2,
927 .slave_data = slave_data,
928 .ale_entries = 1024,
Faiz Abbas27866262019-03-18 13:54:37 +0530929 .mac_control = 0x20,
930 .active_slave = 0,
931 .mdio_base = 0x4a101000,
932 .gmii_sel = 0x44e10650,
933 .phy_sel_compat = "ti,am3352-cpsw-phy-sel",
934 .syscon_addr = 0x44e10630,
935 .macid_sel_compat = "cpsw,am33xx",
936};
937
938struct eth_pdata cpsw_pdata = {
939 .iobase = 0x4a100000,
940 .phy_interface = 0,
941 .priv_pdata = &am335_eth_data,
942};
943
Simon Glass1d8364a2020-12-28 20:34:54 -0700944U_BOOT_DRVINFO(am335x_eth) = {
Faiz Abbas27866262019-03-18 13:54:37 +0530945 .name = "eth_cpsw",
Simon Glass71fa5b42020-12-03 16:55:18 -0700946 .plat = &cpsw_pdata,
Faiz Abbas27866262019-03-18 13:54:37 +0530947};
948#endif
949
Lokesh Vutla89b9f302016-05-16 11:24:24 +0530950#ifdef CONFIG_SPL_LOAD_FIT
951int board_fit_config_name_match(const char *name)
952{
953 if (board_is_gp_evm() && !strcmp(name, "am335x-evm"))
954 return 0;
955 else if (board_is_bone() && !strcmp(name, "am335x-bone"))
956 return 0;
957 else if (board_is_bone_lt() && !strcmp(name, "am335x-boneblack"))
958 return 0;
Jason Kridnerb56b5b32018-03-07 05:40:41 -0500959 else if (board_is_pb() && !strcmp(name, "am335x-pocketbeagle"))
960 return 0;
Lokesh Vutla5a954ba2016-05-16 11:24:28 +0530961 else if (board_is_evm_sk() && !strcmp(name, "am335x-evmsk"))
962 return 0;
Lokesh Vutla1edfcaf2016-05-16 11:24:29 +0530963 else if (board_is_bbg1() && !strcmp(name, "am335x-bonegreen"))
964 return 0;
Lokesh Vutla7ecf1962016-05-16 11:47:28 +0530965 else if (board_is_icev2() && !strcmp(name, "am335x-icev2"))
966 return 0;
Paul Barker1977f3e2022-07-08 10:25:46 +0100967 else if (board_is_bben()) {
968 char subtype_id = board_ti_get_config()[1];
969
970 if (subtype_id == 'L') {
971 if (!strcmp(name, "am335x-sancloud-bbe-lite"))
972 return 0;
973 } else if (subtype_id == 'I') {
974 if (!strcmp(name, "am335x-sancloud-bbe-extended-wifi"))
975 return 0;
976 } else if (!strcmp(name, "am335x-sancloud-bbe")) {
977 return 0;
978 }
979 }
980 return -1;
Lokesh Vutla89b9f302016-05-16 11:24:24 +0530981}
982#endif
Andrew F. Davisbd249152016-08-30 14:06:24 -0500983
Lokesh Vutla2fe7c792017-04-26 13:37:08 +0530984#if !CONFIG_IS_ENABLED(OF_CONTROL)
Simon Glassb75b15b2020-12-03 16:55:23 -0700985static const struct omap_hsmmc_plat am335x_mmc0_plat = {
Lokesh Vutla2fe7c792017-04-26 13:37:08 +0530986 .base_addr = (struct hsmmc *)OMAP_HSMMC1_BASE,
987 .cfg.host_caps = MMC_MODE_HS_52MHz | MMC_MODE_HS | MMC_MODE_4BIT,
988 .cfg.f_min = 400000,
989 .cfg.f_max = 52000000,
990 .cfg.voltages = MMC_VDD_32_33 | MMC_VDD_33_34 | MMC_VDD_165_195,
991 .cfg.b_max = CONFIG_SYS_MMC_MAX_BLK_COUNT,
992};
993
Simon Glass1d8364a2020-12-28 20:34:54 -0700994U_BOOT_DRVINFO(am335x_mmc0) = {
Lokesh Vutla2fe7c792017-04-26 13:37:08 +0530995 .name = "omap_hsmmc",
Simon Glassb75b15b2020-12-03 16:55:23 -0700996 .plat = &am335x_mmc0_plat,
Lokesh Vutla2fe7c792017-04-26 13:37:08 +0530997};
998
Simon Glassb75b15b2020-12-03 16:55:23 -0700999static const struct omap_hsmmc_plat am335x_mmc1_plat = {
Lokesh Vutla2fe7c792017-04-26 13:37:08 +05301000 .base_addr = (struct hsmmc *)OMAP_HSMMC2_BASE,
1001 .cfg.host_caps = MMC_MODE_HS_52MHz | MMC_MODE_HS | MMC_MODE_8BIT,
1002 .cfg.f_min = 400000,
1003 .cfg.f_max = 52000000,
1004 .cfg.voltages = MMC_VDD_32_33 | MMC_VDD_33_34 | MMC_VDD_165_195,
1005 .cfg.b_max = CONFIG_SYS_MMC_MAX_BLK_COUNT,
1006};
1007
Simon Glass1d8364a2020-12-28 20:34:54 -07001008U_BOOT_DRVINFO(am335x_mmc1) = {
Lokesh Vutla2fe7c792017-04-26 13:37:08 +05301009 .name = "omap_hsmmc",
Simon Glassb75b15b2020-12-03 16:55:23 -07001010 .plat = &am335x_mmc1_plat,
Lokesh Vutla2fe7c792017-04-26 13:37:08 +05301011};
1012#endif