blob: 8b13d23aca7006a5b28e853a95d8a42e5186fdc2 [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"
40#include "../common/factoryset.h"
Heiko Schochercbec11a2016-06-07 08:55:45 +020041#include <nand.h>
Heiko Schocher499c4982013-08-19 16:39:01 +020042
Heiko Schocher499c4982013-08-19 16:39:01 +020043#ifdef CONFIG_SPL_BUILD
Marek BehĂșn4bebdd32021-05-20 13:23:52 +020044static struct draco_baseboard_id __section(".data") settings;
Egli, Samuelbc38fa42014-04-24 17:57:53 +020045
46#if DDR_PLL_FREQ == 303
Heiko Schochercbec11a2016-06-07 08:55:45 +020047#if !defined(CONFIG_TARGET_ETAMIN)
Egli, Samuelbc38fa42014-04-24 17:57:53 +020048/* Default@303MHz-i0 */
49const struct ddr3_data ddr3_default = {
50 0x33524444, 0x56312e35, 0x0080, 0x0000, 0x003A, 0x003F, 0x009F,
Heiko Schocherd17c3fc2015-06-16 14:59:34 +020051 0x0079, 0x0888A39B, 0x26517FDA, 0x501F84EF, 0x00100206, 0x61A44A32,
Egli, Samuelbc38fa42014-04-24 17:57:53 +020052 0x0000093B, 0x0000014A,
53 "default name @303MHz \0",
54 "default marking \0",
55};
Heiko Schochercbec11a2016-06-07 08:55:45 +020056#else
57/* etamin board */
58const struct ddr3_data ddr3_default = {
59 0x33524444, 0x56312e36, 0x0080, 0x0000, 0x003A, 0x0010, 0x009F,
60 0x0050, 0x0888A39B, 0x266D7FDA, 0x501F86AF, 0x00100206, 0x61A44BB2,
61 0x0000093B, 0x0000018A,
62 "test-etamin \0",
63 "generic-8Gbit \0",
64};
65#endif
Egli, Samuelbc38fa42014-04-24 17:57:53 +020066#elif DDR_PLL_FREQ == 400
67/* Default@400MHz-i0 */
Heiko Schocher499c4982013-08-19 16:39:01 +020068const struct ddr3_data ddr3_default = {
Egli, Samuelbc38fa42014-04-24 17:57:53 +020069 0x33524444, 0x56312e35, 0x0080, 0x0000, 0x0039, 0x0046, 0x00ab,
70 0x0080, 0x0AAAA4DB, 0x26307FDA, 0x501F821F, 0x00100207, 0x61A45232,
Samuel Egli8069bfe2013-11-04 14:05:03 +010071 0x00000618, 0x0000014A,
Egli, Samuelbc38fa42014-04-24 17:57:53 +020072 "default name @400MHz \0",
73 "default marking \0",
Heiko Schocher499c4982013-08-19 16:39:01 +020074};
Egli, Samuelbc38fa42014-04-24 17:57:53 +020075#endif
Heiko Schocher499c4982013-08-19 16:39:01 +020076
77static void set_default_ddr3_timings(void)
78{
79 printf("Set default DDR3 settings\n");
80 settings.ddr3 = ddr3_default;
81}
82
83static void print_ddr3_timings(void)
84{
Egli, Samuelbc38fa42014-04-24 17:57:53 +020085 printf("\nDDR3\n");
86 printf("clock:\t\t%d MHz\n", DDR_PLL_FREQ);
87 printf("device:\t\t%s\n", settings.ddr3.manu_name);
88 printf("marking:\t%s\n", settings.ddr3.manu_marking);
Heiko Schocherd17c3fc2015-06-16 14:59:34 +020089 printf("%-20s, %-8s, %-8s, %-4s\n", "timing parameters", "eeprom",
90 "default", "diff");
Heiko Schocher499c4982013-08-19 16:39:01 +020091 PRINTARGS(magic);
92 PRINTARGS(version);
93 PRINTARGS(ddr3_sratio);
94 PRINTARGS(iclkout);
95
96 PRINTARGS(dt0rdsratio0);
97 PRINTARGS(dt0wdsratio0);
98 PRINTARGS(dt0fwsratio0);
99 PRINTARGS(dt0wrsratio0);
100
101 PRINTARGS(sdram_tim1);
102 PRINTARGS(sdram_tim2);
103 PRINTARGS(sdram_tim3);
104
105 PRINTARGS(emif_ddr_phy_ctlr_1);
106
107 PRINTARGS(sdram_config);
108 PRINTARGS(ref_ctrl);
Samuel Egli8069bfe2013-11-04 14:05:03 +0100109 PRINTARGS(ioctr_val);
Heiko Schocher499c4982013-08-19 16:39:01 +0200110}
111
112static void print_chip_data(void)
113{
Heiko Schocherd17c3fc2015-06-16 14:59:34 +0200114 struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
115 dpll_mpu_opp100.m = am335x_get_efuse_mpu_max_freq(cdev);
Egli, Samuelbc38fa42014-04-24 17:57:53 +0200116 printf("\nCPU BOARD\n");
117 printf("device: \t'%s'\n", settings.chip.sdevname);
118 printf("hw version: \t'%s'\n", settings.chip.shwver);
Heiko Schocherd17c3fc2015-06-16 14:59:34 +0200119 printf("max freq: \t%d MHz\n", dpll_mpu_opp100.m);
Heiko Schocher499c4982013-08-19 16:39:01 +0200120}
121#endif /* CONFIG_SPL_BUILD */
122
Heiko Schocher4453d7a2016-06-07 08:55:43 +0200123#define AM335X_NAND_ECC_MASK 0x0f
124#define AM335X_NAND_ECC_TYPE_16 0x02
125
126static int ecc_type;
127
128struct am335x_nand_geometry {
129 u32 magic;
130 u8 nand_geo_addr;
131 u8 nand_geo_page;
132 u8 nand_bus;
133};
134
Tom Rini1cfc1272021-08-17 17:59:40 -0400135#define EEPROM_ADDR 0x50
136#define EEPROM_ADDR_DDR3 0x90
137#define EEPROM_ADDR_CHIP 0x120
138
Heiko Schocher4453d7a2016-06-07 08:55:43 +0200139static int draco_read_nand_geometry(void)
140{
141 struct am335x_nand_geometry geo;
142
143 /* Read NAND geometry */
Tom Rini1cfc1272021-08-17 17:59:40 -0400144 if (i2c_read(EEPROM_ADDR, 0x80, 2,
Heiko Schocher4453d7a2016-06-07 08:55:43 +0200145 (uchar *)&geo, sizeof(struct am335x_nand_geometry))) {
146 printf("Could not read the NAND geomtery; something fundamentally wrong on the I2C bus.\n");
147 return -EIO;
148 }
149 if (geo.magic != 0xa657b310) {
150 printf("%s: bad magic: %x\n", __func__, geo.magic);
151 return -EFAULT;
152 }
153 if ((geo.nand_bus & AM335X_NAND_ECC_MASK) == AM335X_NAND_ECC_TYPE_16)
154 ecc_type = 16;
155 else
156 ecc_type = 8;
157
158 return 0;
159}
160
Heiko Schocher499c4982013-08-19 16:39:01 +0200161/*
162 * Read header information from EEPROM into global structure.
163 */
164static int read_eeprom(void)
165{
166 /* Check if baseboard eeprom is available */
Tom Rini1cfc1272021-08-17 17:59:40 -0400167 if (i2c_probe(EEPROM_ADDR)) {
Heiko Schocher499c4982013-08-19 16:39:01 +0200168 printf("Could not probe the EEPROM; something fundamentally wrong on the I2C bus.\n");
169 return 1;
170 }
171
172#ifdef CONFIG_SPL_BUILD
173 /* Read Siemens eeprom data (DDR3) */
Tom Rini1cfc1272021-08-17 17:59:40 -0400174 if (i2c_read(EEPROM_ADDR, EEPROM_ADDR_DDR3, 2,
Heiko Schocher499c4982013-08-19 16:39:01 +0200175 (uchar *)&settings.ddr3, sizeof(struct ddr3_data))) {
176 printf("Could not read the EEPROM; something fundamentally wrong on the I2C bus.\nUse default DDR3 timings\n");
177 set_default_ddr3_timings();
178 }
179 /* Read Siemens eeprom data (CHIP) */
Tom Rini1cfc1272021-08-17 17:59:40 -0400180 if (i2c_read(EEPROM_ADDR, EEPROM_ADDR_CHIP, 2,
Heiko Schocher499c4982013-08-19 16:39:01 +0200181 (uchar *)&settings.chip, sizeof(settings.chip)))
182 printf("Could not read chip settings\n");
183
184 if (ddr3_default.magic == settings.ddr3.magic &&
185 ddr3_default.version == settings.ddr3.version) {
186 printf("Using DDR3 settings from EEPROM\n");
187 } else {
188 if (ddr3_default.magic != settings.ddr3.magic)
Egli, Samuelbc38fa42014-04-24 17:57:53 +0200189 printf("Warning: No valid DDR3 data in eeprom.\n");
Heiko Schocher499c4982013-08-19 16:39:01 +0200190 if (ddr3_default.version != settings.ddr3.version)
Egli, Samuelbc38fa42014-04-24 17:57:53 +0200191 printf("Warning: DDR3 data version does not match.\n");
Heiko Schocher499c4982013-08-19 16:39:01 +0200192
193 printf("Using default settings\n");
194 set_default_ddr3_timings();
195 }
196
Egli, Samuel097951b2014-05-05 16:50:43 +0200197 if (MAGIC_CHIP == settings.chip.magic)
Heiko Schocher499c4982013-08-19 16:39:01 +0200198 print_chip_data();
Egli, Samuel097951b2014-05-05 16:50:43 +0200199 else
Egli, Samuelbc38fa42014-04-24 17:57:53 +0200200 printf("Warning: No chip data in eeprom\n");
Heiko Schocher499c4982013-08-19 16:39:01 +0200201
202 print_ddr3_timings();
Heiko Schocher4453d7a2016-06-07 08:55:43 +0200203
204 return draco_read_nand_geometry();
Heiko Schocher499c4982013-08-19 16:39:01 +0200205#endif
206 return 0;
207}
208
209#ifdef CONFIG_SPL_BUILD
210static void board_init_ddr(void)
211{
Egli, Samuel097951b2014-05-05 16:50:43 +0200212struct emif_regs draco_ddr3_emif_reg_data = {
Heiko Schocher499c4982013-08-19 16:39:01 +0200213 .zq_config = 0x50074BE4,
214};
215
Egli, Samuel097951b2014-05-05 16:50:43 +0200216struct ddr_data draco_ddr3_data = {
Heiko Schocher499c4982013-08-19 16:39:01 +0200217};
218
Egli, Samuel097951b2014-05-05 16:50:43 +0200219struct cmd_control draco_ddr3_cmd_ctrl_data = {
Heiko Schocher499c4982013-08-19 16:39:01 +0200220};
Lokesh Vutla303b2672013-12-10 15:02:21 +0530221
Egli, Samuel097951b2014-05-05 16:50:43 +0200222struct ctrl_ioregs draco_ddr3_ioregs = {
Lokesh Vutla303b2672013-12-10 15:02:21 +0530223};
224
Heiko Schocher499c4982013-08-19 16:39:01 +0200225 /* pass values from eeprom */
Egli, Samuel097951b2014-05-05 16:50:43 +0200226 draco_ddr3_emif_reg_data.sdram_tim1 = settings.ddr3.sdram_tim1;
227 draco_ddr3_emif_reg_data.sdram_tim2 = settings.ddr3.sdram_tim2;
228 draco_ddr3_emif_reg_data.sdram_tim3 = settings.ddr3.sdram_tim3;
229 draco_ddr3_emif_reg_data.emif_ddr_phy_ctlr_1 =
Heiko Schocher499c4982013-08-19 16:39:01 +0200230 settings.ddr3.emif_ddr_phy_ctlr_1;
Egli, Samuel097951b2014-05-05 16:50:43 +0200231 draco_ddr3_emif_reg_data.sdram_config = settings.ddr3.sdram_config;
Heiko Schochercbec11a2016-06-07 08:55:45 +0200232 draco_ddr3_emif_reg_data.sdram_config2 = 0x08000000;
Egli, Samuel097951b2014-05-05 16:50:43 +0200233 draco_ddr3_emif_reg_data.ref_ctrl = settings.ddr3.ref_ctrl;
Heiko Schocher499c4982013-08-19 16:39:01 +0200234
Egli, Samuel097951b2014-05-05 16:50:43 +0200235 draco_ddr3_data.datardsratio0 = settings.ddr3.dt0rdsratio0;
236 draco_ddr3_data.datawdsratio0 = settings.ddr3.dt0wdsratio0;
237 draco_ddr3_data.datafwsratio0 = settings.ddr3.dt0fwsratio0;
238 draco_ddr3_data.datawrsratio0 = settings.ddr3.dt0wrsratio0;
Heiko Schocher499c4982013-08-19 16:39:01 +0200239
Egli, Samuel097951b2014-05-05 16:50:43 +0200240 draco_ddr3_cmd_ctrl_data.cmd0csratio = settings.ddr3.ddr3_sratio;
241 draco_ddr3_cmd_ctrl_data.cmd0iclkout = settings.ddr3.iclkout;
242 draco_ddr3_cmd_ctrl_data.cmd1csratio = settings.ddr3.ddr3_sratio;
243 draco_ddr3_cmd_ctrl_data.cmd1iclkout = settings.ddr3.iclkout;
244 draco_ddr3_cmd_ctrl_data.cmd2csratio = settings.ddr3.ddr3_sratio;
245 draco_ddr3_cmd_ctrl_data.cmd2iclkout = settings.ddr3.iclkout;
Heiko Schocher499c4982013-08-19 16:39:01 +0200246
Egli, Samuel097951b2014-05-05 16:50:43 +0200247 draco_ddr3_ioregs.cm0ioctl = settings.ddr3.ioctr_val,
248 draco_ddr3_ioregs.cm1ioctl = settings.ddr3.ioctr_val,
249 draco_ddr3_ioregs.cm2ioctl = settings.ddr3.ioctr_val,
250 draco_ddr3_ioregs.dt0ioctl = settings.ddr3.ioctr_val,
251 draco_ddr3_ioregs.dt1ioctl = settings.ddr3.ioctr_val,
Lokesh Vutla303b2672013-12-10 15:02:21 +0530252
Egli, Samuel097951b2014-05-05 16:50:43 +0200253 config_ddr(DDR_PLL_FREQ, &draco_ddr3_ioregs, &draco_ddr3_data,
254 &draco_ddr3_cmd_ctrl_data, &draco_ddr3_emif_reg_data, 0);
Heiko Schocher499c4982013-08-19 16:39:01 +0200255}
256
257static void spl_siemens_board_init(void)
258{
259 return;
260}
261#endif /* if def CONFIG_SPL_BUILD */
262
Heiko Schocherd17c3fc2015-06-16 14:59:34 +0200263#ifdef CONFIG_BOARD_LATE_INIT
264int board_late_init(void)
265{
Heiko Schocher4453d7a2016-06-07 08:55:43 +0200266 int ret;
267
268 ret = draco_read_nand_geometry();
269 if (ret != 0)
270 return ret;
271
272 nand_curr_device = 0;
273 omap_nand_switch_ecc(1, ecc_type);
Heiko Schochercbec11a2016-06-07 08:55:45 +0200274#ifdef CONFIG_TARGET_ETAMIN
275 nand_curr_device = 1;
276 omap_nand_switch_ecc(1, ecc_type);
277#endif
Heiko Schocherd17c3fc2015-06-16 14:59:34 +0200278#ifdef CONFIG_FACTORYSET
279 /* Set ASN in environment*/
280 if (factory_dat.asn[0] != 0) {
Simon Glass6a38e412017-08-03 12:22:09 -0600281 env_set("dtb_name", (char *)factory_dat.asn);
Heiko Schocherd17c3fc2015-06-16 14:59:34 +0200282 } else {
283 /* dtb suffix gets added in load script */
Simon Glass6a38e412017-08-03 12:22:09 -0600284 env_set("dtb_name", "am335x-draco");
Heiko Schocherd17c3fc2015-06-16 14:59:34 +0200285 }
286#else
Simon Glass6a38e412017-08-03 12:22:09 -0600287 env_set("dtb_name", "am335x-draco");
Heiko Schocherd17c3fc2015-06-16 14:59:34 +0200288#endif
289
290 return 0;
291}
292#endif
293
Heiko Schocher499c4982013-08-19 16:39:01 +0200294#if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) || \
Simon Glasse5cd9a42021-07-10 21:14:26 -0600295 (defined(CONFIG_SPL_ETH) && defined(CONFIG_SPL_BUILD))
Heiko Schocher499c4982013-08-19 16:39:01 +0200296static void cpsw_control(int enabled)
297{
298 /* VTP can be added here */
299
300 return;
301}
302
303static struct cpsw_slave_data cpsw_slaves[] = {
304 {
305 .slave_reg_ofs = 0x208,
306 .sliver_reg_ofs = 0xd80,
Mugunthan V N4944f372014-02-18 07:31:52 -0500307 .phy_addr = 0,
Heiko Schocher499c4982013-08-19 16:39:01 +0200308 .phy_if = PHY_INTERFACE_MODE_MII,
309 },
310};
311
312static struct cpsw_platform_data cpsw_data = {
313 .mdio_base = CPSW_MDIO_BASE,
314 .cpsw_base = CPSW_BASE,
315 .mdio_div = 0xff,
316 .channels = 4,
317 .cpdma_reg_ofs = 0x800,
318 .slaves = 1,
319 .slave_data = cpsw_slaves,
320 .ale_reg_ofs = 0xd00,
321 .ale_entries = 1024,
322 .host_port_reg_ofs = 0x108,
323 .hw_stats_reg_ofs = 0x900,
324 .bd_ram_ofs = 0x2000,
325 .mac_control = (1 << 5),
326 .control = cpsw_control,
327 .host_port_num = 0,
328 .version = CPSW_CTRL_VERSION_2,
329};
330
331#if defined(CONFIG_DRIVER_TI_CPSW) || \
Paul Kocialkowskif34dfcb2015-08-04 17:04:06 +0200332 (defined(CONFIG_USB_ETHER) && defined(CONFIG_USB_MUSB_GADGET))
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900333int board_eth_init(struct bd_info *bis)
Heiko Schocher499c4982013-08-19 16:39:01 +0200334{
335 struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
336 int n = 0;
337 int rv;
338
Simon Glass6a38e412017-08-03 12:22:09 -0600339 factoryset_env_set();
Heiko Schocher499c4982013-08-19 16:39:01 +0200340
Heiko Schocher499c4982013-08-19 16:39:01 +0200341 /* Set rgmii mode and enable rmii clock to be sourced from chip */
342 writel((RMII_MODE_ENABLE | RMII_CHIPCKL_ENABLE), &cdev->miisel);
343
344 rv = cpsw_register(&cpsw_data);
345 if (rv < 0)
346 printf("Error %d registering CPSW switch\n", rv);
347 else
348 n += rv;
349 return n;
350}
Stefan Roese9aee57f2014-03-12 10:45:41 +0100351
Simon Glassed38aef2020-05-10 11:40:03 -0600352static int do_switch_reset(struct cmd_tbl *cmdtp, int flag, int argc,
353 char *const argv[])
Stefan Roese9aee57f2014-03-12 10:45:41 +0100354{
355 /* Reset SMSC LAN9303 switch for default configuration */
356 gpio_request(GPIO_LAN9303_NRST, "nRST");
357 gpio_direction_output(GPIO_LAN9303_NRST, 0);
358 /* assert active low reset for 200us */
359 udelay(200);
360 gpio_set_value(GPIO_LAN9303_NRST, 1);
361
362 return 0;
363};
364
365U_BOOT_CMD(
366 switch_rst, CONFIG_SYS_MAXARGS, 1, do_switch_reset,
367 "Reset LAN9303 switch via its reset pin",
368 ""
369);
Heiko Schocher499c4982013-08-19 16:39:01 +0200370#endif /* #if defined(CONFIG_DRIVER_TI_CPSW) */
371#endif /* #if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) */
372
Tom Rini4044a7a2022-12-02 16:42:38 -0500373#if CONFIG_IS_ENABLED(NAND_CS_INIT)
374#define ETAMIN_NAND_GPMC_CONFIG1 0x00000800
375#define ETAMIN_NAND_GPMC_CONFIG2 0x001e1e00
376#define ETAMIN_NAND_GPMC_CONFIG3 0x001e1e00
377#define ETAMIN_NAND_GPMC_CONFIG4 0x16051807
378#define ETAMIN_NAND_GPMC_CONFIG5 0x00151e1e
379#define ETAMIN_NAND_GPMC_CONFIG6 0x16000f80
380
Heiko Schochercbec11a2016-06-07 08:55:45 +0200381/* GPMC definitions for second nand cs1 */
382static const u32 gpmc_nand_config[] = {
383 ETAMIN_NAND_GPMC_CONFIG1,
384 ETAMIN_NAND_GPMC_CONFIG2,
385 ETAMIN_NAND_GPMC_CONFIG3,
386 ETAMIN_NAND_GPMC_CONFIG4,
387 ETAMIN_NAND_GPMC_CONFIG5,
388 ETAMIN_NAND_GPMC_CONFIG6,
389 /*CONFIG7- computed as params */
390};
391
392static void board_nand_cs_init(void)
393{
394 enable_gpmc_cs_config(gpmc_nand_config, &gpmc_cfg->cs[1],
395 0x18000000, GPMC_SIZE_16M);
396}
397#endif
398
Heiko Schocher499c4982013-08-19 16:39:01 +0200399#include "../common/board.c"