blob: bc1657e88fd7b6ee625709e7ccf35d0e8625d304 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Peter Korsgaarde3634262012-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 Korsgaarde3634262012-10-18 01:21:09 +00008 */
9
10#include <common.h>
Lokesh Vutla4548bc82017-04-26 13:37:08 +053011#include <dm.h>
Simon Glass4bfd1f52019-08-01 09:46:43 -060012#include <env.h>
Peter Korsgaarde3634262012-10-18 01:21:09 +000013#include <errno.h>
Simon Glass4d72caa2020-05-10 11:40:01 -060014#include <image.h>
Simon Glass52559322019-11-14 12:57:46 -070015#include <init.h>
Simon Glass336d4612020-02-03 07:36:16 -070016#include <malloc.h>
Simon Glass90526e92020-05-10 11:39:56 -060017#include <net.h>
Peter Korsgaarde3634262012-10-18 01:21:09 +000018#include <spl.h>
Lokesh Vutla3d163892016-05-16 11:47:29 +053019#include <serial.h>
Peter Korsgaarde3634262012-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 Vutla97f3a172016-05-16 11:47:26 +053025#include <asm/arch/clk_synthesizer.h>
Peter Korsgaarde3634262012-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 Kipiszcd8845d2013-07-18 15:13:03 -040029#include <asm/arch/mem.h>
Simon Glass401d1c42020-10-30 21:38:53 -060030#include <asm/global_data.h>
Peter Korsgaarde3634262012-10-18 01:21:09 +000031#include <asm/io.h>
32#include <asm/emif.h>
33#include <asm/gpio.h>
Semen Protsenko00bbe962017-06-02 18:00:00 +030034#include <asm/omap_common.h>
Andrew F. Davisb0a4eea2016-08-30 14:06:24 -050035#include <asm/omap_sec_common.h>
Lokesh Vutla4548bc82017-04-26 13:37:08 +053036#include <asm/omap_mmc.h>
Peter Korsgaarde3634262012-10-18 01:21:09 +000037#include <i2c.h>
38#include <miiphy.h>
39#include <cpsw.h>
Simon Glasscd93d622020-05-10 11:40:13 -060040#include <linux/bitops.h>
Simon Glassc05ed002020-05-10 11:40:11 -060041#include <linux/delay.h>
Tom Rini97210272013-08-30 16:28:46 -040042#include <power/tps65217.h>
43#include <power/tps65910.h>
Simon Glassf3998fd2019-08-02 09:44:25 -060044#include <env_internal.h>
Tom Rini68439182013-10-01 12:32:04 -040045#include <watchdog.h>
Nishanth Menon770e68c2016-02-24 12:30:55 -060046#include "../common/board_detect.h"
Peter Korsgaarde3634262012-10-18 01:21:09 +000047#include "board.h"
48
49DECLARE_GLOBAL_DATA_PTR;
50
Peter Korsgaarde3634262012-10-18 01:21:09 +000051/* GPIO that controls power to DDR on EVM-SK */
Lokesh Vutla97f3a172016-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 Quadrose607ec92016-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 Korsgaarde3634262012-10-18 01:21:09 +000061
62static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
63
Roger Quadrose607ec92016-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 Korsgaarde3634262012-10-18 01:21:09 +000073/*
74 * Read header information from EEPROM into global structure.
75 */
Lokesh Vutla140d76a2016-10-14 10:35:25 +053076#ifdef CONFIG_TI_I2C_BOARD_DETECT
77void do_board_detect(void)
Peter Korsgaarde3634262012-10-18 01:21:09 +000078{
Lokesh Vutla140d76a2016-10-14 10:35:25 +053079 enable_i2c0_pin_mux();
Igor Opaniuk2147a162021-02-09 13:52:45 +020080#if !CONFIG_IS_ENABLED(DM_I2C)
Lokesh Vutla140d76a2016-10-14 10:35:25 +053081 i2c_init(CONFIG_SYS_OMAP24_I2C_SPEED, CONFIG_SYS_OMAP24_I2C_SLAVE);
Jean-Jacques Hiblot15142442018-12-07 14:50:49 +010082#endif
Simon Glass64a144d2017-05-12 21:09:55 -060083 if (ti_i2c_eeprom_am_get(CONFIG_EEPROM_BUS_ADDRESS,
84 CONFIG_EEPROM_CHIP_ADDRESS))
Lokesh Vutla140d76a2016-10-14 10:35:25 +053085 printf("ti_i2c_eeprom_init failed\n");
Peter Korsgaarde3634262012-10-18 01:21:09 +000086}
Lokesh Vutla140d76a2016-10-14 10:35:25 +053087#endif
Peter Korsgaarde3634262012-10-18 01:21:09 +000088
Lokesh Vutla3d163892016-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 Rinid0e6d342014-04-09 08:25:57 -040099#ifndef CONFIG_SKIP_LOWLEVEL_INIT
Peter Korsgaardc00f69d2012-10-18 01:21:12 +0000100static const struct ddr_data ddr2_data = {
Tom Rinic4f80f52014-07-07 21:40:16 -0400101 .datardsratio0 = MT47H128M16RT25E_RD_DQS,
102 .datafwsratio0 = MT47H128M16RT25E_PHY_FIFO_WE,
103 .datawrsratio0 = MT47H128M16RT25E_PHY_WR_DATA,
Peter Korsgaardc00f69d2012-10-18 01:21:12 +0000104};
105
106static const struct cmd_control ddr2_cmd_ctrl_data = {
Peter Korsgaardc7d35be2012-10-18 01:21:13 +0000107 .cmd0csratio = MT47H128M16RT25E_RATIO,
Peter Korsgaardc00f69d2012-10-18 01:21:12 +0000108
Peter Korsgaardc7d35be2012-10-18 01:21:13 +0000109 .cmd1csratio = MT47H128M16RT25E_RATIO,
Peter Korsgaardc00f69d2012-10-18 01:21:12 +0000110
Peter Korsgaardc7d35be2012-10-18 01:21:13 +0000111 .cmd2csratio = MT47H128M16RT25E_RATIO,
Peter Korsgaardc00f69d2012-10-18 01:21:12 +0000112};
113
114static const struct emif_regs ddr2_emif_reg_data = {
Peter Korsgaardc7d35be2012-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 Korsgaardc00f69d2012-10-18 01:21:12 +0000121};
122
Jyri Sarha8c17cbd2016-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 Korsgaardc00f69d2012-10-18 01:21:12 +0000133static const struct ddr_data ddr3_data = {
Peter Korsgaardc7d35be2012-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 Korsgaardc00f69d2012-10-18 01:21:12 +0000138};
139
Tom Rinic7ba18a2013-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 Rinic7ba18a2013-03-21 04:30:02 +0000145};
146
Jeff Lance13526f72013-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 Lance13526f72013-01-14 05:32:20 +0000152};
153
Lokesh Vutlad8ff4fd2016-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 Korsgaardc00f69d2012-10-18 01:21:12 +0000161static const struct cmd_control ddr3_cmd_ctrl_data = {
Peter Korsgaardc7d35be2012-10-18 01:21:13 +0000162 .cmd0csratio = MT41J128MJT125_RATIO,
Peter Korsgaardc7d35be2012-10-18 01:21:13 +0000163 .cmd0iclkout = MT41J128MJT125_INVERT_CLKOUT,
Peter Korsgaardc00f69d2012-10-18 01:21:12 +0000164
Peter Korsgaardc7d35be2012-10-18 01:21:13 +0000165 .cmd1csratio = MT41J128MJT125_RATIO,
Peter Korsgaardc7d35be2012-10-18 01:21:13 +0000166 .cmd1iclkout = MT41J128MJT125_INVERT_CLKOUT,
Peter Korsgaardc00f69d2012-10-18 01:21:12 +0000167
Peter Korsgaardc7d35be2012-10-18 01:21:13 +0000168 .cmd2csratio = MT41J128MJT125_RATIO,
Peter Korsgaardc7d35be2012-10-18 01:21:13 +0000169 .cmd2iclkout = MT41J128MJT125_INVERT_CLKOUT,
Peter Korsgaardc00f69d2012-10-18 01:21:12 +0000170};
171
Tom Rinic7ba18a2013-03-21 04:30:02 +0000172static const struct cmd_control ddr3_beagleblack_cmd_ctrl_data = {
173 .cmd0csratio = MT41K256M16HA125E_RATIO,
Tom Rinic7ba18a2013-03-21 04:30:02 +0000174 .cmd0iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
175
176 .cmd1csratio = MT41K256M16HA125E_RATIO,
Tom Rinic7ba18a2013-03-21 04:30:02 +0000177 .cmd1iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
178
179 .cmd2csratio = MT41K256M16HA125E_RATIO,
Tom Rinic7ba18a2013-03-21 04:30:02 +0000180 .cmd2iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
181};
182
Jeff Lance13526f72013-01-14 05:32:20 +0000183static const struct cmd_control ddr3_evm_cmd_ctrl_data = {
184 .cmd0csratio = MT41J512M8RH125_RATIO,
Jeff Lance13526f72013-01-14 05:32:20 +0000185 .cmd0iclkout = MT41J512M8RH125_INVERT_CLKOUT,
186
187 .cmd1csratio = MT41J512M8RH125_RATIO,
Jeff Lance13526f72013-01-14 05:32:20 +0000188 .cmd1iclkout = MT41J512M8RH125_INVERT_CLKOUT,
189
190 .cmd2csratio = MT41J512M8RH125_RATIO,
Jeff Lance13526f72013-01-14 05:32:20 +0000191 .cmd2iclkout = MT41J512M8RH125_INVERT_CLKOUT,
192};
193
Lokesh Vutlad8ff4fd2016-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 Korsgaardc00f69d2012-10-18 01:21:12 +0000205static struct emif_regs ddr3_emif_reg_data = {
Peter Korsgaardc7d35be2012-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 Hiremath59dcf972013-03-14 21:11:16 +0000212 .emif_ddr_phy_ctlr_1 = MT41J128MJT125_EMIF_READ_LATENCY |
213 PHY_EN_DYN_PWRDN,
Peter Korsgaardc00f69d2012-10-18 01:21:12 +0000214};
Jeff Lance13526f72013-01-14 05:32:20 +0000215
Tom Rinic7ba18a2013-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 Sarha8c17cbd2016-12-09 12:29:13 +0200222 .ocp_config = EMIF_OCP_CONFIG_BEAGLEBONE_BLACK,
Tom Rinic7ba18a2013-03-21 04:30:02 +0000223 .zq_config = MT41K256M16HA125E_ZQ_CFG,
224 .emif_ddr_phy_ctlr_1 = MT41K256M16HA125E_EMIF_READ_LATENCY,
225};
226
Jeff Lance13526f72013-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 Sarha8c17cbd2016-12-09 12:29:13 +0200233 .ocp_config = EMIF_OCP_CONFIG_AM335X_EVM,
Jeff Lance13526f72013-01-14 05:32:20 +0000234 .zq_config = MT41J512M8RH125_ZQ_CFG,
Vaibhav Hiremath59dcf972013-03-14 21:11:16 +0000235 .emif_ddr_phy_ctlr_1 = MT41J512M8RH125_EMIF_READ_LATENCY |
236 PHY_EN_DYN_PWRDN,
Jeff Lance13526f72013-01-14 05:32:20 +0000237};
Peter Korsgaard12d7a472013-05-13 08:36:30 +0000238
Lokesh Vutlad8ff4fd2016-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 Korsgaard12d7a472013-05-13 08:36:30 +0000250#ifdef CONFIG_SPL_OS_BOOT
251int spl_start_uboot(void)
252{
Alex Kiernand4bb3b32018-04-19 04:32:53 +0000253#ifdef CONFIG_SPL_SERIAL_SUPPORT
Peter Korsgaard12d7a472013-05-13 08:36:30 +0000254 /* break into full u-boot on 'c' */
Tom Riniba9a6702014-03-28 12:03:38 -0400255 if (serial_tstc() && serial_getc() == 'c')
256 return 1;
Alex Kiernand4bb3b32018-04-19 04:32:53 +0000257#endif
Tom Riniba9a6702014-03-28 12:03:38 -0400258
259#ifdef CONFIG_SPL_ENV_SUPPORT
260 env_init();
Simon Glass310fb142017-08-03 12:22:07 -0600261 env_load();
Simon Glassbfebc8c2017-08-03 12:22:13 -0600262 if (env_get_yesno("boot_os") != 1)
Tom Riniba9a6702014-03-28 12:03:38 -0400263 return 1;
264#endif
265
266 return 0;
Peter Korsgaard12d7a472013-05-13 08:36:30 +0000267}
268#endif
269
Lokesh Vutla94d77fb2013-07-30 10:48:52 +0530270const struct dpll_params *get_dpll_ddr_params(void)
271{
Lokesh Vutlafbd62952017-05-05 12:59:10 +0530272 int ind = get_sys_clk_index();
273
Nishanth Menon770e68c2016-02-24 12:30:55 -0600274 if (board_is_evm_sk())
Lokesh Vutlafbd62952017-05-05 12:59:10 +0530275 return &dpll_ddr3_303MHz[ind];
Jason Kridnereff0c972018-03-07 05:40:41 -0500276 else if (board_is_pb() || board_is_bone_lt() || board_is_icev2())
Lokesh Vutlafbd62952017-05-05 12:59:10 +0530277 return &dpll_ddr3_400MHz[ind];
Nishanth Menon770e68c2016-02-24 12:30:55 -0600278 else if (board_is_evm_15_or_later())
Lokesh Vutlafbd62952017-05-05 12:59:10 +0530279 return &dpll_ddr3_303MHz[ind];
Lokesh Vutla94d77fb2013-07-30 10:48:52 +0530280 else
Lokesh Vutlafbd62952017-05-05 12:59:10 +0530281 return &dpll_ddr2_266MHz[ind];
282}
283
284static 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 Kridnereff0c972018-03-07 05:40:41 -0500307 if (board_is_pb() || board_is_bone_lt())
Lokesh Vutlafbd62952017-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];
Lokesh Vutla94d77fb2013-07-30 10:48:52 +0530326}
327
Lokesh Vutla06507982017-05-05 12:59:09 +0530328static void scale_vcores_bone(int freq)
329{
330 int usb_cur_lim, mpu_vdd;
331
332 /*
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;
338
Igor Opaniuk2147a162021-02-09 13:52:45 +0200339#if !CONFIG_IS_ENABLED(DM_I2C)
Lokesh Vutla06507982017-05-05 12:59:09 +0530340 if (i2c_probe(TPS65217_CHIP_PM))
341 return;
Jean-Jacques Hiblot15142442018-12-07 14:50:49 +0100342#else
343 if (power_tps65217_init(0))
344 return;
345#endif
346
Lokesh Vutla06507982017-05-05 12:59:09 +0530347
348 /*
349 * On Beaglebone White we need to ensure we have AC power
350 * before increasing the frequency.
351 */
Lokesh Vutlafbd62952017-05-05 12:59:10 +0530352 if (bone_not_connected_to_ac_power())
353 freq = MPUPLL_M_600;
Lokesh Vutla06507982017-05-05 12:59:09 +0530354
355 /*
356 * Override what we have detected since we know if we have
357 * a Beaglebone Black it supports 1GHz.
358 */
Jason Kridnereff0c972018-03-07 05:40:41 -0500359 if (board_is_pb() || board_is_bone_lt())
Lokesh Vutla06507982017-05-05 12:59:09 +0530360 freq = MPUPLL_M_1000;
361
Lokesh Vutla06507982017-05-05 12:59:09 +0530362 switch (freq) {
363 case MPUPLL_M_1000:
364 mpu_vdd = TPS65217_DCDC_VOLT_SEL_1325MV;
365 usb_cur_lim = TPS65217_USB_INPUT_CUR_LIMIT_1800MA;
366 break;
367 case MPUPLL_M_800:
368 mpu_vdd = TPS65217_DCDC_VOLT_SEL_1275MV;
Lokesh Vutla9f7923c2017-06-10 13:22:56 +0530369 usb_cur_lim = TPS65217_USB_INPUT_CUR_LIMIT_1300MA;
Lokesh Vutla06507982017-05-05 12:59:09 +0530370 break;
371 case MPUPLL_M_720:
372 mpu_vdd = TPS65217_DCDC_VOLT_SEL_1200MV;
Lokesh Vutla9f7923c2017-06-10 13:22:56 +0530373 usb_cur_lim = TPS65217_USB_INPUT_CUR_LIMIT_1300MA;
Lokesh Vutla06507982017-05-05 12:59:09 +0530374 break;
375 case MPUPLL_M_600:
376 case MPUPLL_M_500:
377 case MPUPLL_M_300:
Lokesh Vutla9f7923c2017-06-10 13:22:56 +0530378 default:
Lokesh Vutla06507982017-05-05 12:59:09 +0530379 mpu_vdd = TPS65217_DCDC_VOLT_SEL_1100MV;
380 usb_cur_lim = TPS65217_USB_INPUT_CUR_LIMIT_1300MA;
381 break;
382 }
383
384 if (tps65217_reg_write(TPS65217_PROT_LEVEL_NONE,
385 TPS65217_POWER_PATH,
386 usb_cur_lim,
387 TPS65217_USB_INPUT_CUR_LIMIT_MASK))
388 puts("tps65217_reg_write failure\n");
389
390 /* Set DCDC3 (CORE) voltage to 1.10V */
391 if (tps65217_voltage_update(TPS65217_DEFDCDC3,
392 TPS65217_DCDC_VOLT_SEL_1100MV)) {
393 puts("tps65217_voltage_update failure\n");
394 return;
395 }
396
397 /* Set DCDC2 (MPU) voltage */
398 if (tps65217_voltage_update(TPS65217_DEFDCDC2, mpu_vdd)) {
399 puts("tps65217_voltage_update failure\n");
400 return;
401 }
402
403 /*
404 * Set LDO3, LDO4 output voltage to 3.3V for Beaglebone.
405 * Set LDO3 to 1.8V and LDO4 to 3.3V for Beaglebone Black.
406 */
407 if (board_is_bone()) {
408 if (tps65217_reg_write(TPS65217_PROT_LEVEL_2,
409 TPS65217_DEFLS1,
410 TPS65217_LDO_VOLTAGE_OUT_3_3,
411 TPS65217_LDO_MASK))
412 puts("tps65217_reg_write failure\n");
413 } else {
414 if (tps65217_reg_write(TPS65217_PROT_LEVEL_2,
415 TPS65217_DEFLS1,
416 TPS65217_LDO_VOLTAGE_OUT_1_8,
417 TPS65217_LDO_MASK))
418 puts("tps65217_reg_write failure\n");
419 }
420
421 if (tps65217_reg_write(TPS65217_PROT_LEVEL_2,
422 TPS65217_DEFLS2,
423 TPS65217_LDO_VOLTAGE_OUT_3_3,
424 TPS65217_LDO_MASK))
425 puts("tps65217_reg_write failure\n");
426}
427
428void scale_vcores_generic(int freq)
429{
430 int sil_rev, mpu_vdd;
431
432 /*
433 * The GP EVM, IDK and EVM SK use a TPS65910 PMIC. For all
434 * MPU frequencies we support we use a CORE voltage of
435 * 1.10V. For MPU voltage we need to switch based on
436 * the frequency we are running at.
437 */
Igor Opaniuk2147a162021-02-09 13:52:45 +0200438#if !CONFIG_IS_ENABLED(DM_I2C)
Lokesh Vutla06507982017-05-05 12:59:09 +0530439 if (i2c_probe(TPS65910_CTRL_I2C_ADDR))
440 return;
Jean-Jacques Hiblot15142442018-12-07 14:50:49 +0100441#else
442 if (power_tps65910_init(0))
443 return;
444#endif
Lokesh Vutla06507982017-05-05 12:59:09 +0530445 /*
446 * Depending on MPU clock and PG we will need a different
447 * VDD to drive at that speed.
448 */
449 sil_rev = readl(&cdev->deviceid) >> 28;
450 mpu_vdd = am335x_get_tps65910_mpu_vdd(sil_rev, freq);
451
452 /* Tell the TPS65910 to use i2c */
453 tps65910_set_i2c_control();
454
455 /* First update MPU voltage. */
456 if (tps65910_voltage_update(MPU, mpu_vdd))
457 return;
458
459 /* Second, update the CORE voltage. */
460 if (tps65910_voltage_update(CORE, TPS65910_OP_REG_SEL_1_1_0))
461 return;
462
463}
464
465void gpi2c_init(void)
466{
467 /* When needed to be invoked prior to BSS initialization */
468 static bool first_time = true;
469
470 if (first_time) {
471 enable_i2c0_pin_mux();
Igor Opaniuk2147a162021-02-09 13:52:45 +0200472#if !CONFIG_IS_ENABLED(DM_I2C)
Lokesh Vutla06507982017-05-05 12:59:09 +0530473 i2c_init(CONFIG_SYS_OMAP24_I2C_SPEED,
474 CONFIG_SYS_OMAP24_I2C_SLAVE);
Jean-Jacques Hiblot15142442018-12-07 14:50:49 +0100475#endif
Lokesh Vutla06507982017-05-05 12:59:09 +0530476 first_time = false;
477 }
478}
479
480void scale_vcores(void)
481{
482 int freq;
483
484 gpi2c_init();
485 freq = am335x_get_efuse_mpu_max_freq(cdev);
486
Lokesh Vutla9f7923c2017-06-10 13:22:56 +0530487 if (board_is_beaglebonex())
Lokesh Vutla06507982017-05-05 12:59:09 +0530488 scale_vcores_bone(freq);
489 else
490 scale_vcores_generic(freq);
491}
492
Heiko Schocher06604812013-07-30 10:48:54 +0530493void set_uart_mux_conf(void)
Peter Korsgaarde3634262012-10-18 01:21:09 +0000494{
Tom Rini1286b7f2014-08-01 09:53:24 -0400495#if CONFIG_CONS_INDEX == 1
Peter Korsgaarde3634262012-10-18 01:21:09 +0000496 enable_uart0_pin_mux();
Tom Rini1286b7f2014-08-01 09:53:24 -0400497#elif CONFIG_CONS_INDEX == 2
Andrew Bradford6422b702012-10-25 08:21:30 -0400498 enable_uart1_pin_mux();
Tom Rini1286b7f2014-08-01 09:53:24 -0400499#elif CONFIG_CONS_INDEX == 3
Andrew Bradford6422b702012-10-25 08:21:30 -0400500 enable_uart2_pin_mux();
Tom Rini1286b7f2014-08-01 09:53:24 -0400501#elif CONFIG_CONS_INDEX == 4
Andrew Bradford6422b702012-10-25 08:21:30 -0400502 enable_uart3_pin_mux();
Tom Rini1286b7f2014-08-01 09:53:24 -0400503#elif CONFIG_CONS_INDEX == 5
Andrew Bradford6422b702012-10-25 08:21:30 -0400504 enable_uart4_pin_mux();
Tom Rini1286b7f2014-08-01 09:53:24 -0400505#elif CONFIG_CONS_INDEX == 6
Andrew Bradford6422b702012-10-25 08:21:30 -0400506 enable_uart5_pin_mux();
Tom Rini1286b7f2014-08-01 09:53:24 -0400507#endif
Heiko Schocher06604812013-07-30 10:48:54 +0530508}
Peter Korsgaarde3634262012-10-18 01:21:09 +0000509
Heiko Schocher06604812013-07-30 10:48:54 +0530510void set_mux_conf_regs(void)
511{
Nishanth Menon770e68c2016-02-24 12:30:55 -0600512 enable_board_pin_mux();
Heiko Schocher06604812013-07-30 10:48:54 +0530513}
514
Lokesh Vutla965de8b2013-12-10 15:02:21 +0530515const struct ctrl_ioregs ioregs_evmsk = {
516 .cm0ioctl = MT41J128MJT125_IOCTRL_VALUE,
517 .cm1ioctl = MT41J128MJT125_IOCTRL_VALUE,
518 .cm2ioctl = MT41J128MJT125_IOCTRL_VALUE,
519 .dt0ioctl = MT41J128MJT125_IOCTRL_VALUE,
520 .dt1ioctl = MT41J128MJT125_IOCTRL_VALUE,
521};
522
523const struct ctrl_ioregs ioregs_bonelt = {
524 .cm0ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
525 .cm1ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
526 .cm2ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
527 .dt0ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
528 .dt1ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
529};
530
531const struct ctrl_ioregs ioregs_evm15 = {
532 .cm0ioctl = MT41J512M8RH125_IOCTRL_VALUE,
533 .cm1ioctl = MT41J512M8RH125_IOCTRL_VALUE,
534 .cm2ioctl = MT41J512M8RH125_IOCTRL_VALUE,
535 .dt0ioctl = MT41J512M8RH125_IOCTRL_VALUE,
536 .dt1ioctl = MT41J512M8RH125_IOCTRL_VALUE,
537};
538
539const struct ctrl_ioregs ioregs = {
540 .cm0ioctl = MT47H128M16RT25E_IOCTRL_VALUE,
541 .cm1ioctl = MT47H128M16RT25E_IOCTRL_VALUE,
542 .cm2ioctl = MT47H128M16RT25E_IOCTRL_VALUE,
543 .dt0ioctl = MT47H128M16RT25E_IOCTRL_VALUE,
544 .dt1ioctl = MT47H128M16RT25E_IOCTRL_VALUE,
545};
546
Heiko Schocher06604812013-07-30 10:48:54 +0530547void sdram_init(void)
548{
Nishanth Menon770e68c2016-02-24 12:30:55 -0600549 if (board_is_evm_sk()) {
Peter Korsgaarde3634262012-10-18 01:21:09 +0000550 /*
551 * EVM SK 1.2A and later use gpio0_7 to enable DDR3.
552 * This is safe enough to do on older revs.
553 */
554 gpio_request(GPIO_DDR_VTT_EN, "ddr_vtt_en");
555 gpio_direction_output(GPIO_DDR_VTT_EN, 1);
556 }
557
Lokesh Vutlad8ff4fd2016-05-16 11:47:24 +0530558 if (board_is_icev2()) {
559 gpio_request(ICE_GPIO_DDR_VTT_EN, "ddr_vtt_en");
560 gpio_direction_output(ICE_GPIO_DDR_VTT_EN, 1);
561 }
562
Nishanth Menon770e68c2016-02-24 12:30:55 -0600563 if (board_is_evm_sk())
Lokesh Vutla965de8b2013-12-10 15:02:21 +0530564 config_ddr(303, &ioregs_evmsk, &ddr3_data,
Matt Porter3ba65f92013-03-15 10:07:03 +0000565 &ddr3_cmd_ctrl_data, &ddr3_emif_reg_data, 0);
Jason Kridnereff0c972018-03-07 05:40:41 -0500566 else if (board_is_pb() || board_is_bone_lt())
Lokesh Vutla965de8b2013-12-10 15:02:21 +0530567 config_ddr(400, &ioregs_bonelt,
Tom Rinic7ba18a2013-03-21 04:30:02 +0000568 &ddr3_beagleblack_data,
569 &ddr3_beagleblack_cmd_ctrl_data,
570 &ddr3_beagleblack_emif_reg_data, 0);
Nishanth Menon770e68c2016-02-24 12:30:55 -0600571 else if (board_is_evm_15_or_later())
Lokesh Vutla965de8b2013-12-10 15:02:21 +0530572 config_ddr(303, &ioregs_evm15, &ddr3_evm_data,
Matt Porter3ba65f92013-03-15 10:07:03 +0000573 &ddr3_evm_cmd_ctrl_data, &ddr3_evm_emif_reg_data, 0);
Lokesh Vutlad8ff4fd2016-05-16 11:47:24 +0530574 else if (board_is_icev2())
575 config_ddr(400, &ioregs_evmsk, &ddr3_icev2_data,
576 &ddr3_icev2_cmd_ctrl_data, &ddr3_icev2_emif_reg_data,
577 0);
Jyri Sarha8c17cbd2016-12-09 12:29:13 +0200578 else if (board_is_gp_evm())
579 config_ddr(266, &ioregs, &ddr2_data,
580 &ddr2_cmd_ctrl_data, &ddr2_evm_emif_reg_data, 0);
Peter Korsgaardc00f69d2012-10-18 01:21:12 +0000581 else
Lokesh Vutla965de8b2013-12-10 15:02:21 +0530582 config_ddr(266, &ioregs, &ddr2_data,
Matt Porter3ba65f92013-03-15 10:07:03 +0000583 &ddr2_cmd_ctrl_data, &ddr2_emif_reg_data, 0);
Peter Korsgaarde3634262012-10-18 01:21:09 +0000584}
Heiko Schocher06604812013-07-30 10:48:54 +0530585#endif
Peter Korsgaarde3634262012-10-18 01:21:09 +0000586
Alex Kiernan8cf2f362018-04-01 09:22:37 +0000587#if defined(CONFIG_CLOCK_SYNTHESIZER) && (!defined(CONFIG_SPL_BUILD) || \
588 (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD)))
Roger Quadrose607ec92016-08-24 15:35:50 +0300589static void request_and_set_gpio(int gpio, char *name, int val)
Lokesh Vutla97f3a172016-05-16 11:47:26 +0530590{
591 int ret;
592
593 ret = gpio_request(gpio, name);
594 if (ret < 0) {
595 printf("%s: Unable to request %s\n", __func__, name);
596 return;
597 }
598
599 ret = gpio_direction_output(gpio, 0);
600 if (ret < 0) {
601 printf("%s: Unable to set %s as output\n", __func__, name);
602 goto err_free_gpio;
603 }
604
Roger Quadrose607ec92016-08-24 15:35:50 +0300605 gpio_set_value(gpio, val);
Lokesh Vutla97f3a172016-05-16 11:47:26 +0530606
607 return;
608
609err_free_gpio:
610 gpio_free(gpio);
611}
612
Roger Quadrose607ec92016-08-24 15:35:50 +0300613#define REQUEST_AND_SET_GPIO(N) request_and_set_gpio(N, #N, 1);
614#define REQUEST_AND_CLR_GPIO(N) request_and_set_gpio(N, #N, 0);
Lokesh Vutla97f3a172016-05-16 11:47:26 +0530615
616/**
617 * RMII mode on ICEv2 board needs 50MHz clock. Given the clock
618 * synthesizer With a capacitor of 18pF, and 25MHz input clock cycle
619 * PLL1 gives an output of 100MHz. So, configuring the div2/3 as 2 to
620 * give 50MHz output for Eth0 and 1.
621 */
622static struct clk_synth cdce913_data = {
623 .id = 0x81,
624 .capacitor = 0x90,
625 .mux = 0x6d,
626 .pdiv2 = 0x2,
627 .pdiv3 = 0x2,
628};
629#endif
630
Sekhar Nori20c37fb2018-08-23 17:11:30 +0530631#if defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_CONTROL) && \
632 defined(CONFIG_DM_ETH) && defined(CONFIG_DRIVER_TI_CPSW)
633
634#define MAX_CPSW_SLAVES 2
635
636/* At the moment, we do not want to stop booting for any failures here */
Masahiro Yamadab75d8dc2020-06-26 15:13:33 +0900637int ft_board_setup(void *fdt, struct bd_info *bd)
Sekhar Nori20c37fb2018-08-23 17:11:30 +0530638{
639 const char *slave_path, *enet_name;
640 int enetnode, slavenode, phynode;
641 struct udevice *ethdev;
642 char alias[16];
643 u32 phy_id[2];
644 int phy_addr;
645 int i, ret;
646
647 /* phy address fixup needed only on beagle bone family */
648 if (!board_is_beaglebonex())
649 goto done;
650
651 for (i = 0; i < MAX_CPSW_SLAVES; i++) {
652 sprintf(alias, "ethernet%d", i);
653
654 slave_path = fdt_get_alias(fdt, alias);
655 if (!slave_path)
656 continue;
657
658 slavenode = fdt_path_offset(fdt, slave_path);
659 if (slavenode < 0)
660 continue;
661
662 enetnode = fdt_parent_offset(fdt, slavenode);
663 enet_name = fdt_get_name(fdt, enetnode, NULL);
664
665 ethdev = eth_get_dev_by_name(enet_name);
666 if (!ethdev)
667 continue;
668
669 phy_addr = cpsw_get_slave_phy_addr(ethdev, i);
670
671 /* check for phy_id as well as phy-handle properties */
672 ret = fdtdec_get_int_array_count(fdt, slavenode, "phy_id",
673 phy_id, 2);
674 if (ret == 2) {
675 if (phy_id[1] != phy_addr) {
676 printf("fixing up phy_id for %s, old: %d, new: %d\n",
677 alias, phy_id[1], phy_addr);
678
679 phy_id[0] = cpu_to_fdt32(phy_id[0]);
680 phy_id[1] = cpu_to_fdt32(phy_addr);
681 do_fixup_by_path(fdt, slave_path, "phy_id",
682 phy_id, sizeof(phy_id), 0);
683 }
684 } else {
685 phynode = fdtdec_lookup_phandle(fdt, slavenode,
686 "phy-handle");
687 if (phynode < 0)
688 continue;
689
690 ret = fdtdec_get_int(fdt, phynode, "reg", -ENOENT);
691 if (ret < 0)
692 continue;
693
694 if (ret != phy_addr) {
695 printf("fixing up phy-handle for %s, old: %d, new: %d\n",
696 alias, ret, phy_addr);
697
698 fdt_setprop_u32(fdt, phynode, "reg",
699 cpu_to_fdt32(phy_addr));
700 }
701 }
702 }
703
704done:
705 return 0;
706}
707#endif
708
Peter Korsgaarde3634262012-10-18 01:21:09 +0000709/*
710 * Basic board specific setup. Pinmux has been handled already.
711 */
712int board_init(void)
713{
Tom Rini68439182013-10-01 12:32:04 -0400714#if defined(CONFIG_HW_WATCHDOG)
715 hw_watchdog_init();
716#endif
717
Tom Rini73feefd2013-08-09 11:22:13 -0400718 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
Miquel Raynal88718be2019-10-03 19:50:03 +0200719#if defined(CONFIG_NOR) || defined(CONFIG_MTD_RAW_NAND)
Ilya Yanok98b5c262012-11-06 13:06:31 +0000720 gpmc_init();
Steve Kipiszcd8845d2013-07-18 15:13:03 -0400721#endif
Lokesh Vutla97f3a172016-05-16 11:47:26 +0530722
Alex Kiernan8cf2f362018-04-01 09:22:37 +0000723#if defined(CONFIG_CLOCK_SYNTHESIZER) && (!defined(CONFIG_SPL_BUILD) || \
724 (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD)))
Lokesh Vutla97f3a172016-05-16 11:47:26 +0530725 if (board_is_icev2()) {
Roger Quadrose607ec92016-08-24 15:35:50 +0300726 int rv;
727 u32 reg;
728
Lokesh Vutla97f3a172016-05-16 11:47:26 +0530729 REQUEST_AND_SET_GPIO(GPIO_PR1_MII_CTRL);
Roger Quadrose607ec92016-08-24 15:35:50 +0300730 /* Make J19 status available on GPIO1_26 */
731 REQUEST_AND_CLR_GPIO(GPIO_MUX_MII_CTRL);
732
Lokesh Vutla97f3a172016-05-16 11:47:26 +0530733 REQUEST_AND_SET_GPIO(GPIO_FET_SWITCH_CTRL);
Roger Quadrose607ec92016-08-24 15:35:50 +0300734 /*
735 * Both ports can be set as RMII-CPSW or MII-PRU-ETH using
736 * jumpers near the port. Read the jumper value and set
737 * the pinmux, external mux and PHY clock accordingly.
738 * As jumper line is overridden by PHY RX_DV pin immediately
739 * after bootstrap (power-up/reset), we need to sample
740 * it during PHY reset using GPIO rising edge detection.
741 */
Lokesh Vutla97f3a172016-05-16 11:47:26 +0530742 REQUEST_AND_SET_GPIO(GPIO_PHY_RESET);
Roger Quadrose607ec92016-08-24 15:35:50 +0300743 /* Enable rising edge IRQ on GPIO0_11 and GPIO 1_26 */
744 reg = readl(GPIO0_RISINGDETECT) | BIT(11);
745 writel(reg, GPIO0_RISINGDETECT);
746 reg = readl(GPIO1_RISINGDETECT) | BIT(26);
747 writel(reg, GPIO1_RISINGDETECT);
748 /* Reset PHYs to capture the Jumper setting */
749 gpio_set_value(GPIO_PHY_RESET, 0);
750 udelay(2); /* PHY datasheet states 1uS min. */
751 gpio_set_value(GPIO_PHY_RESET, 1);
752
753 reg = readl(GPIO0_IRQSTATUSRAW) & BIT(11);
754 if (reg) {
755 writel(reg, GPIO0_IRQSTATUS1); /* clear irq */
756 /* RMII mode */
757 printf("ETH0, CPSW\n");
758 } else {
759 /* MII mode */
760 printf("ETH0, PRU\n");
761 cdce913_data.pdiv3 = 4; /* 25MHz PHY clk */
762 }
763
764 reg = readl(GPIO1_IRQSTATUSRAW) & BIT(26);
765 if (reg) {
766 writel(reg, GPIO1_IRQSTATUS1); /* clear irq */
767 /* RMII mode */
768 printf("ETH1, CPSW\n");
769 gpio_set_value(GPIO_MUX_MII_CTRL, 1);
770 } else {
771 /* MII mode */
772 printf("ETH1, PRU\n");
773 cdce913_data.pdiv2 = 4; /* 25MHz PHY clk */
774 }
775
776 /* disable rising edge IRQs */
777 reg = readl(GPIO0_RISINGDETECT) & ~BIT(11);
778 writel(reg, GPIO0_RISINGDETECT);
779 reg = readl(GPIO1_RISINGDETECT) & ~BIT(26);
780 writel(reg, GPIO1_RISINGDETECT);
Lokesh Vutla97f3a172016-05-16 11:47:26 +0530781
782 rv = setup_clock_synthesizer(&cdce913_data);
783 if (rv) {
784 printf("Clock synthesizer setup failed %d\n", rv);
785 return rv;
786 }
Roger Quadrose607ec92016-08-24 15:35:50 +0300787
788 /* reset PHYs */
789 gpio_set_value(GPIO_PHY_RESET, 0);
790 udelay(2); /* PHY datasheet states 1uS min. */
791 gpio_set_value(GPIO_PHY_RESET, 1);
Lokesh Vutla97f3a172016-05-16 11:47:26 +0530792 }
793#endif
794
Peter Korsgaarde3634262012-10-18 01:21:09 +0000795 return 0;
796}
797
Tom Rini044fc142012-10-24 07:28:17 +0000798#ifdef CONFIG_BOARD_LATE_INIT
799int board_late_init(void)
800{
Tero Kristo752a45a2019-09-27 19:14:29 +0300801 struct udevice *dev;
Roger Quadrosf411b5c2016-08-24 15:35:51 +0300802#if !defined(CONFIG_SPL_BUILD)
803 uint8_t mac_addr[6];
804 uint32_t mac_hi, mac_lo;
805#endif
806
Tom Rini044fc142012-10-24 07:28:17 +0000807#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
Nishanth Menon770e68c2016-02-24 12:30:55 -0600808 char *name = NULL;
Tom Riniace42752013-07-18 15:13:01 -0400809
robertcnelson@gmail.com40159492017-03-30 14:29:52 -0500810 if (board_is_bone_lt()) {
811 /* BeagleBoard.org BeagleBone Black Wireless: */
812 if (!strncmp(board_ti_get_rev(), "BWA", 3)) {
813 name = "BBBW";
814 }
robertcnelson@gmail.com2b79fba2017-03-30 14:29:53 -0500815 /* SeeedStudio BeagleBone Green Wireless */
816 if (!strncmp(board_ti_get_rev(), "GW1", 3)) {
817 name = "BBGW";
818 }
robertcnelson@gmail.com52609d72017-03-30 14:29:54 -0500819 /* BeagleBoard.org BeagleBone Blue */
820 if (!strncmp(board_ti_get_rev(), "BLA", 3)) {
821 name = "BBBL";
822 }
robertcnelson@gmail.com40159492017-03-30 14:29:52 -0500823 }
824
Nishanth Menon770e68c2016-02-24 12:30:55 -0600825 if (board_is_bbg1())
826 name = "BBG1";
Koen Kooiad6054f2018-07-18 10:13:59 +0200827 if (board_is_bben())
828 name = "BBEN";
Nishanth Menon770e68c2016-02-24 12:30:55 -0600829 set_board_info_env(name);
Lokesh Vutla5d4d4362016-11-29 11:58:03 +0530830
831 /*
832 * Default FIT boot on HS devices. Non FIT images are not allowed
833 * on HS devices.
834 */
835 if (get_device_type() == HS_DEVICE)
Simon Glass382bee52017-08-03 12:22:09 -0600836 env_set("boot_fit", "1");
Tom Rini044fc142012-10-24 07:28:17 +0000837#endif
838
Roger Quadrosf411b5c2016-08-24 15:35:51 +0300839#if !defined(CONFIG_SPL_BUILD)
840 /* try reading mac address from efuse */
841 mac_lo = readl(&cdev->macid0l);
842 mac_hi = readl(&cdev->macid0h);
843 mac_addr[0] = mac_hi & 0xFF;
844 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
845 mac_addr[2] = (mac_hi & 0xFF0000) >> 16;
846 mac_addr[3] = (mac_hi & 0xFF000000) >> 24;
847 mac_addr[4] = mac_lo & 0xFF;
848 mac_addr[5] = (mac_lo & 0xFF00) >> 8;
849
Simon Glass00caae62017-08-03 12:22:12 -0600850 if (!env_get("ethaddr")) {
Roger Quadrosf411b5c2016-08-24 15:35:51 +0300851 printf("<ethaddr> not set. Validating first E-fuse MAC\n");
852
853 if (is_valid_ethaddr(mac_addr))
Simon Glassfd1e9592017-08-03 12:22:11 -0600854 eth_env_set_enetaddr("ethaddr", mac_addr);
Roger Quadrosf411b5c2016-08-24 15:35:51 +0300855 }
856
857 mac_lo = readl(&cdev->macid1l);
858 mac_hi = readl(&cdev->macid1h);
859 mac_addr[0] = mac_hi & 0xFF;
860 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
861 mac_addr[2] = (mac_hi & 0xFF0000) >> 16;
862 mac_addr[3] = (mac_hi & 0xFF000000) >> 24;
863 mac_addr[4] = mac_lo & 0xFF;
864 mac_addr[5] = (mac_lo & 0xFF00) >> 8;
865
Simon Glass00caae62017-08-03 12:22:12 -0600866 if (!env_get("eth1addr")) {
Roger Quadrosf411b5c2016-08-24 15:35:51 +0300867 if (is_valid_ethaddr(mac_addr))
Simon Glassfd1e9592017-08-03 12:22:11 -0600868 eth_env_set_enetaddr("eth1addr", mac_addr);
Roger Quadrosf411b5c2016-08-24 15:35:51 +0300869 }
870#endif
871
Sam Protsenkofc228dc2018-02-28 00:26:15 +0200872 if (!env_get("serial#")) {
873 char *board_serial = env_get("board_serial");
874 char *ethaddr = env_get("ethaddr");
875
876 if (!board_serial || !strncmp(board_serial, "unknown", 7))
877 env_set("serial#", ethaddr);
878 else
879 env_set("serial#", board_serial);
880 }
881
Tero Kristo752a45a2019-09-27 19:14:29 +0300882 /* Just probe the potentially supported cdce913 device */
Dario Binacchiba149a52020-12-30 00:16:32 +0100883 uclass_get_device_by_name(UCLASS_CLK, "cdce913@65", &dev);
Tero Kristo752a45a2019-09-27 19:14:29 +0300884
Tom Rini044fc142012-10-24 07:28:17 +0000885 return 0;
886}
887#endif
888
Simon Glasscaa4daa2020-12-03 16:55:18 -0700889/* CPSW plat */
Faiz Abbas0229c932019-03-18 13:54:37 +0530890#if !CONFIG_IS_ENABLED(OF_CONTROL)
891struct cpsw_slave_data slave_data[] = {
892 {
893 .slave_reg_ofs = CPSW_SLAVE0_OFFSET,
894 .sliver_reg_ofs = CPSW_SLIVER0_OFFSET,
895 .phy_addr = 0,
896 },
897 {
898 .slave_reg_ofs = CPSW_SLAVE1_OFFSET,
899 .sliver_reg_ofs = CPSW_SLIVER1_OFFSET,
900 .phy_addr = 1,
901 },
902};
903
904struct cpsw_platform_data am335_eth_data = {
905 .cpsw_base = CPSW_BASE,
906 .version = CPSW_CTRL_VERSION_2,
907 .bd_ram_ofs = CPSW_BD_OFFSET,
908 .ale_reg_ofs = CPSW_ALE_OFFSET,
909 .cpdma_reg_ofs = CPSW_CPDMA_OFFSET,
910 .mdio_div = CPSW_MDIO_DIV,
911 .host_port_reg_ofs = CPSW_HOST_PORT_OFFSET,
912 .channels = 8,
913 .slaves = 2,
914 .slave_data = slave_data,
915 .ale_entries = 1024,
Faiz Abbas0229c932019-03-18 13:54:37 +0530916 .mac_control = 0x20,
917 .active_slave = 0,
918 .mdio_base = 0x4a101000,
919 .gmii_sel = 0x44e10650,
920 .phy_sel_compat = "ti,am3352-cpsw-phy-sel",
921 .syscon_addr = 0x44e10630,
922 .macid_sel_compat = "cpsw,am33xx",
923};
924
925struct eth_pdata cpsw_pdata = {
926 .iobase = 0x4a100000,
927 .phy_interface = 0,
928 .priv_pdata = &am335_eth_data,
929};
930
Simon Glass20e442a2020-12-28 20:34:54 -0700931U_BOOT_DRVINFO(am335x_eth) = {
Faiz Abbas0229c932019-03-18 13:54:37 +0530932 .name = "eth_cpsw",
Simon Glasscaa4daa2020-12-03 16:55:18 -0700933 .plat = &cpsw_pdata,
Faiz Abbas0229c932019-03-18 13:54:37 +0530934};
935#endif
936
Lokesh Vutla505ea6e2016-05-16 11:24:24 +0530937#ifdef CONFIG_SPL_LOAD_FIT
938int board_fit_config_name_match(const char *name)
939{
940 if (board_is_gp_evm() && !strcmp(name, "am335x-evm"))
941 return 0;
942 else if (board_is_bone() && !strcmp(name, "am335x-bone"))
943 return 0;
944 else if (board_is_bone_lt() && !strcmp(name, "am335x-boneblack"))
945 return 0;
Jason Kridnereff0c972018-03-07 05:40:41 -0500946 else if (board_is_pb() && !strcmp(name, "am335x-pocketbeagle"))
947 return 0;
Lokesh Vutla3819ea72016-05-16 11:24:28 +0530948 else if (board_is_evm_sk() && !strcmp(name, "am335x-evmsk"))
949 return 0;
Lokesh Vutlada9d9592016-05-16 11:24:29 +0530950 else if (board_is_bbg1() && !strcmp(name, "am335x-bonegreen"))
951 return 0;
Lokesh Vutla73ec6962016-05-16 11:47:28 +0530952 else if (board_is_icev2() && !strcmp(name, "am335x-icev2"))
953 return 0;
Lokesh Vutla505ea6e2016-05-16 11:24:24 +0530954 else
955 return -1;
956}
957#endif
Andrew F. Davisb0a4eea2016-08-30 14:06:24 -0500958
959#ifdef CONFIG_TI_SECURE_DEVICE
960void board_fit_image_post_process(void **p_image, size_t *p_size)
961{
962 secure_boot_verify_image(p_image, p_size);
963}
964#endif
Lokesh Vutla4548bc82017-04-26 13:37:08 +0530965
966#if !CONFIG_IS_ENABLED(OF_CONTROL)
Simon Glass8a8d24b2020-12-03 16:55:23 -0700967static const struct omap_hsmmc_plat am335x_mmc0_plat = {
Lokesh Vutla4548bc82017-04-26 13:37:08 +0530968 .base_addr = (struct hsmmc *)OMAP_HSMMC1_BASE,
969 .cfg.host_caps = MMC_MODE_HS_52MHz | MMC_MODE_HS | MMC_MODE_4BIT,
970 .cfg.f_min = 400000,
971 .cfg.f_max = 52000000,
972 .cfg.voltages = MMC_VDD_32_33 | MMC_VDD_33_34 | MMC_VDD_165_195,
973 .cfg.b_max = CONFIG_SYS_MMC_MAX_BLK_COUNT,
974};
975
Simon Glass20e442a2020-12-28 20:34:54 -0700976U_BOOT_DRVINFO(am335x_mmc0) = {
Lokesh Vutla4548bc82017-04-26 13:37:08 +0530977 .name = "omap_hsmmc",
Simon Glass8a8d24b2020-12-03 16:55:23 -0700978 .plat = &am335x_mmc0_plat,
Lokesh Vutla4548bc82017-04-26 13:37:08 +0530979};
980
Simon Glass8a8d24b2020-12-03 16:55:23 -0700981static const struct omap_hsmmc_plat am335x_mmc1_plat = {
Lokesh Vutla4548bc82017-04-26 13:37:08 +0530982 .base_addr = (struct hsmmc *)OMAP_HSMMC2_BASE,
983 .cfg.host_caps = MMC_MODE_HS_52MHz | MMC_MODE_HS | MMC_MODE_8BIT,
984 .cfg.f_min = 400000,
985 .cfg.f_max = 52000000,
986 .cfg.voltages = MMC_VDD_32_33 | MMC_VDD_33_34 | MMC_VDD_165_195,
987 .cfg.b_max = CONFIG_SYS_MMC_MAX_BLK_COUNT,
988};
989
Simon Glass20e442a2020-12-28 20:34:54 -0700990U_BOOT_DRVINFO(am335x_mmc1) = {
Lokesh Vutla4548bc82017-04-26 13:37:08 +0530991 .name = "omap_hsmmc",
Simon Glass8a8d24b2020-12-03 16:55:23 -0700992 .plat = &am335x_mmc1_plat,
Lokesh Vutla4548bc82017-04-26 13:37:08 +0530993};
994#endif