blob: 0299dd6486f093679ac2b6fbf2591bd03ced2dd4 [file] [log] [blame]
Peter Korsgaard85ec2db2012-10-18 01:21:09 +00001/*
2 * board.c
3 *
4 * Board functions for TI AM335X based boards
5 *
6 * Copyright (C) 2011, Texas Instruments, Incorporated - http://www.ti.com/
7 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02008 * SPDX-License-Identifier: GPL-2.0+
Peter Korsgaard85ec2db2012-10-18 01:21:09 +00009 */
10
11#include <common.h>
12#include <errno.h>
13#include <spl.h>
14#include <asm/arch/cpu.h>
15#include <asm/arch/hardware.h>
16#include <asm/arch/omap.h>
17#include <asm/arch/ddr_defs.h>
18#include <asm/arch/clock.h>
19#include <asm/arch/gpio.h>
20#include <asm/arch/mmc_host_def.h>
21#include <asm/arch/sys_proto.h>
Steve Kipiszbe9b6f82013-07-18 15:13:03 -040022#include <asm/arch/mem.h>
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000023#include <asm/io.h>
24#include <asm/emif.h>
25#include <asm/gpio.h>
26#include <i2c.h>
27#include <miiphy.h>
28#include <cpsw.h>
Tom Rini52437072013-08-30 16:28:46 -040029#include <power/tps65217.h>
30#include <power/tps65910.h>
Tom Rini303bfe82013-10-01 12:32:04 -040031#include <environment.h>
32#include <watchdog.h>
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000033#include "board.h"
34
35DECLARE_GLOBAL_DATA_PTR;
36
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000037/* GPIO that controls power to DDR on EVM-SK */
38#define GPIO_DDR_VTT_EN 7
39
40static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
41
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000042/*
43 * Read header information from EEPROM into global structure.
44 */
Tom Rini4021fd92013-07-18 15:13:01 -040045static int read_eeprom(struct am335x_baseboard_id *header)
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000046{
47 /* Check if baseboard eeprom is available */
48 if (i2c_probe(CONFIG_SYS_I2C_EEPROM_ADDR)) {
49 puts("Could not probe the EEPROM; something fundamentally "
50 "wrong on the I2C bus.\n");
51 return -ENODEV;
52 }
53
54 /* read the eeprom using i2c */
Tom Rini4021fd92013-07-18 15:13:01 -040055 if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0, 2, (uchar *)header,
56 sizeof(struct am335x_baseboard_id))) {
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000057 puts("Could not read the EEPROM; something fundamentally"
58 " wrong on the I2C bus.\n");
59 return -EIO;
60 }
61
Tom Rini4021fd92013-07-18 15:13:01 -040062 if (header->magic != 0xEE3355AA) {
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000063 /*
64 * read the eeprom using i2c again,
65 * but use only a 1 byte address
66 */
Tom Rini4021fd92013-07-18 15:13:01 -040067 if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0, 1, (uchar *)header,
68 sizeof(struct am335x_baseboard_id))) {
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000069 puts("Could not read the EEPROM; something "
70 "fundamentally wrong on the I2C bus.\n");
71 return -EIO;
72 }
73
Tom Rini4021fd92013-07-18 15:13:01 -040074 if (header->magic != 0xEE3355AA) {
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000075 printf("Incorrect magic number (0x%x) in EEPROM\n",
Tom Rini4021fd92013-07-18 15:13:01 -040076 header->magic);
Peter Korsgaard85ec2db2012-10-18 01:21:09 +000077 return -EINVAL;
78 }
79 }
80
81 return 0;
82}
83
Steve Kipiszc1399b42013-07-18 15:13:04 -040084#if defined(CONFIG_SPL_BUILD) || defined(CONFIG_NOR_BOOT)
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +000085static const struct ddr_data ddr2_data = {
Peter Korsgaard3adb8272012-10-18 01:21:13 +000086 .datardsratio0 = ((MT47H128M16RT25E_RD_DQS<<30) |
87 (MT47H128M16RT25E_RD_DQS<<20) |
88 (MT47H128M16RT25E_RD_DQS<<10) |
89 (MT47H128M16RT25E_RD_DQS<<0)),
90 .datawdsratio0 = ((MT47H128M16RT25E_WR_DQS<<30) |
91 (MT47H128M16RT25E_WR_DQS<<20) |
92 (MT47H128M16RT25E_WR_DQS<<10) |
93 (MT47H128M16RT25E_WR_DQS<<0)),
94 .datawiratio0 = ((MT47H128M16RT25E_PHY_WRLVL<<30) |
95 (MT47H128M16RT25E_PHY_WRLVL<<20) |
96 (MT47H128M16RT25E_PHY_WRLVL<<10) |
97 (MT47H128M16RT25E_PHY_WRLVL<<0)),
98 .datagiratio0 = ((MT47H128M16RT25E_PHY_GATELVL<<30) |
99 (MT47H128M16RT25E_PHY_GATELVL<<20) |
100 (MT47H128M16RT25E_PHY_GATELVL<<10) |
101 (MT47H128M16RT25E_PHY_GATELVL<<0)),
102 .datafwsratio0 = ((MT47H128M16RT25E_PHY_FIFO_WE<<30) |
103 (MT47H128M16RT25E_PHY_FIFO_WE<<20) |
104 (MT47H128M16RT25E_PHY_FIFO_WE<<10) |
105 (MT47H128M16RT25E_PHY_FIFO_WE<<0)),
106 .datawrsratio0 = ((MT47H128M16RT25E_PHY_WR_DATA<<30) |
107 (MT47H128M16RT25E_PHY_WR_DATA<<20) |
108 (MT47H128M16RT25E_PHY_WR_DATA<<10) |
109 (MT47H128M16RT25E_PHY_WR_DATA<<0)),
110 .datauserank0delay = MT47H128M16RT25E_PHY_RANK0_DELAY,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000111 .datadldiff0 = PHY_DLL_LOCK_DIFF,
112};
113
114static const struct cmd_control ddr2_cmd_ctrl_data = {
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000115 .cmd0csratio = MT47H128M16RT25E_RATIO,
116 .cmd0dldiff = MT47H128M16RT25E_DLL_LOCK_DIFF,
117 .cmd0iclkout = MT47H128M16RT25E_INVERT_CLKOUT,
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000118
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000119 .cmd1csratio = MT47H128M16RT25E_RATIO,
120 .cmd1dldiff = MT47H128M16RT25E_DLL_LOCK_DIFF,
121 .cmd1iclkout = MT47H128M16RT25E_INVERT_CLKOUT,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000122
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000123 .cmd2csratio = MT47H128M16RT25E_RATIO,
124 .cmd2dldiff = MT47H128M16RT25E_DLL_LOCK_DIFF,
125 .cmd2iclkout = MT47H128M16RT25E_INVERT_CLKOUT,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000126};
127
128static const struct emif_regs ddr2_emif_reg_data = {
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000129 .sdram_config = MT47H128M16RT25E_EMIF_SDCFG,
130 .ref_ctrl = MT47H128M16RT25E_EMIF_SDREF,
131 .sdram_tim1 = MT47H128M16RT25E_EMIF_TIM1,
132 .sdram_tim2 = MT47H128M16RT25E_EMIF_TIM2,
133 .sdram_tim3 = MT47H128M16RT25E_EMIF_TIM3,
134 .emif_ddr_phy_ctlr_1 = MT47H128M16RT25E_EMIF_READ_LATENCY,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000135};
136
137static const struct ddr_data ddr3_data = {
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000138 .datardsratio0 = MT41J128MJT125_RD_DQS,
139 .datawdsratio0 = MT41J128MJT125_WR_DQS,
140 .datafwsratio0 = MT41J128MJT125_PHY_FIFO_WE,
141 .datawrsratio0 = MT41J128MJT125_PHY_WR_DATA,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000142 .datadldiff0 = PHY_DLL_LOCK_DIFF,
143};
144
Tom Rini385bc752013-03-21 04:30:02 +0000145static const struct ddr_data ddr3_beagleblack_data = {
146 .datardsratio0 = MT41K256M16HA125E_RD_DQS,
147 .datawdsratio0 = MT41K256M16HA125E_WR_DQS,
148 .datafwsratio0 = MT41K256M16HA125E_PHY_FIFO_WE,
149 .datawrsratio0 = MT41K256M16HA125E_PHY_WR_DATA,
150 .datadldiff0 = PHY_DLL_LOCK_DIFF,
151};
152
Jeff Lance7c03a222013-01-14 05:32:20 +0000153static const struct ddr_data ddr3_evm_data = {
154 .datardsratio0 = MT41J512M8RH125_RD_DQS,
155 .datawdsratio0 = MT41J512M8RH125_WR_DQS,
156 .datafwsratio0 = MT41J512M8RH125_PHY_FIFO_WE,
157 .datawrsratio0 = MT41J512M8RH125_PHY_WR_DATA,
158 .datadldiff0 = PHY_DLL_LOCK_DIFF,
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,
163 .cmd0dldiff = MT41J128MJT125_DLL_LOCK_DIFF,
164 .cmd0iclkout = MT41J128MJT125_INVERT_CLKOUT,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000165
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000166 .cmd1csratio = MT41J128MJT125_RATIO,
167 .cmd1dldiff = MT41J128MJT125_DLL_LOCK_DIFF,
168 .cmd1iclkout = MT41J128MJT125_INVERT_CLKOUT,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000169
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000170 .cmd2csratio = MT41J128MJT125_RATIO,
171 .cmd2dldiff = MT41J128MJT125_DLL_LOCK_DIFF,
172 .cmd2iclkout = MT41J128MJT125_INVERT_CLKOUT,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000173};
174
Tom Rini385bc752013-03-21 04:30:02 +0000175static const struct cmd_control ddr3_beagleblack_cmd_ctrl_data = {
176 .cmd0csratio = MT41K256M16HA125E_RATIO,
177 .cmd0dldiff = MT41K256M16HA125E_DLL_LOCK_DIFF,
178 .cmd0iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
179
180 .cmd1csratio = MT41K256M16HA125E_RATIO,
181 .cmd1dldiff = MT41K256M16HA125E_DLL_LOCK_DIFF,
182 .cmd1iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
183
184 .cmd2csratio = MT41K256M16HA125E_RATIO,
185 .cmd2dldiff = MT41K256M16HA125E_DLL_LOCK_DIFF,
186 .cmd2iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
187};
188
Jeff Lance7c03a222013-01-14 05:32:20 +0000189static const struct cmd_control ddr3_evm_cmd_ctrl_data = {
190 .cmd0csratio = MT41J512M8RH125_RATIO,
191 .cmd0dldiff = MT41J512M8RH125_DLL_LOCK_DIFF,
192 .cmd0iclkout = MT41J512M8RH125_INVERT_CLKOUT,
193
194 .cmd1csratio = MT41J512M8RH125_RATIO,
195 .cmd1dldiff = MT41J512M8RH125_DLL_LOCK_DIFF,
196 .cmd1iclkout = MT41J512M8RH125_INVERT_CLKOUT,
197
198 .cmd2csratio = MT41J512M8RH125_RATIO,
199 .cmd2dldiff = MT41J512M8RH125_DLL_LOCK_DIFF,
200 .cmd2iclkout = MT41J512M8RH125_INVERT_CLKOUT,
201};
202
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000203static struct emif_regs ddr3_emif_reg_data = {
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000204 .sdram_config = MT41J128MJT125_EMIF_SDCFG,
205 .ref_ctrl = MT41J128MJT125_EMIF_SDREF,
206 .sdram_tim1 = MT41J128MJT125_EMIF_TIM1,
207 .sdram_tim2 = MT41J128MJT125_EMIF_TIM2,
208 .sdram_tim3 = MT41J128MJT125_EMIF_TIM3,
209 .zq_config = MT41J128MJT125_ZQ_CFG,
Vaibhav Hiremathc30d57b2013-03-14 21:11:16 +0000210 .emif_ddr_phy_ctlr_1 = MT41J128MJT125_EMIF_READ_LATENCY |
211 PHY_EN_DYN_PWRDN,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000212};
Jeff Lance7c03a222013-01-14 05:32:20 +0000213
Tom Rini385bc752013-03-21 04:30:02 +0000214static struct emif_regs ddr3_beagleblack_emif_reg_data = {
215 .sdram_config = MT41K256M16HA125E_EMIF_SDCFG,
216 .ref_ctrl = MT41K256M16HA125E_EMIF_SDREF,
217 .sdram_tim1 = MT41K256M16HA125E_EMIF_TIM1,
218 .sdram_tim2 = MT41K256M16HA125E_EMIF_TIM2,
219 .sdram_tim3 = MT41K256M16HA125E_EMIF_TIM3,
220 .zq_config = MT41K256M16HA125E_ZQ_CFG,
221 .emif_ddr_phy_ctlr_1 = MT41K256M16HA125E_EMIF_READ_LATENCY,
222};
223
Jeff Lance7c03a222013-01-14 05:32:20 +0000224static struct emif_regs ddr3_evm_emif_reg_data = {
225 .sdram_config = MT41J512M8RH125_EMIF_SDCFG,
226 .ref_ctrl = MT41J512M8RH125_EMIF_SDREF,
227 .sdram_tim1 = MT41J512M8RH125_EMIF_TIM1,
228 .sdram_tim2 = MT41J512M8RH125_EMIF_TIM2,
229 .sdram_tim3 = MT41J512M8RH125_EMIF_TIM3,
230 .zq_config = MT41J512M8RH125_ZQ_CFG,
Vaibhav Hiremathc30d57b2013-03-14 21:11:16 +0000231 .emif_ddr_phy_ctlr_1 = MT41J512M8RH125_EMIF_READ_LATENCY |
232 PHY_EN_DYN_PWRDN,
Jeff Lance7c03a222013-01-14 05:32:20 +0000233};
Peter Korsgaardeb204db2013-05-13 08:36:30 +0000234
235#ifdef CONFIG_SPL_OS_BOOT
236int spl_start_uboot(void)
237{
238 /* break into full u-boot on 'c' */
239 return (serial_tstc() && serial_getc() == 'c');
240}
241#endif
242
Lokesh Vutla89a83bf2013-07-30 10:48:52 +0530243#define OSC (V_OSCK/1000000)
244const struct dpll_params dpll_ddr = {
245 266, OSC-1, 1, -1, -1, -1, -1};
246const struct dpll_params dpll_ddr_evm_sk = {
247 303, OSC-1, 1, -1, -1, -1, -1};
248const struct dpll_params dpll_ddr_bone_black = {
249 400, OSC-1, 1, -1, -1, -1, -1};
250
Tom Rini52437072013-08-30 16:28:46 -0400251void am33xx_spl_board_init(void)
252{
253 struct am335x_baseboard_id header;
Tom Rini52437072013-08-30 16:28:46 -0400254 int mpu_vdd;
255
256 if (read_eeprom(&header) < 0)
257 puts("Could not get board ID.\n");
258
259 /* Get the frequency */
Steve Kipisz5adac352013-08-14 10:51:31 -0400260 dpll_mpu_opp100.m = am335x_get_efuse_mpu_max_freq(cdev);
Tom Rini52437072013-08-30 16:28:46 -0400261
262 if (board_is_bone(&header) || board_is_bone_lt(&header)) {
263 /* BeagleBone PMIC Code */
264 int usb_cur_lim;
265
266 /*
267 * Only perform PMIC configurations if board rev > A1
268 * on Beaglebone White
269 */
270 if (board_is_bone(&header) && !strncmp(header.version,
271 "00A1", 4))
272 return;
273
274 if (i2c_probe(TPS65217_CHIP_PM))
275 return;
276
277 /*
278 * On Beaglebone White we need to ensure we have AC power
279 * before increasing the frequency.
280 */
281 if (board_is_bone(&header)) {
282 uchar pmic_status_reg;
283 if (tps65217_reg_read(TPS65217_STATUS,
284 &pmic_status_reg))
285 return;
286 if (!(pmic_status_reg & TPS65217_PWR_SRC_AC_BITMASK)) {
287 puts("No AC power, disabling frequency switch\n");
288 return;
289 }
290 }
291
292 /*
293 * Override what we have detected since we know if we have
294 * a Beaglebone Black it supports 1GHz.
295 */
296 if (board_is_bone_lt(&header))
Steve Kipisz5adac352013-08-14 10:51:31 -0400297 dpll_mpu_opp100.m = MPUPLL_M_1000;
Tom Rini52437072013-08-30 16:28:46 -0400298
299 /*
300 * Increase USB current limit to 1300mA or 1800mA and set
301 * the MPU voltage controller as needed.
302 */
Steve Kipisz5adac352013-08-14 10:51:31 -0400303 if (dpll_mpu_opp100.m == MPUPLL_M_1000) {
Tom Rini52437072013-08-30 16:28:46 -0400304 usb_cur_lim = TPS65217_USB_INPUT_CUR_LIMIT_1800MA;
305 mpu_vdd = TPS65217_DCDC_VOLT_SEL_1325MV;
306 } else {
307 usb_cur_lim = TPS65217_USB_INPUT_CUR_LIMIT_1300MA;
308 mpu_vdd = TPS65217_DCDC_VOLT_SEL_1275MV;
309 }
310
311 if (tps65217_reg_write(TPS65217_PROT_LEVEL_NONE,
312 TPS65217_POWER_PATH,
313 usb_cur_lim,
314 TPS65217_USB_INPUT_CUR_LIMIT_MASK))
315 puts("tps65217_reg_write failure\n");
316
Steve Kipisz5adac352013-08-14 10:51:31 -0400317 /* Set DCDC3 (CORE) voltage to 1.125V */
318 if (tps65217_voltage_update(TPS65217_DEFDCDC3,
319 TPS65217_DCDC_VOLT_SEL_1125MV)) {
320 puts("tps65217_voltage_update failure\n");
321 return;
322 }
323
324 /* Set CORE Frequencies to OPP100 */
325 do_setup_dpll(&dpll_core_regs, &dpll_core_opp100);
Tom Rini52437072013-08-30 16:28:46 -0400326
327 /* Set DCDC2 (MPU) voltage */
328 if (tps65217_voltage_update(TPS65217_DEFDCDC2, mpu_vdd)) {
329 puts("tps65217_voltage_update failure\n");
330 return;
331 }
332
333 /*
334 * Set LDO3, LDO4 output voltage to 3.3V for Beaglebone.
335 * Set LDO3 to 1.8V and LDO4 to 3.3V for Beaglebone Black.
336 */
337 if (board_is_bone(&header)) {
338 if (tps65217_reg_write(TPS65217_PROT_LEVEL_2,
339 TPS65217_DEFLS1,
340 TPS65217_LDO_VOLTAGE_OUT_3_3,
341 TPS65217_LDO_MASK))
342 puts("tps65217_reg_write failure\n");
343 } else {
344 if (tps65217_reg_write(TPS65217_PROT_LEVEL_2,
345 TPS65217_DEFLS1,
346 TPS65217_LDO_VOLTAGE_OUT_1_8,
347 TPS65217_LDO_MASK))
348 puts("tps65217_reg_write failure\n");
349 }
350
351 if (tps65217_reg_write(TPS65217_PROT_LEVEL_2,
352 TPS65217_DEFLS2,
353 TPS65217_LDO_VOLTAGE_OUT_3_3,
354 TPS65217_LDO_MASK))
355 puts("tps65217_reg_write failure\n");
356 } else {
357 int sil_rev;
358
359 /*
360 * The GP EVM, IDK and EVM SK use a TPS65910 PMIC. For all
361 * MPU frequencies we support we use a CORE voltage of
362 * 1.1375V. For MPU voltage we need to switch based on
363 * the frequency we are running at.
364 */
365 if (i2c_probe(TPS65910_CTRL_I2C_ADDR))
366 return;
367
368 /*
369 * Depending on MPU clock and PG we will need a different
370 * VDD to drive at that speed.
371 */
372 sil_rev = readl(&cdev->deviceid) >> 28;
Steve Kipisz5adac352013-08-14 10:51:31 -0400373 mpu_vdd = am335x_get_tps65910_mpu_vdd(sil_rev,
374 dpll_mpu_opp100.m);
Tom Rini52437072013-08-30 16:28:46 -0400375
376 /* Tell the TPS65910 to use i2c */
377 tps65910_set_i2c_control();
378
379 /* First update MPU voltage. */
380 if (tps65910_voltage_update(MPU, mpu_vdd))
381 return;
382
383 /* Second, update the CORE voltage. */
384 if (tps65910_voltage_update(CORE, TPS65910_OP_REG_SEL_1_1_3))
385 return;
Steve Kipisz5adac352013-08-14 10:51:31 -0400386
387 /* Set CORE Frequencies to OPP100 */
388 do_setup_dpll(&dpll_core_regs, &dpll_core_opp100);
Tom Rini52437072013-08-30 16:28:46 -0400389 }
390
391 /* Set MPU Frequency to what we detected now that voltages are set */
Steve Kipisz5adac352013-08-14 10:51:31 -0400392 do_setup_dpll(&dpll_mpu_regs, &dpll_mpu_opp100);
Tom Rini52437072013-08-30 16:28:46 -0400393}
394
Lokesh Vutla89a83bf2013-07-30 10:48:52 +0530395const struct dpll_params *get_dpll_ddr_params(void)
396{
397 struct am335x_baseboard_id header;
398
399 enable_i2c0_pin_mux();
400 i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
401 if (read_eeprom(&header) < 0)
402 puts("Could not get board ID.\n");
403
404 if (board_is_evm_sk(&header))
405 return &dpll_ddr_evm_sk;
406 else if (board_is_bone_lt(&header))
407 return &dpll_ddr_bone_black;
408 else if (board_is_evm_15_or_later(&header))
409 return &dpll_ddr_evm_sk;
410 else
411 return &dpll_ddr;
412}
413
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530414void set_uart_mux_conf(void)
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000415{
Andrew Bradford65c51ff2012-10-25 08:21:30 -0400416#ifdef CONFIG_SERIAL1
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000417 enable_uart0_pin_mux();
Andrew Bradford65c51ff2012-10-25 08:21:30 -0400418#endif /* CONFIG_SERIAL1 */
419#ifdef CONFIG_SERIAL2
420 enable_uart1_pin_mux();
421#endif /* CONFIG_SERIAL2 */
422#ifdef CONFIG_SERIAL3
423 enable_uart2_pin_mux();
424#endif /* CONFIG_SERIAL3 */
425#ifdef CONFIG_SERIAL4
426 enable_uart3_pin_mux();
427#endif /* CONFIG_SERIAL4 */
428#ifdef CONFIG_SERIAL5
429 enable_uart4_pin_mux();
430#endif /* CONFIG_SERIAL5 */
431#ifdef CONFIG_SERIAL6
432 enable_uart5_pin_mux();
433#endif /* CONFIG_SERIAL6 */
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530434}
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000435
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530436void set_mux_conf_regs(void)
437{
438 __maybe_unused struct am335x_baseboard_id header;
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000439
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530440 if (read_eeprom(&header) < 0)
441 puts("Could not get board ID.\n");
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000442
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530443 enable_board_pin_mux(&header);
444}
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000445
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530446void sdram_init(void)
447{
448 __maybe_unused struct am335x_baseboard_id header;
Lokesh Vutlab1b6fba2013-07-30 10:48:53 +0530449
Tom Rini4021fd92013-07-18 15:13:01 -0400450 if (read_eeprom(&header) < 0)
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000451 puts("Could not get board ID.\n");
452
Tom Rini4021fd92013-07-18 15:13:01 -0400453 if (board_is_evm_sk(&header)) {
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000454 /*
455 * EVM SK 1.2A and later use gpio0_7 to enable DDR3.
456 * This is safe enough to do on older revs.
457 */
458 gpio_request(GPIO_DDR_VTT_EN, "ddr_vtt_en");
459 gpio_direction_output(GPIO_DDR_VTT_EN, 1);
460 }
461
Tom Rini4021fd92013-07-18 15:13:01 -0400462 if (board_is_evm_sk(&header))
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000463 config_ddr(303, MT41J128MJT125_IOCTRL_VALUE, &ddr3_data,
Matt Porter65991ec2013-03-15 10:07:03 +0000464 &ddr3_cmd_ctrl_data, &ddr3_emif_reg_data, 0);
Tom Rini4021fd92013-07-18 15:13:01 -0400465 else if (board_is_bone_lt(&header))
Tom Rini8939ec32013-04-10 15:10:54 +0200466 config_ddr(400, MT41K256M16HA125E_IOCTRL_VALUE,
Tom Rini385bc752013-03-21 04:30:02 +0000467 &ddr3_beagleblack_data,
468 &ddr3_beagleblack_cmd_ctrl_data,
469 &ddr3_beagleblack_emif_reg_data, 0);
Tom Rini4021fd92013-07-18 15:13:01 -0400470 else if (board_is_evm_15_or_later(&header))
Jeff Lance7c03a222013-01-14 05:32:20 +0000471 config_ddr(303, MT41J512M8RH125_IOCTRL_VALUE, &ddr3_evm_data,
Matt Porter65991ec2013-03-15 10:07:03 +0000472 &ddr3_evm_cmd_ctrl_data, &ddr3_evm_emif_reg_data, 0);
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +0000473 else
Peter Korsgaard3adb8272012-10-18 01:21:13 +0000474 config_ddr(266, MT47H128M16RT25E_IOCTRL_VALUE, &ddr2_data,
Matt Porter65991ec2013-03-15 10:07:03 +0000475 &ddr2_cmd_ctrl_data, &ddr2_emif_reg_data, 0);
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000476}
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530477#endif
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000478
479/*
480 * Basic board specific setup. Pinmux has been handled already.
481 */
482int board_init(void)
483{
Tom Rini303bfe82013-10-01 12:32:04 -0400484#if defined(CONFIG_HW_WATCHDOG)
485 hw_watchdog_init();
486#endif
487
Tom Rinif3b6a1d2013-08-09 11:22:13 -0400488 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
pekon gupta53b4b322013-11-18 19:03:02 +0530489#if defined(CONFIG_NOR) || defined(CONFIG_NAND)
Ilya Yanok3d9725e2012-11-06 13:06:31 +0000490 gpmc_init();
Steve Kipiszbe9b6f82013-07-18 15:13:03 -0400491#endif
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000492 return 0;
493}
494
Tom Rini40271852012-10-24 07:28:17 +0000495#ifdef CONFIG_BOARD_LATE_INIT
496int board_late_init(void)
497{
498#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
499 char safe_string[HDR_NAME_LEN + 1];
Tom Rini4021fd92013-07-18 15:13:01 -0400500 struct am335x_baseboard_id header;
501
502 if (read_eeprom(&header) < 0)
503 puts("Could not get board ID.\n");
Tom Rini40271852012-10-24 07:28:17 +0000504
505 /* Now set variables based on the header. */
506 strncpy(safe_string, (char *)header.name, sizeof(header.name));
507 safe_string[sizeof(header.name)] = 0;
508 setenv("board_name", safe_string);
509
510 strncpy(safe_string, (char *)header.version, sizeof(header.version));
511 safe_string[sizeof(header.version)] = 0;
512 setenv("board_rev", safe_string);
513#endif
514
515 return 0;
516}
517#endif
518
Ilya Yanok0760a0d2013-02-05 11:36:26 +0000519#if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) || \
520 (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD))
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000521static void cpsw_control(int enabled)
522{
523 /* VTP can be added here */
524
525 return;
526}
527
528static struct cpsw_slave_data cpsw_slaves[] = {
529 {
530 .slave_reg_ofs = 0x208,
531 .sliver_reg_ofs = 0xd80,
532 .phy_id = 0,
533 },
534 {
535 .slave_reg_ofs = 0x308,
536 .sliver_reg_ofs = 0xdc0,
537 .phy_id = 1,
538 },
539};
540
541static struct cpsw_platform_data cpsw_data = {
Matt Portere24646f2013-03-15 10:07:02 +0000542 .mdio_base = CPSW_MDIO_BASE,
543 .cpsw_base = CPSW_BASE,
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000544 .mdio_div = 0xff,
545 .channels = 8,
546 .cpdma_reg_ofs = 0x800,
547 .slaves = 1,
548 .slave_data = cpsw_slaves,
549 .ale_reg_ofs = 0xd00,
550 .ale_entries = 1024,
551 .host_port_reg_ofs = 0x108,
552 .hw_stats_reg_ofs = 0x900,
Mugunthan V Nff559872013-07-08 16:04:37 +0530553 .bd_ram_ofs = 0x2000,
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000554 .mac_control = (1 << 5),
555 .control = cpsw_control,
556 .host_port_num = 0,
557 .version = CPSW_CTRL_VERSION_2,
558};
Ilya Yanok44a2c072012-11-06 13:48:24 +0000559#endif
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000560
Ilya Yanok44a2c072012-11-06 13:48:24 +0000561#if defined(CONFIG_DRIVER_TI_CPSW) || \
562 (defined(CONFIG_USB_ETHER) && defined(CONFIG_MUSB_GADGET))
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000563int board_eth_init(bd_t *bis)
564{
Ilya Yanok44a2c072012-11-06 13:48:24 +0000565 int rv, n = 0;
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000566 uint8_t mac_addr[6];
567 uint32_t mac_hi, mac_lo;
Tom Rini4021fd92013-07-18 15:13:01 -0400568 __maybe_unused struct am335x_baseboard_id header;
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000569
Ilya Yanok0760a0d2013-02-05 11:36:26 +0000570 /* try reading mac address from efuse */
571 mac_lo = readl(&cdev->macid0l);
572 mac_hi = readl(&cdev->macid0h);
573 mac_addr[0] = mac_hi & 0xFF;
574 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
575 mac_addr[2] = (mac_hi & 0xFF0000) >> 16;
576 mac_addr[3] = (mac_hi & 0xFF000000) >> 24;
577 mac_addr[4] = mac_lo & 0xFF;
578 mac_addr[5] = (mac_lo & 0xFF00) >> 8;
579
580#if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) || \
581 (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD))
582 if (!getenv("ethaddr")) {
583 printf("<ethaddr> not set. Validating first E-fuse MAC\n");
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000584
585 if (is_valid_ether_addr(mac_addr))
586 eth_setenv_enetaddr("ethaddr", mac_addr);
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000587 }
588
Joel A Fernandesf7488542013-05-07 05:52:55 +0000589#ifdef CONFIG_DRIVER_TI_CPSW
Tom Rini4021fd92013-07-18 15:13:01 -0400590 if (read_eeprom(&header) < 0)
591 puts("Could not get board ID.\n");
592
593 if (board_is_bone(&header) || board_is_bone_lt(&header) ||
594 board_is_idk(&header)) {
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000595 writel(MII_MODE_ENABLE, &cdev->miisel);
596 cpsw_slaves[0].phy_if = cpsw_slaves[1].phy_if =
597 PHY_INTERFACE_MODE_MII;
598 } else {
Heiko Schocherc4fea292013-08-19 16:38:56 +0200599 writel((RGMII_MODE_ENABLE | RGMII_INT_DELAY), &cdev->miisel);
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000600 cpsw_slaves[0].phy_if = cpsw_slaves[1].phy_if =
601 PHY_INTERFACE_MODE_RGMII;
602 }
603
Ilya Yanok44a2c072012-11-06 13:48:24 +0000604 rv = cpsw_register(&cpsw_data);
605 if (rv < 0)
606 printf("Error %d registering CPSW switch\n", rv);
607 else
608 n += rv;
Joel A Fernandesf7488542013-05-07 05:52:55 +0000609#endif
Tom Rini183943d2013-02-12 14:59:23 -0500610
611 /*
612 *
613 * CPSW RGMII Internal Delay Mode is not supported in all PVT
614 * operating points. So we must set the TX clock delay feature
615 * in the AR8051 PHY. Since we only support a single ethernet
616 * device in U-Boot, we only do this for the first instance.
617 */
618#define AR8051_PHY_DEBUG_ADDR_REG 0x1d
619#define AR8051_PHY_DEBUG_DATA_REG 0x1e
620#define AR8051_DEBUG_RGMII_CLK_DLY_REG 0x5
621#define AR8051_RGMII_TX_CLK_DLY 0x100
622
Tom Rini4021fd92013-07-18 15:13:01 -0400623 if (board_is_evm_sk(&header) || board_is_gp_evm(&header)) {
Tom Rini183943d2013-02-12 14:59:23 -0500624 const char *devname;
625 devname = miiphy_get_current_dev();
626
627 miiphy_write(devname, 0x0, AR8051_PHY_DEBUG_ADDR_REG,
628 AR8051_DEBUG_RGMII_CLK_DLY_REG);
629 miiphy_write(devname, 0x0, AR8051_PHY_DEBUG_DATA_REG,
630 AR8051_RGMII_TX_CLK_DLY);
631 }
Ilya Yanok44a2c072012-11-06 13:48:24 +0000632#endif
Ilya Yanok0760a0d2013-02-05 11:36:26 +0000633#if defined(CONFIG_USB_ETHER) && \
634 (!defined(CONFIG_SPL_BUILD) || defined(CONFIG_SPL_USBETH_SUPPORT))
635 if (is_valid_ether_addr(mac_addr))
636 eth_setenv_enetaddr("usbnet_devaddr", mac_addr);
637
Ilya Yanok44a2c072012-11-06 13:48:24 +0000638 rv = usb_eth_initialize(bis);
639 if (rv < 0)
640 printf("Error %d registering USB_ETHER\n", rv);
641 else
642 n += rv;
643#endif
644 return n;
Peter Korsgaard85ec2db2012-10-18 01:21:09 +0000645}
646#endif