blob: a6840b895b2753c347e6d9815f1ad835fb36c932 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Heiko Schocherc0dcece2013-08-19 16:39:01 +02002/*
Egli, Samuel820969f2014-05-05 16:50:43 +02003 * Board functions for TI AM335X based draco board
Heiko Schocherc0dcece2013-08-19 16:39:01 +02004 * (C) Copyright 2013 Siemens Schweiz AG
5 * (C) Heiko Schocher, DENX Software Engineering, hs@denx.de.
6 *
7 * Based on:
8 *
9 * Board functions for TI AM335X based boards
10 * u-boot:/board/ti/am335x/board.c
11 *
12 * Copyright (C) 2011, Texas Instruments, Incorporated - http://www.ti.com/
Heiko Schocherc0dcece2013-08-19 16:39:01 +020013 */
14
15#include <common.h>
Simon Glass9fb625c2019-08-01 09:46:51 -060016#include <env.h>
Heiko Schocherc0dcece2013-08-19 16:39:01 +020017#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 Schocher6b3943f2016-06-07 08:55:45 +020027#include <asm/arch/mem.h>
Heiko Schocherc0dcece2013-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 Schocher6b3943f2016-06-07 08:55:45 +020037#include <nand.h>
Heiko Schocherc0dcece2013-08-19 16:39:01 +020038
Heiko Schocherc0dcece2013-08-19 16:39:01 +020039#ifdef CONFIG_SPL_BUILD
Egli, Samuel820969f2014-05-05 16:50:43 +020040static struct draco_baseboard_id __attribute__((section(".data"))) settings;
Egli, Samuel823b2c42014-04-24 17:57:53 +020041
42#if DDR_PLL_FREQ == 303
Heiko Schocher6b3943f2016-06-07 08:55:45 +020043#if !defined(CONFIG_TARGET_ETAMIN)
Egli, Samuel823b2c42014-04-24 17:57:53 +020044/* Default@303MHz-i0 */
Heiko Schocherc0dcece2013-08-19 16:39:01 +020045const struct ddr3_data ddr3_default = {
Egli, Samuel823b2c42014-04-24 17:57:53 +020046 0x33524444, 0x56312e35, 0x0080, 0x0000, 0x003A, 0x003F, 0x009F,
Heiko Schocher61159b72015-06-16 14:59:34 +020047 0x0079, 0x0888A39B, 0x26517FDA, 0x501F84EF, 0x00100206, 0x61A44A32,
Egli, Samuel823b2c42014-04-24 17:57:53 +020048 0x0000093B, 0x0000014A,
49 "default name @303MHz \0",
50 "default marking \0",
Heiko Schocherc0dcece2013-08-19 16:39:01 +020051};
Heiko Schocher6b3943f2016-06-07 08:55:45 +020052#else
53/* etamin board */
54const struct ddr3_data ddr3_default = {
55 0x33524444, 0x56312e36, 0x0080, 0x0000, 0x003A, 0x0010, 0x009F,
56 0x0050, 0x0888A39B, 0x266D7FDA, 0x501F86AF, 0x00100206, 0x61A44BB2,
57 0x0000093B, 0x0000018A,
58 "test-etamin \0",
59 "generic-8Gbit \0",
60};
61#endif
Egli, Samuel823b2c42014-04-24 17:57:53 +020062#elif DDR_PLL_FREQ == 400
63/* Default@400MHz-i0 */
64const struct ddr3_data ddr3_default = {
65 0x33524444, 0x56312e35, 0x0080, 0x0000, 0x0039, 0x0046, 0x00ab,
66 0x0080, 0x0AAAA4DB, 0x26307FDA, 0x501F821F, 0x00100207, 0x61A45232,
67 0x00000618, 0x0000014A,
68 "default name @400MHz \0",
69 "default marking \0",
70};
71#endif
Heiko Schocherc0dcece2013-08-19 16:39:01 +020072
73static void set_default_ddr3_timings(void)
74{
75 printf("Set default DDR3 settings\n");
76 settings.ddr3 = ddr3_default;
77}
78
79static void print_ddr3_timings(void)
80{
Egli, Samuel823b2c42014-04-24 17:57:53 +020081 printf("\nDDR3\n");
82 printf("clock:\t\t%d MHz\n", DDR_PLL_FREQ);
83 printf("device:\t\t%s\n", settings.ddr3.manu_name);
84 printf("marking:\t%s\n", settings.ddr3.manu_marking);
Heiko Schocher61159b72015-06-16 14:59:34 +020085 printf("%-20s, %-8s, %-8s, %-4s\n", "timing parameters", "eeprom",
86 "default", "diff");
Heiko Schocherc0dcece2013-08-19 16:39:01 +020087 PRINTARGS(magic);
88 PRINTARGS(version);
89 PRINTARGS(ddr3_sratio);
90 PRINTARGS(iclkout);
91
92 PRINTARGS(dt0rdsratio0);
93 PRINTARGS(dt0wdsratio0);
94 PRINTARGS(dt0fwsratio0);
95 PRINTARGS(dt0wrsratio0);
96
97 PRINTARGS(sdram_tim1);
98 PRINTARGS(sdram_tim2);
99 PRINTARGS(sdram_tim3);
100
101 PRINTARGS(emif_ddr_phy_ctlr_1);
102
103 PRINTARGS(sdram_config);
104 PRINTARGS(ref_ctrl);
Samuel Egli56eb3da2013-11-04 14:05:03 +0100105 PRINTARGS(ioctr_val);
Heiko Schocherc0dcece2013-08-19 16:39:01 +0200106}
107
108static void print_chip_data(void)
109{
Heiko Schocher61159b72015-06-16 14:59:34 +0200110 struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
111 dpll_mpu_opp100.m = am335x_get_efuse_mpu_max_freq(cdev);
Egli, Samuel823b2c42014-04-24 17:57:53 +0200112 printf("\nCPU BOARD\n");
113 printf("device: \t'%s'\n", settings.chip.sdevname);
114 printf("hw version: \t'%s'\n", settings.chip.shwver);
Heiko Schocher61159b72015-06-16 14:59:34 +0200115 printf("max freq: \t%d MHz\n", dpll_mpu_opp100.m);
Heiko Schocherc0dcece2013-08-19 16:39:01 +0200116}
117#endif /* CONFIG_SPL_BUILD */
118
Heiko Schocher02b11f12016-06-07 08:55:43 +0200119#define AM335X_NAND_ECC_MASK 0x0f
120#define AM335X_NAND_ECC_TYPE_16 0x02
121
122static int ecc_type;
123
124struct am335x_nand_geometry {
125 u32 magic;
126 u8 nand_geo_addr;
127 u8 nand_geo_page;
128 u8 nand_bus;
129};
130
131static int draco_read_nand_geometry(void)
132{
133 struct am335x_nand_geometry geo;
134
135 /* Read NAND geometry */
136 if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0x80, 2,
137 (uchar *)&geo, sizeof(struct am335x_nand_geometry))) {
138 printf("Could not read the NAND geomtery; something fundamentally wrong on the I2C bus.\n");
139 return -EIO;
140 }
141 if (geo.magic != 0xa657b310) {
142 printf("%s: bad magic: %x\n", __func__, geo.magic);
143 return -EFAULT;
144 }
145 if ((geo.nand_bus & AM335X_NAND_ECC_MASK) == AM335X_NAND_ECC_TYPE_16)
146 ecc_type = 16;
147 else
148 ecc_type = 8;
149
150 return 0;
151}
152
Heiko Schocherc0dcece2013-08-19 16:39:01 +0200153/*
154 * Read header information from EEPROM into global structure.
155 */
156static int read_eeprom(void)
157{
158 /* Check if baseboard eeprom is available */
159 if (i2c_probe(CONFIG_SYS_I2C_EEPROM_ADDR)) {
160 printf("Could not probe the EEPROM; something fundamentally wrong on the I2C bus.\n");
161 return 1;
162 }
163
164#ifdef CONFIG_SPL_BUILD
165 /* Read Siemens eeprom data (DDR3) */
166 if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, EEPROM_ADDR_DDR3, 2,
167 (uchar *)&settings.ddr3, sizeof(struct ddr3_data))) {
168 printf("Could not read the EEPROM; something fundamentally wrong on the I2C bus.\nUse default DDR3 timings\n");
169 set_default_ddr3_timings();
170 }
171 /* Read Siemens eeprom data (CHIP) */
172 if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, EEPROM_ADDR_CHIP, 2,
173 (uchar *)&settings.chip, sizeof(settings.chip)))
174 printf("Could not read chip settings\n");
175
176 if (ddr3_default.magic == settings.ddr3.magic &&
177 ddr3_default.version == settings.ddr3.version) {
178 printf("Using DDR3 settings from EEPROM\n");
179 } else {
180 if (ddr3_default.magic != settings.ddr3.magic)
Egli, Samuel823b2c42014-04-24 17:57:53 +0200181 printf("Warning: No valid DDR3 data in eeprom.\n");
Heiko Schocherc0dcece2013-08-19 16:39:01 +0200182 if (ddr3_default.version != settings.ddr3.version)
Egli, Samuel823b2c42014-04-24 17:57:53 +0200183 printf("Warning: DDR3 data version does not match.\n");
Heiko Schocherc0dcece2013-08-19 16:39:01 +0200184
185 printf("Using default settings\n");
186 set_default_ddr3_timings();
187 }
188
Egli, Samuel820969f2014-05-05 16:50:43 +0200189 if (MAGIC_CHIP == settings.chip.magic)
Heiko Schocherc0dcece2013-08-19 16:39:01 +0200190 print_chip_data();
Egli, Samuel820969f2014-05-05 16:50:43 +0200191 else
Egli, Samuel823b2c42014-04-24 17:57:53 +0200192 printf("Warning: No chip data in eeprom\n");
Heiko Schocherc0dcece2013-08-19 16:39:01 +0200193
194 print_ddr3_timings();
Heiko Schocher02b11f12016-06-07 08:55:43 +0200195
196 return draco_read_nand_geometry();
Heiko Schocherc0dcece2013-08-19 16:39:01 +0200197#endif
198 return 0;
199}
200
201#ifdef CONFIG_SPL_BUILD
202static void board_init_ddr(void)
203{
Egli, Samuel820969f2014-05-05 16:50:43 +0200204struct emif_regs draco_ddr3_emif_reg_data = {
Heiko Schocherc0dcece2013-08-19 16:39:01 +0200205 .zq_config = 0x50074BE4,
206};
207
Egli, Samuel820969f2014-05-05 16:50:43 +0200208struct ddr_data draco_ddr3_data = {
Heiko Schocherc0dcece2013-08-19 16:39:01 +0200209};
210
Egli, Samuel820969f2014-05-05 16:50:43 +0200211struct cmd_control draco_ddr3_cmd_ctrl_data = {
Heiko Schocherc0dcece2013-08-19 16:39:01 +0200212};
Lokesh Vutla965de8b2013-12-10 15:02:21 +0530213
Egli, Samuel820969f2014-05-05 16:50:43 +0200214struct ctrl_ioregs draco_ddr3_ioregs = {
Lokesh Vutla965de8b2013-12-10 15:02:21 +0530215};
216
Heiko Schocherc0dcece2013-08-19 16:39:01 +0200217 /* pass values from eeprom */
Egli, Samuel820969f2014-05-05 16:50:43 +0200218 draco_ddr3_emif_reg_data.sdram_tim1 = settings.ddr3.sdram_tim1;
219 draco_ddr3_emif_reg_data.sdram_tim2 = settings.ddr3.sdram_tim2;
220 draco_ddr3_emif_reg_data.sdram_tim3 = settings.ddr3.sdram_tim3;
221 draco_ddr3_emif_reg_data.emif_ddr_phy_ctlr_1 =
Heiko Schocherc0dcece2013-08-19 16:39:01 +0200222 settings.ddr3.emif_ddr_phy_ctlr_1;
Egli, Samuel820969f2014-05-05 16:50:43 +0200223 draco_ddr3_emif_reg_data.sdram_config = settings.ddr3.sdram_config;
Heiko Schocher6b3943f2016-06-07 08:55:45 +0200224 draco_ddr3_emif_reg_data.sdram_config2 = 0x08000000;
Egli, Samuel820969f2014-05-05 16:50:43 +0200225 draco_ddr3_emif_reg_data.ref_ctrl = settings.ddr3.ref_ctrl;
Heiko Schocherc0dcece2013-08-19 16:39:01 +0200226
Egli, Samuel820969f2014-05-05 16:50:43 +0200227 draco_ddr3_data.datardsratio0 = settings.ddr3.dt0rdsratio0;
228 draco_ddr3_data.datawdsratio0 = settings.ddr3.dt0wdsratio0;
229 draco_ddr3_data.datafwsratio0 = settings.ddr3.dt0fwsratio0;
230 draco_ddr3_data.datawrsratio0 = settings.ddr3.dt0wrsratio0;
Heiko Schocherc0dcece2013-08-19 16:39:01 +0200231
Egli, Samuel820969f2014-05-05 16:50:43 +0200232 draco_ddr3_cmd_ctrl_data.cmd0csratio = settings.ddr3.ddr3_sratio;
233 draco_ddr3_cmd_ctrl_data.cmd0iclkout = settings.ddr3.iclkout;
234 draco_ddr3_cmd_ctrl_data.cmd1csratio = settings.ddr3.ddr3_sratio;
235 draco_ddr3_cmd_ctrl_data.cmd1iclkout = settings.ddr3.iclkout;
236 draco_ddr3_cmd_ctrl_data.cmd2csratio = settings.ddr3.ddr3_sratio;
237 draco_ddr3_cmd_ctrl_data.cmd2iclkout = settings.ddr3.iclkout;
Heiko Schocherc0dcece2013-08-19 16:39:01 +0200238
Egli, Samuel820969f2014-05-05 16:50:43 +0200239 draco_ddr3_ioregs.cm0ioctl = settings.ddr3.ioctr_val,
240 draco_ddr3_ioregs.cm1ioctl = settings.ddr3.ioctr_val,
241 draco_ddr3_ioregs.cm2ioctl = settings.ddr3.ioctr_val,
242 draco_ddr3_ioregs.dt0ioctl = settings.ddr3.ioctr_val,
243 draco_ddr3_ioregs.dt1ioctl = settings.ddr3.ioctr_val,
Lokesh Vutla965de8b2013-12-10 15:02:21 +0530244
Egli, Samuel820969f2014-05-05 16:50:43 +0200245 config_ddr(DDR_PLL_FREQ, &draco_ddr3_ioregs, &draco_ddr3_data,
246 &draco_ddr3_cmd_ctrl_data, &draco_ddr3_emif_reg_data, 0);
Heiko Schocherc0dcece2013-08-19 16:39:01 +0200247}
248
249static void spl_siemens_board_init(void)
250{
251 return;
252}
253#endif /* if def CONFIG_SPL_BUILD */
254
Heiko Schocher61159b72015-06-16 14:59:34 +0200255#ifdef CONFIG_BOARD_LATE_INIT
256int board_late_init(void)
257{
Heiko Schocher02b11f12016-06-07 08:55:43 +0200258 int ret;
259
260 ret = draco_read_nand_geometry();
261 if (ret != 0)
262 return ret;
263
264 nand_curr_device = 0;
265 omap_nand_switch_ecc(1, ecc_type);
Heiko Schocher6b3943f2016-06-07 08:55:45 +0200266#ifdef CONFIG_TARGET_ETAMIN
267 nand_curr_device = 1;
268 omap_nand_switch_ecc(1, ecc_type);
269#endif
Heiko Schocher61159b72015-06-16 14:59:34 +0200270#ifdef CONFIG_FACTORYSET
271 /* Set ASN in environment*/
272 if (factory_dat.asn[0] != 0) {
Simon Glass382bee52017-08-03 12:22:09 -0600273 env_set("dtb_name", (char *)factory_dat.asn);
Heiko Schocher61159b72015-06-16 14:59:34 +0200274 } else {
275 /* dtb suffix gets added in load script */
Simon Glass382bee52017-08-03 12:22:09 -0600276 env_set("dtb_name", "am335x-draco");
Heiko Schocher61159b72015-06-16 14:59:34 +0200277 }
278#else
Simon Glass382bee52017-08-03 12:22:09 -0600279 env_set("dtb_name", "am335x-draco");
Heiko Schocher61159b72015-06-16 14:59:34 +0200280#endif
281
282 return 0;
283}
284#endif
285
Heiko Schocherc0dcece2013-08-19 16:39:01 +0200286#if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) || \
287 (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD))
288static void cpsw_control(int enabled)
289{
290 /* VTP can be added here */
291
292 return;
293}
294
295static struct cpsw_slave_data cpsw_slaves[] = {
296 {
297 .slave_reg_ofs = 0x208,
298 .sliver_reg_ofs = 0xd80,
Mugunthan V N9c653aa2014-02-18 07:31:52 -0500299 .phy_addr = 0,
Heiko Schocherc0dcece2013-08-19 16:39:01 +0200300 .phy_if = PHY_INTERFACE_MODE_MII,
301 },
302};
303
304static struct cpsw_platform_data cpsw_data = {
305 .mdio_base = CPSW_MDIO_BASE,
306 .cpsw_base = CPSW_BASE,
307 .mdio_div = 0xff,
308 .channels = 4,
309 .cpdma_reg_ofs = 0x800,
310 .slaves = 1,
311 .slave_data = cpsw_slaves,
312 .ale_reg_ofs = 0xd00,
313 .ale_entries = 1024,
314 .host_port_reg_ofs = 0x108,
315 .hw_stats_reg_ofs = 0x900,
316 .bd_ram_ofs = 0x2000,
317 .mac_control = (1 << 5),
318 .control = cpsw_control,
319 .host_port_num = 0,
320 .version = CPSW_CTRL_VERSION_2,
321};
322
323#if defined(CONFIG_DRIVER_TI_CPSW) || \
Paul Kocialkowski95de1e22015-08-04 17:04:06 +0200324 (defined(CONFIG_USB_ETHER) && defined(CONFIG_USB_MUSB_GADGET))
Heiko Schocherc0dcece2013-08-19 16:39:01 +0200325int board_eth_init(bd_t *bis)
326{
327 struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
328 int n = 0;
329 int rv;
330
Simon Glass382bee52017-08-03 12:22:09 -0600331 factoryset_env_set();
Heiko Schocherc0dcece2013-08-19 16:39:01 +0200332
Heiko Schocherc0dcece2013-08-19 16:39:01 +0200333 /* Set rgmii mode and enable rmii clock to be sourced from chip */
334 writel((RMII_MODE_ENABLE | RMII_CHIPCKL_ENABLE), &cdev->miisel);
335
336 rv = cpsw_register(&cpsw_data);
337 if (rv < 0)
338 printf("Error %d registering CPSW switch\n", rv);
339 else
340 n += rv;
341 return n;
342}
Stefan Roeseec716e32014-03-12 10:45:41 +0100343
344static int do_switch_reset(cmd_tbl_t *cmdtp, int flag, int argc,
Heiko Schocher6b3943f2016-06-07 08:55:45 +0200345 char *const argv[])
Stefan Roeseec716e32014-03-12 10:45:41 +0100346{
347 /* Reset SMSC LAN9303 switch for default configuration */
348 gpio_request(GPIO_LAN9303_NRST, "nRST");
349 gpio_direction_output(GPIO_LAN9303_NRST, 0);
350 /* assert active low reset for 200us */
351 udelay(200);
352 gpio_set_value(GPIO_LAN9303_NRST, 1);
353
354 return 0;
355};
356
357U_BOOT_CMD(
358 switch_rst, CONFIG_SYS_MAXARGS, 1, do_switch_reset,
359 "Reset LAN9303 switch via its reset pin",
360 ""
361);
Heiko Schocherc0dcece2013-08-19 16:39:01 +0200362#endif /* #if defined(CONFIG_DRIVER_TI_CPSW) */
363#endif /* #if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) */
364
Heiko Schocher6b3943f2016-06-07 08:55:45 +0200365#ifdef CONFIG_NAND_CS_INIT
366/* GPMC definitions for second nand cs1 */
367static const u32 gpmc_nand_config[] = {
368 ETAMIN_NAND_GPMC_CONFIG1,
369 ETAMIN_NAND_GPMC_CONFIG2,
370 ETAMIN_NAND_GPMC_CONFIG3,
371 ETAMIN_NAND_GPMC_CONFIG4,
372 ETAMIN_NAND_GPMC_CONFIG5,
373 ETAMIN_NAND_GPMC_CONFIG6,
374 /*CONFIG7- computed as params */
375};
376
377static void board_nand_cs_init(void)
378{
379 enable_gpmc_cs_config(gpmc_nand_config, &gpmc_cfg->cs[1],
380 0x18000000, GPMC_SIZE_16M);
381}
382#endif
383
Heiko Schocherc0dcece2013-08-19 16:39:01 +0200384#include "../common/board.c"