blob: 367a300b8978e712c7adf46d1768322bb85d15fd [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 *
Nishanth Menona94a4072023-11-01 15:56:03 -050012 * Copyright (C) 2011, Texas Instruments, Incorporated - https://www.ti.com/
Heiko Schocherc0dcece2013-08-19 16:39:01 +020013 */
14
15#include <common.h>
Simon Glass09140112020-05-10 11:40:03 -060016#include <command.h>
Simon Glass9fb625c2019-08-01 09:46:51 -060017#include <env.h>
Heiko Schocherc0dcece2013-08-19 16:39:01 +020018#include <errno.h>
Simon Glass52559322019-11-14 12:57:46 -070019#include <init.h>
Simon Glass90526e92020-05-10 11:39:56 -060020#include <net.h>
Heiko Schocherc0dcece2013-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 Schocher6b3943f2016-06-07 08:55:45 +020030#include <asm/arch/mem.h>
Heiko Schocherc0dcece2013-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 Glassc05ed002020-05-10 11:40:11 -060038#include <linux/delay.h>
Heiko Schocherc0dcece2013-08-19 16:39:01 +020039#include "board.h"
Enrico Leto5ae54612024-01-24 15:43:49 +010040#include "../common/eeprom.h"
Heiko Schocherc0dcece2013-08-19 16:39:01 +020041#include "../common/factoryset.h"
Heiko Schocher6b3943f2016-06-07 08:55:45 +020042#include <nand.h>
Heiko Schocherc0dcece2013-08-19 16:39:01 +020043
Heiko Schocherc0dcece2013-08-19 16:39:01 +020044#ifdef CONFIG_SPL_BUILD
Marek BehĂșn236f2ec2021-05-20 13:23:52 +020045static struct draco_baseboard_id __section(".data") settings;
Egli, Samuel823b2c42014-04-24 17:57:53 +020046
47#if DDR_PLL_FREQ == 303
Heiko Schocher6b3943f2016-06-07 08:55:45 +020048#if !defined(CONFIG_TARGET_ETAMIN)
Egli, Samuel823b2c42014-04-24 17:57:53 +020049/* Default@303MHz-i0 */
Heiko Schocherc0dcece2013-08-19 16:39:01 +020050const struct ddr3_data ddr3_default = {
Egli, Samuel823b2c42014-04-24 17:57:53 +020051 0x33524444, 0x56312e35, 0x0080, 0x0000, 0x003A, 0x003F, 0x009F,
Heiko Schocher61159b72015-06-16 14:59:34 +020052 0x0079, 0x0888A39B, 0x26517FDA, 0x501F84EF, 0x00100206, 0x61A44A32,
Egli, Samuel823b2c42014-04-24 17:57:53 +020053 0x0000093B, 0x0000014A,
54 "default name @303MHz \0",
55 "default marking \0",
Heiko Schocherc0dcece2013-08-19 16:39:01 +020056};
Heiko Schocher6b3943f2016-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, Samuel823b2c42014-04-24 17:57:53 +020067#elif DDR_PLL_FREQ == 400
68/* Default@400MHz-i0 */
69const struct ddr3_data ddr3_default = {
70 0x33524444, 0x56312e35, 0x0080, 0x0000, 0x0039, 0x0046, 0x00ab,
71 0x0080, 0x0AAAA4DB, 0x26307FDA, 0x501F821F, 0x00100207, 0x61A45232,
72 0x00000618, 0x0000014A,
73 "default name @400MHz \0",
74 "default marking \0",
75};
76#endif
Heiko Schocherc0dcece2013-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, Samuel823b2c42014-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 Schocher61159b72015-06-16 14:59:34 +020090 printf("%-20s, %-8s, %-8s, %-4s\n", "timing parameters", "eeprom",
91 "default", "diff");
Heiko Schocherc0dcece2013-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 Egli56eb3da2013-11-04 14:05:03 +0100110 PRINTARGS(ioctr_val);
Heiko Schocherc0dcece2013-08-19 16:39:01 +0200111}
112
113static void print_chip_data(void)
114{
Heiko Schocher61159b72015-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, Samuel823b2c42014-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 Schocher61159b72015-06-16 14:59:34 +0200120 printf("max freq: \t%d MHz\n", dpll_mpu_opp100.m);
Heiko Schocherc0dcece2013-08-19 16:39:01 +0200121}
122#endif /* CONFIG_SPL_BUILD */
123
Heiko Schocher02b11f12016-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 Leto5ae54612024-01-24 15:43:49 +0100141 if (i2c_read(SIEMENS_EE_I2C_ADDR, SIEMENS_EE_ADDR_NAND_GEO, 2,
Heiko Schocher02b11f12016-06-07 08:55:43 +0200142 (uchar *)&geo, sizeof(struct am335x_nand_geometry))) {
143 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
Heiko Schocherc0dcece2013-08-19 16:39:01 +0200158/*
159 * Read header information from EEPROM into global structure.
160 */
161static int read_eeprom(void)
162{
163 /* Check if baseboard eeprom is available */
Enrico Leto5ae54612024-01-24 15:43:49 +0100164 if (i2c_probe(SIEMENS_EE_I2C_ADDR)) {
Heiko Schocherc0dcece2013-08-19 16:39:01 +0200165 printf("Could not probe the EEPROM; something fundamentally wrong on the I2C bus.\n");
166 return 1;
167 }
168
169#ifdef CONFIG_SPL_BUILD
170 /* Read Siemens eeprom data (DDR3) */
Enrico Leto5ae54612024-01-24 15:43:49 +0100171 if (i2c_read(SIEMENS_EE_I2C_ADDR, SIEMENS_EE_ADDR_DDR3, 2,
Heiko Schocherc0dcece2013-08-19 16:39:01 +0200172 (uchar *)&settings.ddr3, sizeof(struct ddr3_data))) {
173 printf("Could not read the EEPROM; something fundamentally wrong on the I2C bus.\nUse default DDR3 timings\n");
174 set_default_ddr3_timings();
175 }
176 /* Read Siemens eeprom data (CHIP) */
Enrico Leto5ae54612024-01-24 15:43:49 +0100177 if (i2c_read(SIEMENS_EE_I2C_ADDR, SIEMENS_EE_ADDR_CHIP, 2,
Heiko Schocherc0dcece2013-08-19 16:39:01 +0200178 (uchar *)&settings.chip, sizeof(settings.chip)))
179 printf("Could not read chip settings\n");
180
181 if (ddr3_default.magic == settings.ddr3.magic &&
182 ddr3_default.version == settings.ddr3.version) {
183 printf("Using DDR3 settings from EEPROM\n");
184 } else {
185 if (ddr3_default.magic != settings.ddr3.magic)
Egli, Samuel823b2c42014-04-24 17:57:53 +0200186 printf("Warning: No valid DDR3 data in eeprom.\n");
Heiko Schocherc0dcece2013-08-19 16:39:01 +0200187 if (ddr3_default.version != settings.ddr3.version)
Egli, Samuel823b2c42014-04-24 17:57:53 +0200188 printf("Warning: DDR3 data version does not match.\n");
Heiko Schocherc0dcece2013-08-19 16:39:01 +0200189
190 printf("Using default settings\n");
191 set_default_ddr3_timings();
192 }
193
Egli, Samuel820969f2014-05-05 16:50:43 +0200194 if (MAGIC_CHIP == settings.chip.magic)
Heiko Schocherc0dcece2013-08-19 16:39:01 +0200195 print_chip_data();
Egli, Samuel820969f2014-05-05 16:50:43 +0200196 else
Egli, Samuel823b2c42014-04-24 17:57:53 +0200197 printf("Warning: No chip data in eeprom\n");
Heiko Schocherc0dcece2013-08-19 16:39:01 +0200198
199 print_ddr3_timings();
Heiko Schocher02b11f12016-06-07 08:55:43 +0200200
201 return draco_read_nand_geometry();
Heiko Schocherc0dcece2013-08-19 16:39:01 +0200202#endif
203 return 0;
204}
205
206#ifdef CONFIG_SPL_BUILD
207static void board_init_ddr(void)
208{
Egli, Samuel820969f2014-05-05 16:50:43 +0200209struct emif_regs draco_ddr3_emif_reg_data = {
Heiko Schocherc0dcece2013-08-19 16:39:01 +0200210 .zq_config = 0x50074BE4,
211};
212
Egli, Samuel820969f2014-05-05 16:50:43 +0200213struct ddr_data draco_ddr3_data = {
Heiko Schocherc0dcece2013-08-19 16:39:01 +0200214};
215
Egli, Samuel820969f2014-05-05 16:50:43 +0200216struct cmd_control draco_ddr3_cmd_ctrl_data = {
Heiko Schocherc0dcece2013-08-19 16:39:01 +0200217};
Lokesh Vutla965de8b2013-12-10 15:02:21 +0530218
Egli, Samuel820969f2014-05-05 16:50:43 +0200219struct ctrl_ioregs draco_ddr3_ioregs = {
Lokesh Vutla965de8b2013-12-10 15:02:21 +0530220};
221
Heiko Schocherc0dcece2013-08-19 16:39:01 +0200222 /* pass values from eeprom */
Egli, Samuel820969f2014-05-05 16:50:43 +0200223 draco_ddr3_emif_reg_data.sdram_tim1 = settings.ddr3.sdram_tim1;
224 draco_ddr3_emif_reg_data.sdram_tim2 = settings.ddr3.sdram_tim2;
225 draco_ddr3_emif_reg_data.sdram_tim3 = settings.ddr3.sdram_tim3;
226 draco_ddr3_emif_reg_data.emif_ddr_phy_ctlr_1 =
Heiko Schocherc0dcece2013-08-19 16:39:01 +0200227 settings.ddr3.emif_ddr_phy_ctlr_1;
Egli, Samuel820969f2014-05-05 16:50:43 +0200228 draco_ddr3_emif_reg_data.sdram_config = settings.ddr3.sdram_config;
Heiko Schocher6b3943f2016-06-07 08:55:45 +0200229 draco_ddr3_emif_reg_data.sdram_config2 = 0x08000000;
Egli, Samuel820969f2014-05-05 16:50:43 +0200230 draco_ddr3_emif_reg_data.ref_ctrl = settings.ddr3.ref_ctrl;
Heiko Schocherc0dcece2013-08-19 16:39:01 +0200231
Egli, Samuel820969f2014-05-05 16:50:43 +0200232 draco_ddr3_data.datardsratio0 = settings.ddr3.dt0rdsratio0;
233 draco_ddr3_data.datawdsratio0 = settings.ddr3.dt0wdsratio0;
234 draco_ddr3_data.datafwsratio0 = settings.ddr3.dt0fwsratio0;
235 draco_ddr3_data.datawrsratio0 = settings.ddr3.dt0wrsratio0;
Heiko Schocherc0dcece2013-08-19 16:39:01 +0200236
Egli, Samuel820969f2014-05-05 16:50:43 +0200237 draco_ddr3_cmd_ctrl_data.cmd0csratio = settings.ddr3.ddr3_sratio;
238 draco_ddr3_cmd_ctrl_data.cmd0iclkout = settings.ddr3.iclkout;
239 draco_ddr3_cmd_ctrl_data.cmd1csratio = settings.ddr3.ddr3_sratio;
240 draco_ddr3_cmd_ctrl_data.cmd1iclkout = settings.ddr3.iclkout;
241 draco_ddr3_cmd_ctrl_data.cmd2csratio = settings.ddr3.ddr3_sratio;
242 draco_ddr3_cmd_ctrl_data.cmd2iclkout = settings.ddr3.iclkout;
Heiko Schocherc0dcece2013-08-19 16:39:01 +0200243
Egli, Samuel820969f2014-05-05 16:50:43 +0200244 draco_ddr3_ioregs.cm0ioctl = settings.ddr3.ioctr_val,
245 draco_ddr3_ioregs.cm1ioctl = settings.ddr3.ioctr_val,
246 draco_ddr3_ioregs.cm2ioctl = settings.ddr3.ioctr_val,
247 draco_ddr3_ioregs.dt0ioctl = settings.ddr3.ioctr_val,
248 draco_ddr3_ioregs.dt1ioctl = settings.ddr3.ioctr_val,
Lokesh Vutla965de8b2013-12-10 15:02:21 +0530249
Egli, Samuel820969f2014-05-05 16:50:43 +0200250 config_ddr(DDR_PLL_FREQ, &draco_ddr3_ioregs, &draco_ddr3_data,
251 &draco_ddr3_cmd_ctrl_data, &draco_ddr3_emif_reg_data, 0);
Heiko Schocherc0dcece2013-08-19 16:39:01 +0200252}
253
254static void spl_siemens_board_init(void)
255{
256 return;
257}
258#endif /* if def CONFIG_SPL_BUILD */
259
Heiko Schocher61159b72015-06-16 14:59:34 +0200260#ifdef CONFIG_BOARD_LATE_INIT
261int board_late_init(void)
262{
Heiko Schocher02b11f12016-06-07 08:55:43 +0200263 int ret;
264
265 ret = draco_read_nand_geometry();
266 if (ret != 0)
267 return ret;
268
269 nand_curr_device = 0;
270 omap_nand_switch_ecc(1, ecc_type);
Heiko Schocher6b3943f2016-06-07 08:55:45 +0200271#ifdef CONFIG_TARGET_ETAMIN
272 nand_curr_device = 1;
273 omap_nand_switch_ecc(1, ecc_type);
274#endif
Heiko Schocher61159b72015-06-16 14:59:34 +0200275#ifdef CONFIG_FACTORYSET
276 /* Set ASN in environment*/
277 if (factory_dat.asn[0] != 0) {
Simon Glass382bee52017-08-03 12:22:09 -0600278 env_set("dtb_name", (char *)factory_dat.asn);
Heiko Schocher61159b72015-06-16 14:59:34 +0200279 } else {
280 /* dtb suffix gets added in load script */
Simon Glass382bee52017-08-03 12:22:09 -0600281 env_set("dtb_name", "am335x-draco");
Heiko Schocher61159b72015-06-16 14:59:34 +0200282 }
283#else
Simon Glass382bee52017-08-03 12:22:09 -0600284 env_set("dtb_name", "am335x-draco");
Heiko Schocher61159b72015-06-16 14:59:34 +0200285#endif
286
287 return 0;
288}
289#endif
290
Heiko Schocherc0dcece2013-08-19 16:39:01 +0200291#if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) || \
Simon Glassf2d7a362021-07-10 21:14:26 -0600292 (defined(CONFIG_SPL_ETH) && defined(CONFIG_SPL_BUILD))
Heiko Schocherc0dcece2013-08-19 16:39:01 +0200293static void cpsw_control(int enabled)
294{
295 /* VTP can be added here */
296
297 return;
298}
299
300static struct cpsw_slave_data cpsw_slaves[] = {
301 {
302 .slave_reg_ofs = 0x208,
303 .sliver_reg_ofs = 0xd80,
Mugunthan V N9c653aa2014-02-18 07:31:52 -0500304 .phy_addr = 0,
Heiko Schocherc0dcece2013-08-19 16:39:01 +0200305 .phy_if = PHY_INTERFACE_MODE_MII,
306 },
307};
308
309static struct cpsw_platform_data cpsw_data = {
310 .mdio_base = CPSW_MDIO_BASE,
311 .cpsw_base = CPSW_BASE,
312 .mdio_div = 0xff,
313 .channels = 4,
314 .cpdma_reg_ofs = 0x800,
315 .slaves = 1,
316 .slave_data = cpsw_slaves,
317 .ale_reg_ofs = 0xd00,
318 .ale_entries = 1024,
319 .host_port_reg_ofs = 0x108,
320 .hw_stats_reg_ofs = 0x900,
321 .bd_ram_ofs = 0x2000,
322 .mac_control = (1 << 5),
323 .control = cpsw_control,
324 .host_port_num = 0,
325 .version = CPSW_CTRL_VERSION_2,
326};
327
328#if defined(CONFIG_DRIVER_TI_CPSW) || \
Paul Kocialkowski95de1e22015-08-04 17:04:06 +0200329 (defined(CONFIG_USB_ETHER) && defined(CONFIG_USB_MUSB_GADGET))
Masahiro Yamadab75d8dc2020-06-26 15:13:33 +0900330int board_eth_init(struct bd_info *bis)
Heiko Schocherc0dcece2013-08-19 16:39:01 +0200331{
332 struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
333 int n = 0;
334 int rv;
335
Simon Glass382bee52017-08-03 12:22:09 -0600336 factoryset_env_set();
Heiko Schocherc0dcece2013-08-19 16:39:01 +0200337
Heiko Schocherc0dcece2013-08-19 16:39:01 +0200338 /* Set rgmii mode and enable rmii clock to be sourced from chip */
339 writel((RMII_MODE_ENABLE | RMII_CHIPCKL_ENABLE), &cdev->miisel);
340
341 rv = cpsw_register(&cpsw_data);
342 if (rv < 0)
343 printf("Error %d registering CPSW switch\n", rv);
344 else
345 n += rv;
346 return n;
347}
Stefan Roeseec716e32014-03-12 10:45:41 +0100348
Simon Glass09140112020-05-10 11:40:03 -0600349static int do_switch_reset(struct cmd_tbl *cmdtp, int flag, int argc,
350 char *const argv[])
Stefan Roeseec716e32014-03-12 10:45:41 +0100351{
352 /* Reset SMSC LAN9303 switch for default configuration */
353 gpio_request(GPIO_LAN9303_NRST, "nRST");
354 gpio_direction_output(GPIO_LAN9303_NRST, 0);
355 /* assert active low reset for 200us */
356 udelay(200);
357 gpio_set_value(GPIO_LAN9303_NRST, 1);
358
359 return 0;
360};
361
362U_BOOT_CMD(
363 switch_rst, CONFIG_SYS_MAXARGS, 1, do_switch_reset,
364 "Reset LAN9303 switch via its reset pin",
365 ""
366);
Heiko Schocherc0dcece2013-08-19 16:39:01 +0200367#endif /* #if defined(CONFIG_DRIVER_TI_CPSW) */
368#endif /* #if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) */
369
Tom Rini3348c6b2022-12-02 16:42:38 -0500370#if CONFIG_IS_ENABLED(NAND_CS_INIT)
371#define ETAMIN_NAND_GPMC_CONFIG1 0x00000800
372#define ETAMIN_NAND_GPMC_CONFIG2 0x001e1e00
373#define ETAMIN_NAND_GPMC_CONFIG3 0x001e1e00
374#define ETAMIN_NAND_GPMC_CONFIG4 0x16051807
375#define ETAMIN_NAND_GPMC_CONFIG5 0x00151e1e
376#define ETAMIN_NAND_GPMC_CONFIG6 0x16000f80
377
Heiko Schocher6b3943f2016-06-07 08:55:45 +0200378/* GPMC definitions for second nand cs1 */
379static const u32 gpmc_nand_config[] = {
380 ETAMIN_NAND_GPMC_CONFIG1,
381 ETAMIN_NAND_GPMC_CONFIG2,
382 ETAMIN_NAND_GPMC_CONFIG3,
383 ETAMIN_NAND_GPMC_CONFIG4,
384 ETAMIN_NAND_GPMC_CONFIG5,
385 ETAMIN_NAND_GPMC_CONFIG6,
386 /*CONFIG7- computed as params */
387};
388
389static void board_nand_cs_init(void)
390{
391 enable_gpmc_cs_config(gpmc_nand_config, &gpmc_cfg->cs[1],
392 0x18000000, GPMC_SIZE_16M);
393}
394#endif
395
Heiko Schocherc0dcece2013-08-19 16:39:01 +0200396#include "../common/board.c"