blob: 3a5e11dc816d7fc107de7252262ab06ac2d4d2a1 [file] [log] [blame]
Heiko Schocherc0dcece2013-08-19 16:39:01 +02001/*
2 * Board functions for TI AM335X based dxr2 board
3 * (C) Copyright 2013 Siemens Schweiz AG
4 * (C) Heiko Schocher, DENX Software Engineering, hs@denx.de.
5 *
6 * Based on:
7 *
8 * Board functions for TI AM335X based boards
9 * u-boot:/board/ti/am335x/board.c
10 *
11 * Copyright (C) 2011, Texas Instruments, Incorporated - http://www.ti.com/
12 *
13 * SPDX-License-Identifier: GPL-2.0+
14 */
15
16#include <common.h>
17#include <errno.h>
18#include <spl.h>
19#include <asm/arch/cpu.h>
20#include <asm/arch/hardware.h>
21#include <asm/arch/omap.h>
22#include <asm/arch/ddr_defs.h>
23#include <asm/arch/clock.h>
24#include <asm/arch/gpio.h>
25#include <asm/arch/mmc_host_def.h>
26#include <asm/arch/sys_proto.h>
27#include <asm/io.h>
28#include <asm/emif.h>
29#include <asm/gpio.h>
30#include <i2c.h>
31#include <miiphy.h>
32#include <cpsw.h>
33#include <watchdog.h>
34#include "board.h"
35#include "../common/factoryset.h"
36
37DECLARE_GLOBAL_DATA_PTR;
38
39#ifdef CONFIG_SPL_BUILD
40static struct dxr2_baseboard_id __attribute__((section(".data"))) settings;
Samuel Egli56eb3da2013-11-04 14:05:03 +010041/* @303MHz-i0 */
Heiko Schocherc0dcece2013-08-19 16:39:01 +020042const struct ddr3_data ddr3_default = {
Samuel Egli56eb3da2013-11-04 14:05:03 +010043 0x33524444, 0x56312e34, 0x0080, 0x0000, 0x0038, 0x003E, 0x00A4,
44 0x0075, 0x0888A39B, 0x26247FDA, 0x501F821F, 0x00100206, 0x61A44A32,
45 0x00000618, 0x0000014A,
Heiko Schocherc0dcece2013-08-19 16:39:01 +020046};
47
48static void set_default_ddr3_timings(void)
49{
50 printf("Set default DDR3 settings\n");
51 settings.ddr3 = ddr3_default;
52}
53
54static void print_ddr3_timings(void)
55{
56 printf("\n\nDDR3 Timing parameters:\n");
57 printf("Diff Eeprom Default\n");
58 PRINTARGS(magic);
59 PRINTARGS(version);
60 PRINTARGS(ddr3_sratio);
61 PRINTARGS(iclkout);
62
63 PRINTARGS(dt0rdsratio0);
64 PRINTARGS(dt0wdsratio0);
65 PRINTARGS(dt0fwsratio0);
66 PRINTARGS(dt0wrsratio0);
67
68 PRINTARGS(sdram_tim1);
69 PRINTARGS(sdram_tim2);
70 PRINTARGS(sdram_tim3);
71
72 PRINTARGS(emif_ddr_phy_ctlr_1);
73
74 PRINTARGS(sdram_config);
75 PRINTARGS(ref_ctrl);
Samuel Egli56eb3da2013-11-04 14:05:03 +010076 PRINTARGS(ioctr_val);
Heiko Schocherc0dcece2013-08-19 16:39:01 +020077}
78
79static void print_chip_data(void)
80{
81 printf("\n");
82 printf("Device: '%s'\n", settings.chip.sdevname);
83 printf("HW version: '%s'\n", settings.chip.shwver);
84}
85#endif /* CONFIG_SPL_BUILD */
86
87/*
88 * Read header information from EEPROM into global structure.
89 */
90static int read_eeprom(void)
91{
92 /* Check if baseboard eeprom is available */
93 if (i2c_probe(CONFIG_SYS_I2C_EEPROM_ADDR)) {
94 printf("Could not probe the EEPROM; something fundamentally wrong on the I2C bus.\n");
95 return 1;
96 }
97
98#ifdef CONFIG_SPL_BUILD
99 /* Read Siemens eeprom data (DDR3) */
100 if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, EEPROM_ADDR_DDR3, 2,
101 (uchar *)&settings.ddr3, sizeof(struct ddr3_data))) {
102 printf("Could not read the EEPROM; something fundamentally wrong on the I2C bus.\nUse default DDR3 timings\n");
103 set_default_ddr3_timings();
104 }
105 /* Read Siemens eeprom data (CHIP) */
106 if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, EEPROM_ADDR_CHIP, 2,
107 (uchar *)&settings.chip, sizeof(settings.chip)))
108 printf("Could not read chip settings\n");
109
110 if (ddr3_default.magic == settings.ddr3.magic &&
111 ddr3_default.version == settings.ddr3.version) {
112 printf("Using DDR3 settings from EEPROM\n");
113 } else {
114 if (ddr3_default.magic != settings.ddr3.magic)
115 printf("Error: No valid DDR3 data in eeprom.\n");
116 if (ddr3_default.version != settings.ddr3.version)
117 printf("Error: DDR3 data version does not match.\n");
118
119 printf("Using default settings\n");
120 set_default_ddr3_timings();
121 }
122
123 if (MAGIC_CHIP == settings.chip.magic) {
124 printf("Valid chip data in eeprom\n");
125 print_chip_data();
126 } else {
127 printf("Error: No chip data in eeprom\n");
128 }
129
130 print_ddr3_timings();
131#endif
132 return 0;
133}
134
135#ifdef CONFIG_SPL_BUILD
136static void board_init_ddr(void)
137{
138struct emif_regs dxr2_ddr3_emif_reg_data = {
139 .zq_config = 0x50074BE4,
140};
141
142struct ddr_data dxr2_ddr3_data = {
Heiko Schocherc0dcece2013-08-19 16:39:01 +0200143};
144
145struct cmd_control dxr2_ddr3_cmd_ctrl_data = {
Heiko Schocherc0dcece2013-08-19 16:39:01 +0200146};
147 /* pass values from eeprom */
148 dxr2_ddr3_emif_reg_data.sdram_tim1 = settings.ddr3.sdram_tim1;
149 dxr2_ddr3_emif_reg_data.sdram_tim2 = settings.ddr3.sdram_tim2;
150 dxr2_ddr3_emif_reg_data.sdram_tim3 = settings.ddr3.sdram_tim3;
151 dxr2_ddr3_emif_reg_data.emif_ddr_phy_ctlr_1 =
152 settings.ddr3.emif_ddr_phy_ctlr_1;
153 dxr2_ddr3_emif_reg_data.sdram_config = settings.ddr3.sdram_config;
154 dxr2_ddr3_emif_reg_data.ref_ctrl = settings.ddr3.ref_ctrl;
155
156 dxr2_ddr3_data.datardsratio0 = settings.ddr3.dt0rdsratio0;
157 dxr2_ddr3_data.datawdsratio0 = settings.ddr3.dt0wdsratio0;
158 dxr2_ddr3_data.datafwsratio0 = settings.ddr3.dt0fwsratio0;
159 dxr2_ddr3_data.datawrsratio0 = settings.ddr3.dt0wrsratio0;
160
161 dxr2_ddr3_cmd_ctrl_data.cmd0csratio = settings.ddr3.ddr3_sratio;
162 dxr2_ddr3_cmd_ctrl_data.cmd0iclkout = settings.ddr3.iclkout;
163 dxr2_ddr3_cmd_ctrl_data.cmd1csratio = settings.ddr3.ddr3_sratio;
164 dxr2_ddr3_cmd_ctrl_data.cmd1iclkout = settings.ddr3.iclkout;
165 dxr2_ddr3_cmd_ctrl_data.cmd2csratio = settings.ddr3.ddr3_sratio;
166 dxr2_ddr3_cmd_ctrl_data.cmd2iclkout = settings.ddr3.iclkout;
167
Samuel Egli56eb3da2013-11-04 14:05:03 +0100168 config_ddr(DDR_PLL_FREQ, settings.ddr3.ioctr_val, &dxr2_ddr3_data,
Heiko Schocherc0dcece2013-08-19 16:39:01 +0200169 &dxr2_ddr3_cmd_ctrl_data, &dxr2_ddr3_emif_reg_data, 0);
170}
171
172static void spl_siemens_board_init(void)
173{
174 return;
175}
176#endif /* if def CONFIG_SPL_BUILD */
177
178#if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) || \
179 (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD))
180static void cpsw_control(int enabled)
181{
182 /* VTP can be added here */
183
184 return;
185}
186
187static struct cpsw_slave_data cpsw_slaves[] = {
188 {
189 .slave_reg_ofs = 0x208,
190 .sliver_reg_ofs = 0xd80,
191 .phy_id = 0,
192 .phy_if = PHY_INTERFACE_MODE_MII,
193 },
194};
195
196static struct cpsw_platform_data cpsw_data = {
197 .mdio_base = CPSW_MDIO_BASE,
198 .cpsw_base = CPSW_BASE,
199 .mdio_div = 0xff,
200 .channels = 4,
201 .cpdma_reg_ofs = 0x800,
202 .slaves = 1,
203 .slave_data = cpsw_slaves,
204 .ale_reg_ofs = 0xd00,
205 .ale_entries = 1024,
206 .host_port_reg_ofs = 0x108,
207 .hw_stats_reg_ofs = 0x900,
208 .bd_ram_ofs = 0x2000,
209 .mac_control = (1 << 5),
210 .control = cpsw_control,
211 .host_port_num = 0,
212 .version = CPSW_CTRL_VERSION_2,
213};
214
215#if defined(CONFIG_DRIVER_TI_CPSW) || \
216 (defined(CONFIG_USB_ETHER) && defined(CONFIG_MUSB_GADGET))
217int board_eth_init(bd_t *bis)
218{
219 struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
220 int n = 0;
221 int rv;
222
223 factoryset_setenv();
224
225 /* Set rgmii mode and enable rmii clock to be sourced from chip */
226 writel((RMII_MODE_ENABLE | RMII_CHIPCKL_ENABLE), &cdev->miisel);
227
228 rv = cpsw_register(&cpsw_data);
229 if (rv < 0)
230 printf("Error %d registering CPSW switch\n", rv);
231 else
232 n += rv;
233 return n;
234}
235#endif /* #if defined(CONFIG_DRIVER_TI_CPSW) */
236#endif /* #if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) */
237
238#include "../common/board.c"