blob: c705b5ab0f6f63ff9f9c9a0eb085a9335fc67f76 [file] [log] [blame]
Heiko Schocher499c4982013-08-19 16:39:01 +02001/*
Egli, Samuel097951b2014-05-05 16:50:43 +02002 * Board functions for TI AM335X based draco board
Heiko Schocher499c4982013-08-19 16:39:01 +02003 * (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>
Heiko Schochercbec11a2016-06-07 08:55:45 +020027#include <asm/arch/mem.h>
Heiko Schocher499c4982013-08-19 16:39:01 +020028#include <asm/io.h>
29#include <asm/emif.h>
30#include <asm/gpio.h>
31#include <i2c.h>
32#include <miiphy.h>
33#include <cpsw.h>
34#include <watchdog.h>
35#include "board.h"
36#include "../common/factoryset.h"
Heiko Schochercbec11a2016-06-07 08:55:45 +020037#include <nand.h>
Heiko Schocher499c4982013-08-19 16:39:01 +020038
39DECLARE_GLOBAL_DATA_PTR;
40
41#ifdef CONFIG_SPL_BUILD
Egli, Samuel097951b2014-05-05 16:50:43 +020042static struct draco_baseboard_id __attribute__((section(".data"))) settings;
Egli, Samuelbc38fa42014-04-24 17:57:53 +020043
44#if DDR_PLL_FREQ == 303
Heiko Schochercbec11a2016-06-07 08:55:45 +020045#if !defined(CONFIG_TARGET_ETAMIN)
Egli, Samuelbc38fa42014-04-24 17:57:53 +020046/* Default@303MHz-i0 */
47const struct ddr3_data ddr3_default = {
48 0x33524444, 0x56312e35, 0x0080, 0x0000, 0x003A, 0x003F, 0x009F,
Heiko Schocherd17c3fc2015-06-16 14:59:34 +020049 0x0079, 0x0888A39B, 0x26517FDA, 0x501F84EF, 0x00100206, 0x61A44A32,
Egli, Samuelbc38fa42014-04-24 17:57:53 +020050 0x0000093B, 0x0000014A,
51 "default name @303MHz \0",
52 "default marking \0",
53};
Heiko Schochercbec11a2016-06-07 08:55:45 +020054#else
55/* etamin board */
56const struct ddr3_data ddr3_default = {
57 0x33524444, 0x56312e36, 0x0080, 0x0000, 0x003A, 0x0010, 0x009F,
58 0x0050, 0x0888A39B, 0x266D7FDA, 0x501F86AF, 0x00100206, 0x61A44BB2,
59 0x0000093B, 0x0000018A,
60 "test-etamin \0",
61 "generic-8Gbit \0",
62};
63#endif
Egli, Samuelbc38fa42014-04-24 17:57:53 +020064#elif DDR_PLL_FREQ == 400
65/* Default@400MHz-i0 */
Heiko Schocher499c4982013-08-19 16:39:01 +020066const struct ddr3_data ddr3_default = {
Egli, Samuelbc38fa42014-04-24 17:57:53 +020067 0x33524444, 0x56312e35, 0x0080, 0x0000, 0x0039, 0x0046, 0x00ab,
68 0x0080, 0x0AAAA4DB, 0x26307FDA, 0x501F821F, 0x00100207, 0x61A45232,
Samuel Egli8069bfe2013-11-04 14:05:03 +010069 0x00000618, 0x0000014A,
Egli, Samuelbc38fa42014-04-24 17:57:53 +020070 "default name @400MHz \0",
71 "default marking \0",
Heiko Schocher499c4982013-08-19 16:39:01 +020072};
Egli, Samuelbc38fa42014-04-24 17:57:53 +020073#endif
Heiko Schocher499c4982013-08-19 16:39:01 +020074
75static void set_default_ddr3_timings(void)
76{
77 printf("Set default DDR3 settings\n");
78 settings.ddr3 = ddr3_default;
79}
80
81static void print_ddr3_timings(void)
82{
Egli, Samuelbc38fa42014-04-24 17:57:53 +020083 printf("\nDDR3\n");
84 printf("clock:\t\t%d MHz\n", DDR_PLL_FREQ);
85 printf("device:\t\t%s\n", settings.ddr3.manu_name);
86 printf("marking:\t%s\n", settings.ddr3.manu_marking);
Heiko Schocherd17c3fc2015-06-16 14:59:34 +020087 printf("%-20s, %-8s, %-8s, %-4s\n", "timing parameters", "eeprom",
88 "default", "diff");
Heiko Schocher499c4982013-08-19 16:39:01 +020089 PRINTARGS(magic);
90 PRINTARGS(version);
91 PRINTARGS(ddr3_sratio);
92 PRINTARGS(iclkout);
93
94 PRINTARGS(dt0rdsratio0);
95 PRINTARGS(dt0wdsratio0);
96 PRINTARGS(dt0fwsratio0);
97 PRINTARGS(dt0wrsratio0);
98
99 PRINTARGS(sdram_tim1);
100 PRINTARGS(sdram_tim2);
101 PRINTARGS(sdram_tim3);
102
103 PRINTARGS(emif_ddr_phy_ctlr_1);
104
105 PRINTARGS(sdram_config);
106 PRINTARGS(ref_ctrl);
Samuel Egli8069bfe2013-11-04 14:05:03 +0100107 PRINTARGS(ioctr_val);
Heiko Schocher499c4982013-08-19 16:39:01 +0200108}
109
110static void print_chip_data(void)
111{
Heiko Schocherd17c3fc2015-06-16 14:59:34 +0200112 struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
113 dpll_mpu_opp100.m = am335x_get_efuse_mpu_max_freq(cdev);
Egli, Samuelbc38fa42014-04-24 17:57:53 +0200114 printf("\nCPU BOARD\n");
115 printf("device: \t'%s'\n", settings.chip.sdevname);
116 printf("hw version: \t'%s'\n", settings.chip.shwver);
Heiko Schocherd17c3fc2015-06-16 14:59:34 +0200117 printf("max freq: \t%d MHz\n", dpll_mpu_opp100.m);
Heiko Schocher499c4982013-08-19 16:39:01 +0200118}
119#endif /* CONFIG_SPL_BUILD */
120
Heiko Schocher4453d7a2016-06-07 08:55:43 +0200121#define AM335X_NAND_ECC_MASK 0x0f
122#define AM335X_NAND_ECC_TYPE_16 0x02
123
124static int ecc_type;
125
126struct am335x_nand_geometry {
127 u32 magic;
128 u8 nand_geo_addr;
129 u8 nand_geo_page;
130 u8 nand_bus;
131};
132
133static int draco_read_nand_geometry(void)
134{
135 struct am335x_nand_geometry geo;
136
137 /* Read NAND geometry */
138 if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0x80, 2,
139 (uchar *)&geo, sizeof(struct am335x_nand_geometry))) {
140 printf("Could not read the NAND geomtery; something fundamentally wrong on the I2C bus.\n");
141 return -EIO;
142 }
143 if (geo.magic != 0xa657b310) {
144 printf("%s: bad magic: %x\n", __func__, geo.magic);
145 return -EFAULT;
146 }
147 if ((geo.nand_bus & AM335X_NAND_ECC_MASK) == AM335X_NAND_ECC_TYPE_16)
148 ecc_type = 16;
149 else
150 ecc_type = 8;
151
152 return 0;
153}
154
Heiko Schocher499c4982013-08-19 16:39:01 +0200155/*
156 * Read header information from EEPROM into global structure.
157 */
158static int read_eeprom(void)
159{
160 /* Check if baseboard eeprom is available */
161 if (i2c_probe(CONFIG_SYS_I2C_EEPROM_ADDR)) {
162 printf("Could not probe the EEPROM; something fundamentally wrong on the I2C bus.\n");
163 return 1;
164 }
165
166#ifdef CONFIG_SPL_BUILD
167 /* Read Siemens eeprom data (DDR3) */
168 if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, EEPROM_ADDR_DDR3, 2,
169 (uchar *)&settings.ddr3, sizeof(struct ddr3_data))) {
170 printf("Could not read the EEPROM; something fundamentally wrong on the I2C bus.\nUse default DDR3 timings\n");
171 set_default_ddr3_timings();
172 }
173 /* Read Siemens eeprom data (CHIP) */
174 if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, EEPROM_ADDR_CHIP, 2,
175 (uchar *)&settings.chip, sizeof(settings.chip)))
176 printf("Could not read chip settings\n");
177
178 if (ddr3_default.magic == settings.ddr3.magic &&
179 ddr3_default.version == settings.ddr3.version) {
180 printf("Using DDR3 settings from EEPROM\n");
181 } else {
182 if (ddr3_default.magic != settings.ddr3.magic)
Egli, Samuelbc38fa42014-04-24 17:57:53 +0200183 printf("Warning: No valid DDR3 data in eeprom.\n");
Heiko Schocher499c4982013-08-19 16:39:01 +0200184 if (ddr3_default.version != settings.ddr3.version)
Egli, Samuelbc38fa42014-04-24 17:57:53 +0200185 printf("Warning: DDR3 data version does not match.\n");
Heiko Schocher499c4982013-08-19 16:39:01 +0200186
187 printf("Using default settings\n");
188 set_default_ddr3_timings();
189 }
190
Egli, Samuel097951b2014-05-05 16:50:43 +0200191 if (MAGIC_CHIP == settings.chip.magic)
Heiko Schocher499c4982013-08-19 16:39:01 +0200192 print_chip_data();
Egli, Samuel097951b2014-05-05 16:50:43 +0200193 else
Egli, Samuelbc38fa42014-04-24 17:57:53 +0200194 printf("Warning: No chip data in eeprom\n");
Heiko Schocher499c4982013-08-19 16:39:01 +0200195
196 print_ddr3_timings();
Heiko Schocher4453d7a2016-06-07 08:55:43 +0200197
198 return draco_read_nand_geometry();
Heiko Schocher499c4982013-08-19 16:39:01 +0200199#endif
200 return 0;
201}
202
203#ifdef CONFIG_SPL_BUILD
204static void board_init_ddr(void)
205{
Egli, Samuel097951b2014-05-05 16:50:43 +0200206struct emif_regs draco_ddr3_emif_reg_data = {
Heiko Schocher499c4982013-08-19 16:39:01 +0200207 .zq_config = 0x50074BE4,
208};
209
Egli, Samuel097951b2014-05-05 16:50:43 +0200210struct ddr_data draco_ddr3_data = {
Heiko Schocher499c4982013-08-19 16:39:01 +0200211};
212
Egli, Samuel097951b2014-05-05 16:50:43 +0200213struct cmd_control draco_ddr3_cmd_ctrl_data = {
Heiko Schocher499c4982013-08-19 16:39:01 +0200214};
Lokesh Vutla303b2672013-12-10 15:02:21 +0530215
Egli, Samuel097951b2014-05-05 16:50:43 +0200216struct ctrl_ioregs draco_ddr3_ioregs = {
Lokesh Vutla303b2672013-12-10 15:02:21 +0530217};
218
Heiko Schocher499c4982013-08-19 16:39:01 +0200219 /* pass values from eeprom */
Egli, Samuel097951b2014-05-05 16:50:43 +0200220 draco_ddr3_emif_reg_data.sdram_tim1 = settings.ddr3.sdram_tim1;
221 draco_ddr3_emif_reg_data.sdram_tim2 = settings.ddr3.sdram_tim2;
222 draco_ddr3_emif_reg_data.sdram_tim3 = settings.ddr3.sdram_tim3;
223 draco_ddr3_emif_reg_data.emif_ddr_phy_ctlr_1 =
Heiko Schocher499c4982013-08-19 16:39:01 +0200224 settings.ddr3.emif_ddr_phy_ctlr_1;
Egli, Samuel097951b2014-05-05 16:50:43 +0200225 draco_ddr3_emif_reg_data.sdram_config = settings.ddr3.sdram_config;
Heiko Schochercbec11a2016-06-07 08:55:45 +0200226 draco_ddr3_emif_reg_data.sdram_config2 = 0x08000000;
Egli, Samuel097951b2014-05-05 16:50:43 +0200227 draco_ddr3_emif_reg_data.ref_ctrl = settings.ddr3.ref_ctrl;
Heiko Schocher499c4982013-08-19 16:39:01 +0200228
Egli, Samuel097951b2014-05-05 16:50:43 +0200229 draco_ddr3_data.datardsratio0 = settings.ddr3.dt0rdsratio0;
230 draco_ddr3_data.datawdsratio0 = settings.ddr3.dt0wdsratio0;
231 draco_ddr3_data.datafwsratio0 = settings.ddr3.dt0fwsratio0;
232 draco_ddr3_data.datawrsratio0 = settings.ddr3.dt0wrsratio0;
Heiko Schocher499c4982013-08-19 16:39:01 +0200233
Egli, Samuel097951b2014-05-05 16:50:43 +0200234 draco_ddr3_cmd_ctrl_data.cmd0csratio = settings.ddr3.ddr3_sratio;
235 draco_ddr3_cmd_ctrl_data.cmd0iclkout = settings.ddr3.iclkout;
236 draco_ddr3_cmd_ctrl_data.cmd1csratio = settings.ddr3.ddr3_sratio;
237 draco_ddr3_cmd_ctrl_data.cmd1iclkout = settings.ddr3.iclkout;
238 draco_ddr3_cmd_ctrl_data.cmd2csratio = settings.ddr3.ddr3_sratio;
239 draco_ddr3_cmd_ctrl_data.cmd2iclkout = settings.ddr3.iclkout;
Heiko Schocher499c4982013-08-19 16:39:01 +0200240
Egli, Samuel097951b2014-05-05 16:50:43 +0200241 draco_ddr3_ioregs.cm0ioctl = settings.ddr3.ioctr_val,
242 draco_ddr3_ioregs.cm1ioctl = settings.ddr3.ioctr_val,
243 draco_ddr3_ioregs.cm2ioctl = settings.ddr3.ioctr_val,
244 draco_ddr3_ioregs.dt0ioctl = settings.ddr3.ioctr_val,
245 draco_ddr3_ioregs.dt1ioctl = settings.ddr3.ioctr_val,
Lokesh Vutla303b2672013-12-10 15:02:21 +0530246
Egli, Samuel097951b2014-05-05 16:50:43 +0200247 config_ddr(DDR_PLL_FREQ, &draco_ddr3_ioregs, &draco_ddr3_data,
248 &draco_ddr3_cmd_ctrl_data, &draco_ddr3_emif_reg_data, 0);
Heiko Schocher499c4982013-08-19 16:39:01 +0200249}
250
251static void spl_siemens_board_init(void)
252{
253 return;
254}
255#endif /* if def CONFIG_SPL_BUILD */
256
Heiko Schocherd17c3fc2015-06-16 14:59:34 +0200257#ifdef CONFIG_BOARD_LATE_INIT
258int board_late_init(void)
259{
Heiko Schocher4453d7a2016-06-07 08:55:43 +0200260 int ret;
261
262 ret = draco_read_nand_geometry();
263 if (ret != 0)
264 return ret;
265
266 nand_curr_device = 0;
267 omap_nand_switch_ecc(1, ecc_type);
Heiko Schochercbec11a2016-06-07 08:55:45 +0200268#ifdef CONFIG_TARGET_ETAMIN
269 nand_curr_device = 1;
270 omap_nand_switch_ecc(1, ecc_type);
271#endif
Heiko Schocherd17c3fc2015-06-16 14:59:34 +0200272#ifdef CONFIG_FACTORYSET
273 /* Set ASN in environment*/
274 if (factory_dat.asn[0] != 0) {
Simon Glass6a38e412017-08-03 12:22:09 -0600275 env_set("dtb_name", (char *)factory_dat.asn);
Heiko Schocherd17c3fc2015-06-16 14:59:34 +0200276 } else {
277 /* dtb suffix gets added in load script */
Simon Glass6a38e412017-08-03 12:22:09 -0600278 env_set("dtb_name", "am335x-draco");
Heiko Schocherd17c3fc2015-06-16 14:59:34 +0200279 }
280#else
Simon Glass6a38e412017-08-03 12:22:09 -0600281 env_set("dtb_name", "am335x-draco");
Heiko Schocherd17c3fc2015-06-16 14:59:34 +0200282#endif
283
284 return 0;
285}
286#endif
287
Heiko Schocher499c4982013-08-19 16:39:01 +0200288#if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) || \
289 (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD))
290static void cpsw_control(int enabled)
291{
292 /* VTP can be added here */
293
294 return;
295}
296
297static struct cpsw_slave_data cpsw_slaves[] = {
298 {
299 .slave_reg_ofs = 0x208,
300 .sliver_reg_ofs = 0xd80,
Mugunthan V N4944f372014-02-18 07:31:52 -0500301 .phy_addr = 0,
Heiko Schocher499c4982013-08-19 16:39:01 +0200302 .phy_if = PHY_INTERFACE_MODE_MII,
303 },
304};
305
306static struct cpsw_platform_data cpsw_data = {
307 .mdio_base = CPSW_MDIO_BASE,
308 .cpsw_base = CPSW_BASE,
309 .mdio_div = 0xff,
310 .channels = 4,
311 .cpdma_reg_ofs = 0x800,
312 .slaves = 1,
313 .slave_data = cpsw_slaves,
314 .ale_reg_ofs = 0xd00,
315 .ale_entries = 1024,
316 .host_port_reg_ofs = 0x108,
317 .hw_stats_reg_ofs = 0x900,
318 .bd_ram_ofs = 0x2000,
319 .mac_control = (1 << 5),
320 .control = cpsw_control,
321 .host_port_num = 0,
322 .version = CPSW_CTRL_VERSION_2,
323};
324
325#if defined(CONFIG_DRIVER_TI_CPSW) || \
Paul Kocialkowskif34dfcb2015-08-04 17:04:06 +0200326 (defined(CONFIG_USB_ETHER) && defined(CONFIG_USB_MUSB_GADGET))
Heiko Schocher499c4982013-08-19 16:39:01 +0200327int board_eth_init(bd_t *bis)
328{
329 struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
330 int n = 0;
331 int rv;
332
Simon Glass6a38e412017-08-03 12:22:09 -0600333 factoryset_env_set();
Heiko Schocher499c4982013-08-19 16:39:01 +0200334
Heiko Schocher499c4982013-08-19 16:39:01 +0200335 /* Set rgmii mode and enable rmii clock to be sourced from chip */
336 writel((RMII_MODE_ENABLE | RMII_CHIPCKL_ENABLE), &cdev->miisel);
337
338 rv = cpsw_register(&cpsw_data);
339 if (rv < 0)
340 printf("Error %d registering CPSW switch\n", rv);
341 else
342 n += rv;
343 return n;
344}
Stefan Roese9aee57f2014-03-12 10:45:41 +0100345
346static int do_switch_reset(cmd_tbl_t *cmdtp, int flag, int argc,
Heiko Schochercbec11a2016-06-07 08:55:45 +0200347 char *const argv[])
Stefan Roese9aee57f2014-03-12 10:45:41 +0100348{
349 /* Reset SMSC LAN9303 switch for default configuration */
350 gpio_request(GPIO_LAN9303_NRST, "nRST");
351 gpio_direction_output(GPIO_LAN9303_NRST, 0);
352 /* assert active low reset for 200us */
353 udelay(200);
354 gpio_set_value(GPIO_LAN9303_NRST, 1);
355
356 return 0;
357};
358
359U_BOOT_CMD(
360 switch_rst, CONFIG_SYS_MAXARGS, 1, do_switch_reset,
361 "Reset LAN9303 switch via its reset pin",
362 ""
363);
Heiko Schocher499c4982013-08-19 16:39:01 +0200364#endif /* #if defined(CONFIG_DRIVER_TI_CPSW) */
365#endif /* #if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) */
366
Heiko Schochercbec11a2016-06-07 08:55:45 +0200367#ifdef CONFIG_NAND_CS_INIT
368/* GPMC definitions for second nand cs1 */
369static const u32 gpmc_nand_config[] = {
370 ETAMIN_NAND_GPMC_CONFIG1,
371 ETAMIN_NAND_GPMC_CONFIG2,
372 ETAMIN_NAND_GPMC_CONFIG3,
373 ETAMIN_NAND_GPMC_CONFIG4,
374 ETAMIN_NAND_GPMC_CONFIG5,
375 ETAMIN_NAND_GPMC_CONFIG6,
376 /*CONFIG7- computed as params */
377};
378
379static void board_nand_cs_init(void)
380{
381 enable_gpmc_cs_config(gpmc_nand_config, &gpmc_cfg->cs[1],
382 0x18000000, GPMC_SIZE_16M);
383}
384#endif
385
Heiko Schocher499c4982013-08-19 16:39:01 +0200386#include "../common/board.c"