blob: d108d3e49db0565964441d58f275944f1ccbfaf5 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Heiko Schocher499c4982013-08-19 16:39:01 +02002/*
Egli, Samuel097951b2014-05-05 16:50:43 +02003 * Board functions for TI AM335X based draco board
Heiko Schocher499c4982013-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 *
Nishanth Menoneaa39c62023-11-01 15:56:03 -050012 * Copyright (C) 2011, Texas Instruments, Incorporated - https://www.ti.com/
Heiko Schocher499c4982013-08-19 16:39:01 +020013 */
14
15#include <common.h>
Simon Glassed38aef2020-05-10 11:40:03 -060016#include <command.h>
Simon Glass5e6201b2019-08-01 09:46:51 -060017#include <env.h>
Heiko Schocher499c4982013-08-19 16:39:01 +020018#include <errno.h>
Simon Glassa7b51302019-11-14 12:57:46 -070019#include <init.h>
Simon Glass274e0b02020-05-10 11:39:56 -060020#include <net.h>
Heiko Schocher499c4982013-08-19 16:39:01 +020021#include <spl.h>
22#include <asm/arch/cpu.h>
23#include <asm/arch/hardware.h>
24#include <asm/arch/omap.h>
25#include <asm/arch/ddr_defs.h>
26#include <asm/arch/clock.h>
27#include <asm/arch/gpio.h>
28#include <asm/arch/mmc_host_def.h>
29#include <asm/arch/sys_proto.h>
Heiko Schochercbec11a2016-06-07 08:55:45 +020030#include <asm/arch/mem.h>
Heiko Schocher499c4982013-08-19 16:39:01 +020031#include <asm/io.h>
32#include <asm/emif.h>
33#include <asm/gpio.h>
34#include <i2c.h>
35#include <miiphy.h>
36#include <cpsw.h>
37#include <watchdog.h>
Simon Glassdbd79542020-05-10 11:40:11 -060038#include <linux/delay.h>
Heiko Schocher499c4982013-08-19 16:39:01 +020039#include "board.h"
Enrico Leto096bfdc2024-01-24 15:43:49 +010040#include "../common/eeprom.h"
Heiko Schocher499c4982013-08-19 16:39:01 +020041#include "../common/factoryset.h"
Heiko Schochercbec11a2016-06-07 08:55:45 +020042#include <nand.h>
Heiko Schocher499c4982013-08-19 16:39:01 +020043
Heiko Schocher499c4982013-08-19 16:39:01 +020044#ifdef CONFIG_SPL_BUILD
Marek BehĂșn4bebdd32021-05-20 13:23:52 +020045static struct draco_baseboard_id __section(".data") settings;
Egli, Samuelbc38fa42014-04-24 17:57:53 +020046
47#if DDR_PLL_FREQ == 303
Heiko Schochercbec11a2016-06-07 08:55:45 +020048#if !defined(CONFIG_TARGET_ETAMIN)
Egli, Samuelbc38fa42014-04-24 17:57:53 +020049/* Default@303MHz-i0 */
50const struct ddr3_data ddr3_default = {
51 0x33524444, 0x56312e35, 0x0080, 0x0000, 0x003A, 0x003F, 0x009F,
Heiko Schocherd17c3fc2015-06-16 14:59:34 +020052 0x0079, 0x0888A39B, 0x26517FDA, 0x501F84EF, 0x00100206, 0x61A44A32,
Egli, Samuelbc38fa42014-04-24 17:57:53 +020053 0x0000093B, 0x0000014A,
54 "default name @303MHz \0",
55 "default marking \0",
56};
Heiko Schochercbec11a2016-06-07 08:55:45 +020057#else
58/* etamin board */
59const struct ddr3_data ddr3_default = {
60 0x33524444, 0x56312e36, 0x0080, 0x0000, 0x003A, 0x0010, 0x009F,
61 0x0050, 0x0888A39B, 0x266D7FDA, 0x501F86AF, 0x00100206, 0x61A44BB2,
62 0x0000093B, 0x0000018A,
63 "test-etamin \0",
64 "generic-8Gbit \0",
65};
66#endif
Egli, Samuelbc38fa42014-04-24 17:57:53 +020067#elif DDR_PLL_FREQ == 400
68/* Default@400MHz-i0 */
Heiko Schocher499c4982013-08-19 16:39:01 +020069const struct ddr3_data ddr3_default = {
Egli, Samuelbc38fa42014-04-24 17:57:53 +020070 0x33524444, 0x56312e35, 0x0080, 0x0000, 0x0039, 0x0046, 0x00ab,
71 0x0080, 0x0AAAA4DB, 0x26307FDA, 0x501F821F, 0x00100207, 0x61A45232,
Samuel Egli8069bfe2013-11-04 14:05:03 +010072 0x00000618, 0x0000014A,
Egli, Samuelbc38fa42014-04-24 17:57:53 +020073 "default name @400MHz \0",
74 "default marking \0",
Heiko Schocher499c4982013-08-19 16:39:01 +020075};
Egli, Samuelbc38fa42014-04-24 17:57:53 +020076#endif
Heiko Schocher499c4982013-08-19 16:39:01 +020077
78static void set_default_ddr3_timings(void)
79{
80 printf("Set default DDR3 settings\n");
81 settings.ddr3 = ddr3_default;
82}
83
84static void print_ddr3_timings(void)
85{
Egli, Samuelbc38fa42014-04-24 17:57:53 +020086 printf("\nDDR3\n");
87 printf("clock:\t\t%d MHz\n", DDR_PLL_FREQ);
88 printf("device:\t\t%s\n", settings.ddr3.manu_name);
89 printf("marking:\t%s\n", settings.ddr3.manu_marking);
Heiko Schocherd17c3fc2015-06-16 14:59:34 +020090 printf("%-20s, %-8s, %-8s, %-4s\n", "timing parameters", "eeprom",
91 "default", "diff");
Heiko Schocher499c4982013-08-19 16:39:01 +020092 PRINTARGS(magic);
93 PRINTARGS(version);
94 PRINTARGS(ddr3_sratio);
95 PRINTARGS(iclkout);
96
97 PRINTARGS(dt0rdsratio0);
98 PRINTARGS(dt0wdsratio0);
99 PRINTARGS(dt0fwsratio0);
100 PRINTARGS(dt0wrsratio0);
101
102 PRINTARGS(sdram_tim1);
103 PRINTARGS(sdram_tim2);
104 PRINTARGS(sdram_tim3);
105
106 PRINTARGS(emif_ddr_phy_ctlr_1);
107
108 PRINTARGS(sdram_config);
109 PRINTARGS(ref_ctrl);
Samuel Egli8069bfe2013-11-04 14:05:03 +0100110 PRINTARGS(ioctr_val);
Heiko Schocher499c4982013-08-19 16:39:01 +0200111}
112
113static void print_chip_data(void)
114{
Heiko Schocherd17c3fc2015-06-16 14:59:34 +0200115 struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
116 dpll_mpu_opp100.m = am335x_get_efuse_mpu_max_freq(cdev);
Egli, Samuelbc38fa42014-04-24 17:57:53 +0200117 printf("\nCPU BOARD\n");
118 printf("device: \t'%s'\n", settings.chip.sdevname);
119 printf("hw version: \t'%s'\n", settings.chip.shwver);
Heiko Schocherd17c3fc2015-06-16 14:59:34 +0200120 printf("max freq: \t%d MHz\n", dpll_mpu_opp100.m);
Heiko Schocher499c4982013-08-19 16:39:01 +0200121}
122#endif /* CONFIG_SPL_BUILD */
123
Heiko Schocher4453d7a2016-06-07 08:55:43 +0200124#define AM335X_NAND_ECC_MASK 0x0f
125#define AM335X_NAND_ECC_TYPE_16 0x02
126
127static int ecc_type;
128
129struct am335x_nand_geometry {
130 u32 magic;
131 u8 nand_geo_addr;
132 u8 nand_geo_page;
133 u8 nand_bus;
134};
135
136static int draco_read_nand_geometry(void)
137{
138 struct am335x_nand_geometry geo;
139
140 /* Read NAND geometry */
Enrico Leto32f433f2024-01-24 15:43:50 +0100141 if (siemens_ee_read_data(SIEMENS_EE_ADDR_NAND_GEO, (uchar *)&geo,
142 sizeof(struct am335x_nand_geometry))) {
Heiko Schocher4453d7a2016-06-07 08:55:43 +0200143 printf("Could not read the NAND geomtery; something fundamentally wrong on the I2C bus.\n");
144 return -EIO;
145 }
146 if (geo.magic != 0xa657b310) {
147 printf("%s: bad magic: %x\n", __func__, geo.magic);
148 return -EFAULT;
149 }
150 if ((geo.nand_bus & AM335X_NAND_ECC_MASK) == AM335X_NAND_ECC_TYPE_16)
151 ecc_type = 16;
152 else
153 ecc_type = 8;
154
155 return 0;
156}
157
Enrico Leto32f433f2024-01-24 15:43:50 +0100158#ifdef CONFIG_SPL_BUILD
Heiko Schocher499c4982013-08-19 16:39:01 +0200159/*
160 * Read header information from EEPROM into global structure.
161 */
162static int read_eeprom(void)
163{
Heiko Schocher499c4982013-08-19 16:39:01 +0200164 /* Read Siemens eeprom data (DDR3) */
Enrico Leto32f433f2024-01-24 15:43:50 +0100165 if (siemens_ee_read_data(SIEMENS_EE_ADDR_DDR3, (uchar *)&settings.ddr3,
166 sizeof(struct ddr3_data))) {
Heiko Schocher499c4982013-08-19 16:39:01 +0200167 printf("Could not read the EEPROM; something fundamentally wrong on the I2C bus.\nUse default DDR3 timings\n");
168 set_default_ddr3_timings();
169 }
170 /* Read Siemens eeprom data (CHIP) */
Enrico Leto32f433f2024-01-24 15:43:50 +0100171 if (siemens_ee_read_data(SIEMENS_EE_ADDR_CHIP, (uchar *)&settings.chip,
172 sizeof(settings.chip)))
Heiko Schocher499c4982013-08-19 16:39:01 +0200173 printf("Could not read chip settings\n");
174
175 if (ddr3_default.magic == settings.ddr3.magic &&
176 ddr3_default.version == settings.ddr3.version) {
177 printf("Using DDR3 settings from EEPROM\n");
178 } else {
179 if (ddr3_default.magic != settings.ddr3.magic)
Egli, Samuelbc38fa42014-04-24 17:57:53 +0200180 printf("Warning: No valid DDR3 data in eeprom.\n");
Heiko Schocher499c4982013-08-19 16:39:01 +0200181 if (ddr3_default.version != settings.ddr3.version)
Egli, Samuelbc38fa42014-04-24 17:57:53 +0200182 printf("Warning: DDR3 data version does not match.\n");
Heiko Schocher499c4982013-08-19 16:39:01 +0200183
184 printf("Using default settings\n");
185 set_default_ddr3_timings();
186 }
187
Egli, Samuel097951b2014-05-05 16:50:43 +0200188 if (MAGIC_CHIP == settings.chip.magic)
Heiko Schocher499c4982013-08-19 16:39:01 +0200189 print_chip_data();
Egli, Samuel097951b2014-05-05 16:50:43 +0200190 else
Egli, Samuelbc38fa42014-04-24 17:57:53 +0200191 printf("Warning: No chip data in eeprom\n");
Heiko Schocher499c4982013-08-19 16:39:01 +0200192
193 print_ddr3_timings();
Heiko Schocher4453d7a2016-06-07 08:55:43 +0200194
195 return draco_read_nand_geometry();
Heiko Schocher499c4982013-08-19 16:39:01 +0200196}
197
Heiko Schocher499c4982013-08-19 16:39:01 +0200198static void board_init_ddr(void)
199{
Egli, Samuel097951b2014-05-05 16:50:43 +0200200struct emif_regs draco_ddr3_emif_reg_data = {
Heiko Schocher499c4982013-08-19 16:39:01 +0200201 .zq_config = 0x50074BE4,
202};
203
Egli, Samuel097951b2014-05-05 16:50:43 +0200204struct ddr_data draco_ddr3_data = {
Heiko Schocher499c4982013-08-19 16:39:01 +0200205};
206
Egli, Samuel097951b2014-05-05 16:50:43 +0200207struct cmd_control draco_ddr3_cmd_ctrl_data = {
Heiko Schocher499c4982013-08-19 16:39:01 +0200208};
Lokesh Vutla303b2672013-12-10 15:02:21 +0530209
Egli, Samuel097951b2014-05-05 16:50:43 +0200210struct ctrl_ioregs draco_ddr3_ioregs = {
Lokesh Vutla303b2672013-12-10 15:02:21 +0530211};
212
Heiko Schocher499c4982013-08-19 16:39:01 +0200213 /* pass values from eeprom */
Egli, Samuel097951b2014-05-05 16:50:43 +0200214 draco_ddr3_emif_reg_data.sdram_tim1 = settings.ddr3.sdram_tim1;
215 draco_ddr3_emif_reg_data.sdram_tim2 = settings.ddr3.sdram_tim2;
216 draco_ddr3_emif_reg_data.sdram_tim3 = settings.ddr3.sdram_tim3;
217 draco_ddr3_emif_reg_data.emif_ddr_phy_ctlr_1 =
Heiko Schocher499c4982013-08-19 16:39:01 +0200218 settings.ddr3.emif_ddr_phy_ctlr_1;
Egli, Samuel097951b2014-05-05 16:50:43 +0200219 draco_ddr3_emif_reg_data.sdram_config = settings.ddr3.sdram_config;
Heiko Schochercbec11a2016-06-07 08:55:45 +0200220 draco_ddr3_emif_reg_data.sdram_config2 = 0x08000000;
Egli, Samuel097951b2014-05-05 16:50:43 +0200221 draco_ddr3_emif_reg_data.ref_ctrl = settings.ddr3.ref_ctrl;
Heiko Schocher499c4982013-08-19 16:39:01 +0200222
Egli, Samuel097951b2014-05-05 16:50:43 +0200223 draco_ddr3_data.datardsratio0 = settings.ddr3.dt0rdsratio0;
224 draco_ddr3_data.datawdsratio0 = settings.ddr3.dt0wdsratio0;
225 draco_ddr3_data.datafwsratio0 = settings.ddr3.dt0fwsratio0;
226 draco_ddr3_data.datawrsratio0 = settings.ddr3.dt0wrsratio0;
Heiko Schocher499c4982013-08-19 16:39:01 +0200227
Egli, Samuel097951b2014-05-05 16:50:43 +0200228 draco_ddr3_cmd_ctrl_data.cmd0csratio = settings.ddr3.ddr3_sratio;
229 draco_ddr3_cmd_ctrl_data.cmd0iclkout = settings.ddr3.iclkout;
230 draco_ddr3_cmd_ctrl_data.cmd1csratio = settings.ddr3.ddr3_sratio;
231 draco_ddr3_cmd_ctrl_data.cmd1iclkout = settings.ddr3.iclkout;
232 draco_ddr3_cmd_ctrl_data.cmd2csratio = settings.ddr3.ddr3_sratio;
233 draco_ddr3_cmd_ctrl_data.cmd2iclkout = settings.ddr3.iclkout;
Heiko Schocher499c4982013-08-19 16:39:01 +0200234
Egli, Samuel097951b2014-05-05 16:50:43 +0200235 draco_ddr3_ioregs.cm0ioctl = settings.ddr3.ioctr_val,
236 draco_ddr3_ioregs.cm1ioctl = settings.ddr3.ioctr_val,
237 draco_ddr3_ioregs.cm2ioctl = settings.ddr3.ioctr_val,
238 draco_ddr3_ioregs.dt0ioctl = settings.ddr3.ioctr_val,
239 draco_ddr3_ioregs.dt1ioctl = settings.ddr3.ioctr_val,
Lokesh Vutla303b2672013-12-10 15:02:21 +0530240
Egli, Samuel097951b2014-05-05 16:50:43 +0200241 config_ddr(DDR_PLL_FREQ, &draco_ddr3_ioregs, &draco_ddr3_data,
242 &draco_ddr3_cmd_ctrl_data, &draco_ddr3_emif_reg_data, 0);
Heiko Schocher499c4982013-08-19 16:39:01 +0200243}
244
245static void spl_siemens_board_init(void)
246{
247 return;
248}
249#endif /* if def CONFIG_SPL_BUILD */
250
Heiko Schocherd17c3fc2015-06-16 14:59:34 +0200251#ifdef CONFIG_BOARD_LATE_INIT
252int board_late_init(void)
253{
Heiko Schocher4453d7a2016-06-07 08:55:43 +0200254 int ret;
255
256 ret = draco_read_nand_geometry();
257 if (ret != 0)
258 return ret;
259
260 nand_curr_device = 0;
261 omap_nand_switch_ecc(1, ecc_type);
Heiko Schochercbec11a2016-06-07 08:55:45 +0200262#ifdef CONFIG_TARGET_ETAMIN
263 nand_curr_device = 1;
264 omap_nand_switch_ecc(1, ecc_type);
265#endif
Heiko Schocherd17c3fc2015-06-16 14:59:34 +0200266#ifdef CONFIG_FACTORYSET
267 /* Set ASN in environment*/
268 if (factory_dat.asn[0] != 0) {
Simon Glass6a38e412017-08-03 12:22:09 -0600269 env_set("dtb_name", (char *)factory_dat.asn);
Heiko Schocherd17c3fc2015-06-16 14:59:34 +0200270 } else {
271 /* dtb suffix gets added in load script */
Simon Glass6a38e412017-08-03 12:22:09 -0600272 env_set("dtb_name", "am335x-draco");
Heiko Schocherd17c3fc2015-06-16 14:59:34 +0200273 }
274#else
Simon Glass6a38e412017-08-03 12:22:09 -0600275 env_set("dtb_name", "am335x-draco");
Heiko Schocherd17c3fc2015-06-16 14:59:34 +0200276#endif
277
278 return 0;
279}
280#endif
281
Heiko Schocher499c4982013-08-19 16:39:01 +0200282#if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) || \
Simon Glasse5cd9a42021-07-10 21:14:26 -0600283 (defined(CONFIG_SPL_ETH) && defined(CONFIG_SPL_BUILD))
Heiko Schocher499c4982013-08-19 16:39:01 +0200284static void cpsw_control(int enabled)
285{
286 /* VTP can be added here */
287
288 return;
289}
290
291static struct cpsw_slave_data cpsw_slaves[] = {
292 {
293 .slave_reg_ofs = 0x208,
294 .sliver_reg_ofs = 0xd80,
Mugunthan V N4944f372014-02-18 07:31:52 -0500295 .phy_addr = 0,
Heiko Schocher499c4982013-08-19 16:39:01 +0200296 .phy_if = PHY_INTERFACE_MODE_MII,
297 },
298};
299
300static struct cpsw_platform_data cpsw_data = {
301 .mdio_base = CPSW_MDIO_BASE,
302 .cpsw_base = CPSW_BASE,
303 .mdio_div = 0xff,
304 .channels = 4,
305 .cpdma_reg_ofs = 0x800,
306 .slaves = 1,
307 .slave_data = cpsw_slaves,
308 .ale_reg_ofs = 0xd00,
309 .ale_entries = 1024,
310 .host_port_reg_ofs = 0x108,
311 .hw_stats_reg_ofs = 0x900,
312 .bd_ram_ofs = 0x2000,
313 .mac_control = (1 << 5),
314 .control = cpsw_control,
315 .host_port_num = 0,
316 .version = CPSW_CTRL_VERSION_2,
317};
318
319#if defined(CONFIG_DRIVER_TI_CPSW) || \
Paul Kocialkowskif34dfcb2015-08-04 17:04:06 +0200320 (defined(CONFIG_USB_ETHER) && defined(CONFIG_USB_MUSB_GADGET))
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900321int board_eth_init(struct bd_info *bis)
Heiko Schocher499c4982013-08-19 16:39:01 +0200322{
323 struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
324 int n = 0;
325 int rv;
326
Simon Glass6a38e412017-08-03 12:22:09 -0600327 factoryset_env_set();
Heiko Schocher499c4982013-08-19 16:39:01 +0200328
Heiko Schocher499c4982013-08-19 16:39:01 +0200329 /* Set rgmii mode and enable rmii clock to be sourced from chip */
330 writel((RMII_MODE_ENABLE | RMII_CHIPCKL_ENABLE), &cdev->miisel);
331
332 rv = cpsw_register(&cpsw_data);
333 if (rv < 0)
334 printf("Error %d registering CPSW switch\n", rv);
335 else
336 n += rv;
337 return n;
338}
Stefan Roese9aee57f2014-03-12 10:45:41 +0100339
Simon Glassed38aef2020-05-10 11:40:03 -0600340static int do_switch_reset(struct cmd_tbl *cmdtp, int flag, int argc,
341 char *const argv[])
Stefan Roese9aee57f2014-03-12 10:45:41 +0100342{
343 /* Reset SMSC LAN9303 switch for default configuration */
344 gpio_request(GPIO_LAN9303_NRST, "nRST");
345 gpio_direction_output(GPIO_LAN9303_NRST, 0);
346 /* assert active low reset for 200us */
347 udelay(200);
348 gpio_set_value(GPIO_LAN9303_NRST, 1);
349
350 return 0;
351};
352
353U_BOOT_CMD(
354 switch_rst, CONFIG_SYS_MAXARGS, 1, do_switch_reset,
355 "Reset LAN9303 switch via its reset pin",
356 ""
357);
Heiko Schocher499c4982013-08-19 16:39:01 +0200358#endif /* #if defined(CONFIG_DRIVER_TI_CPSW) */
359#endif /* #if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) */
360
Heiko Schocher499c4982013-08-19 16:39:01 +0200361#include "../common/board.c"