blob: 94bd71ad0976460912e91154d9ea255ec9f1f756 [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 *
12 * Copyright (C) 2011, Texas Instruments, Incorporated - http://www.ti.com/
Heiko Schocher499c4982013-08-19 16:39:01 +020013 */
14
15#include <common.h>
Simon Glass5e6201b2019-08-01 09:46:51 -060016#include <env.h>
Heiko Schocher499c4982013-08-19 16:39:01 +020017#include <errno.h>
Simon Glassa7b51302019-11-14 12:57:46 -070018#include <init.h>
Heiko Schocher499c4982013-08-19 16:39:01 +020019#include <spl.h>
20#include <asm/arch/cpu.h>
21#include <asm/arch/hardware.h>
22#include <asm/arch/omap.h>
23#include <asm/arch/ddr_defs.h>
24#include <asm/arch/clock.h>
25#include <asm/arch/gpio.h>
26#include <asm/arch/mmc_host_def.h>
27#include <asm/arch/sys_proto.h>
Heiko Schochercbec11a2016-06-07 08:55:45 +020028#include <asm/arch/mem.h>
Heiko Schocher499c4982013-08-19 16:39:01 +020029#include <asm/io.h>
30#include <asm/emif.h>
31#include <asm/gpio.h>
32#include <i2c.h>
33#include <miiphy.h>
34#include <cpsw.h>
35#include <watchdog.h>
36#include "board.h"
37#include "../common/factoryset.h"
Heiko Schochercbec11a2016-06-07 08:55:45 +020038#include <nand.h>
Heiko Schocher499c4982013-08-19 16:39:01 +020039
Heiko Schocher499c4982013-08-19 16:39:01 +020040#ifdef CONFIG_SPL_BUILD
Egli, Samuel097951b2014-05-05 16:50:43 +020041static struct draco_baseboard_id __attribute__((section(".data"))) settings;
Egli, Samuelbc38fa42014-04-24 17:57:53 +020042
43#if DDR_PLL_FREQ == 303
Heiko Schochercbec11a2016-06-07 08:55:45 +020044#if !defined(CONFIG_TARGET_ETAMIN)
Egli, Samuelbc38fa42014-04-24 17:57:53 +020045/* Default@303MHz-i0 */
46const struct ddr3_data ddr3_default = {
47 0x33524444, 0x56312e35, 0x0080, 0x0000, 0x003A, 0x003F, 0x009F,
Heiko Schocherd17c3fc2015-06-16 14:59:34 +020048 0x0079, 0x0888A39B, 0x26517FDA, 0x501F84EF, 0x00100206, 0x61A44A32,
Egli, Samuelbc38fa42014-04-24 17:57:53 +020049 0x0000093B, 0x0000014A,
50 "default name @303MHz \0",
51 "default marking \0",
52};
Heiko Schochercbec11a2016-06-07 08:55:45 +020053#else
54/* etamin board */
55const struct ddr3_data ddr3_default = {
56 0x33524444, 0x56312e36, 0x0080, 0x0000, 0x003A, 0x0010, 0x009F,
57 0x0050, 0x0888A39B, 0x266D7FDA, 0x501F86AF, 0x00100206, 0x61A44BB2,
58 0x0000093B, 0x0000018A,
59 "test-etamin \0",
60 "generic-8Gbit \0",
61};
62#endif
Egli, Samuelbc38fa42014-04-24 17:57:53 +020063#elif DDR_PLL_FREQ == 400
64/* Default@400MHz-i0 */
Heiko Schocher499c4982013-08-19 16:39:01 +020065const struct ddr3_data ddr3_default = {
Egli, Samuelbc38fa42014-04-24 17:57:53 +020066 0x33524444, 0x56312e35, 0x0080, 0x0000, 0x0039, 0x0046, 0x00ab,
67 0x0080, 0x0AAAA4DB, 0x26307FDA, 0x501F821F, 0x00100207, 0x61A45232,
Samuel Egli8069bfe2013-11-04 14:05:03 +010068 0x00000618, 0x0000014A,
Egli, Samuelbc38fa42014-04-24 17:57:53 +020069 "default name @400MHz \0",
70 "default marking \0",
Heiko Schocher499c4982013-08-19 16:39:01 +020071};
Egli, Samuelbc38fa42014-04-24 17:57:53 +020072#endif
Heiko Schocher499c4982013-08-19 16:39:01 +020073
74static void set_default_ddr3_timings(void)
75{
76 printf("Set default DDR3 settings\n");
77 settings.ddr3 = ddr3_default;
78}
79
80static void print_ddr3_timings(void)
81{
Egli, Samuelbc38fa42014-04-24 17:57:53 +020082 printf("\nDDR3\n");
83 printf("clock:\t\t%d MHz\n", DDR_PLL_FREQ);
84 printf("device:\t\t%s\n", settings.ddr3.manu_name);
85 printf("marking:\t%s\n", settings.ddr3.manu_marking);
Heiko Schocherd17c3fc2015-06-16 14:59:34 +020086 printf("%-20s, %-8s, %-8s, %-4s\n", "timing parameters", "eeprom",
87 "default", "diff");
Heiko Schocher499c4982013-08-19 16:39:01 +020088 PRINTARGS(magic);
89 PRINTARGS(version);
90 PRINTARGS(ddr3_sratio);
91 PRINTARGS(iclkout);
92
93 PRINTARGS(dt0rdsratio0);
94 PRINTARGS(dt0wdsratio0);
95 PRINTARGS(dt0fwsratio0);
96 PRINTARGS(dt0wrsratio0);
97
98 PRINTARGS(sdram_tim1);
99 PRINTARGS(sdram_tim2);
100 PRINTARGS(sdram_tim3);
101
102 PRINTARGS(emif_ddr_phy_ctlr_1);
103
104 PRINTARGS(sdram_config);
105 PRINTARGS(ref_ctrl);
Samuel Egli8069bfe2013-11-04 14:05:03 +0100106 PRINTARGS(ioctr_val);
Heiko Schocher499c4982013-08-19 16:39:01 +0200107}
108
109static void print_chip_data(void)
110{
Heiko Schocherd17c3fc2015-06-16 14:59:34 +0200111 struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
112 dpll_mpu_opp100.m = am335x_get_efuse_mpu_max_freq(cdev);
Egli, Samuelbc38fa42014-04-24 17:57:53 +0200113 printf("\nCPU BOARD\n");
114 printf("device: \t'%s'\n", settings.chip.sdevname);
115 printf("hw version: \t'%s'\n", settings.chip.shwver);
Heiko Schocherd17c3fc2015-06-16 14:59:34 +0200116 printf("max freq: \t%d MHz\n", dpll_mpu_opp100.m);
Heiko Schocher499c4982013-08-19 16:39:01 +0200117}
118#endif /* CONFIG_SPL_BUILD */
119
Heiko Schocher4453d7a2016-06-07 08:55:43 +0200120#define AM335X_NAND_ECC_MASK 0x0f
121#define AM335X_NAND_ECC_TYPE_16 0x02
122
123static int ecc_type;
124
125struct am335x_nand_geometry {
126 u32 magic;
127 u8 nand_geo_addr;
128 u8 nand_geo_page;
129 u8 nand_bus;
130};
131
132static int draco_read_nand_geometry(void)
133{
134 struct am335x_nand_geometry geo;
135
136 /* Read NAND geometry */
137 if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0x80, 2,
138 (uchar *)&geo, sizeof(struct am335x_nand_geometry))) {
139 printf("Could not read the NAND geomtery; something fundamentally wrong on the I2C bus.\n");
140 return -EIO;
141 }
142 if (geo.magic != 0xa657b310) {
143 printf("%s: bad magic: %x\n", __func__, geo.magic);
144 return -EFAULT;
145 }
146 if ((geo.nand_bus & AM335X_NAND_ECC_MASK) == AM335X_NAND_ECC_TYPE_16)
147 ecc_type = 16;
148 else
149 ecc_type = 8;
150
151 return 0;
152}
153
Heiko Schocher499c4982013-08-19 16:39:01 +0200154/*
155 * Read header information from EEPROM into global structure.
156 */
157static int read_eeprom(void)
158{
159 /* Check if baseboard eeprom is available */
160 if (i2c_probe(CONFIG_SYS_I2C_EEPROM_ADDR)) {
161 printf("Could not probe the EEPROM; something fundamentally wrong on the I2C bus.\n");
162 return 1;
163 }
164
165#ifdef CONFIG_SPL_BUILD
166 /* Read Siemens eeprom data (DDR3) */
167 if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, EEPROM_ADDR_DDR3, 2,
168 (uchar *)&settings.ddr3, sizeof(struct ddr3_data))) {
169 printf("Could not read the EEPROM; something fundamentally wrong on the I2C bus.\nUse default DDR3 timings\n");
170 set_default_ddr3_timings();
171 }
172 /* Read Siemens eeprom data (CHIP) */
173 if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, EEPROM_ADDR_CHIP, 2,
174 (uchar *)&settings.chip, sizeof(settings.chip)))
175 printf("Could not read chip settings\n");
176
177 if (ddr3_default.magic == settings.ddr3.magic &&
178 ddr3_default.version == settings.ddr3.version) {
179 printf("Using DDR3 settings from EEPROM\n");
180 } else {
181 if (ddr3_default.magic != settings.ddr3.magic)
Egli, Samuelbc38fa42014-04-24 17:57:53 +0200182 printf("Warning: No valid DDR3 data in eeprom.\n");
Heiko Schocher499c4982013-08-19 16:39:01 +0200183 if (ddr3_default.version != settings.ddr3.version)
Egli, Samuelbc38fa42014-04-24 17:57:53 +0200184 printf("Warning: DDR3 data version does not match.\n");
Heiko Schocher499c4982013-08-19 16:39:01 +0200185
186 printf("Using default settings\n");
187 set_default_ddr3_timings();
188 }
189
Egli, Samuel097951b2014-05-05 16:50:43 +0200190 if (MAGIC_CHIP == settings.chip.magic)
Heiko Schocher499c4982013-08-19 16:39:01 +0200191 print_chip_data();
Egli, Samuel097951b2014-05-05 16:50:43 +0200192 else
Egli, Samuelbc38fa42014-04-24 17:57:53 +0200193 printf("Warning: No chip data in eeprom\n");
Heiko Schocher499c4982013-08-19 16:39:01 +0200194
195 print_ddr3_timings();
Heiko Schocher4453d7a2016-06-07 08:55:43 +0200196
197 return draco_read_nand_geometry();
Heiko Schocher499c4982013-08-19 16:39:01 +0200198#endif
199 return 0;
200}
201
202#ifdef CONFIG_SPL_BUILD
203static void board_init_ddr(void)
204{
Egli, Samuel097951b2014-05-05 16:50:43 +0200205struct emif_regs draco_ddr3_emif_reg_data = {
Heiko Schocher499c4982013-08-19 16:39:01 +0200206 .zq_config = 0x50074BE4,
207};
208
Egli, Samuel097951b2014-05-05 16:50:43 +0200209struct ddr_data draco_ddr3_data = {
Heiko Schocher499c4982013-08-19 16:39:01 +0200210};
211
Egli, Samuel097951b2014-05-05 16:50:43 +0200212struct cmd_control draco_ddr3_cmd_ctrl_data = {
Heiko Schocher499c4982013-08-19 16:39:01 +0200213};
Lokesh Vutla303b2672013-12-10 15:02:21 +0530214
Egli, Samuel097951b2014-05-05 16:50:43 +0200215struct ctrl_ioregs draco_ddr3_ioregs = {
Lokesh Vutla303b2672013-12-10 15:02:21 +0530216};
217
Heiko Schocher499c4982013-08-19 16:39:01 +0200218 /* pass values from eeprom */
Egli, Samuel097951b2014-05-05 16:50:43 +0200219 draco_ddr3_emif_reg_data.sdram_tim1 = settings.ddr3.sdram_tim1;
220 draco_ddr3_emif_reg_data.sdram_tim2 = settings.ddr3.sdram_tim2;
221 draco_ddr3_emif_reg_data.sdram_tim3 = settings.ddr3.sdram_tim3;
222 draco_ddr3_emif_reg_data.emif_ddr_phy_ctlr_1 =
Heiko Schocher499c4982013-08-19 16:39:01 +0200223 settings.ddr3.emif_ddr_phy_ctlr_1;
Egli, Samuel097951b2014-05-05 16:50:43 +0200224 draco_ddr3_emif_reg_data.sdram_config = settings.ddr3.sdram_config;
Heiko Schochercbec11a2016-06-07 08:55:45 +0200225 draco_ddr3_emif_reg_data.sdram_config2 = 0x08000000;
Egli, Samuel097951b2014-05-05 16:50:43 +0200226 draco_ddr3_emif_reg_data.ref_ctrl = settings.ddr3.ref_ctrl;
Heiko Schocher499c4982013-08-19 16:39:01 +0200227
Egli, Samuel097951b2014-05-05 16:50:43 +0200228 draco_ddr3_data.datardsratio0 = settings.ddr3.dt0rdsratio0;
229 draco_ddr3_data.datawdsratio0 = settings.ddr3.dt0wdsratio0;
230 draco_ddr3_data.datafwsratio0 = settings.ddr3.dt0fwsratio0;
231 draco_ddr3_data.datawrsratio0 = settings.ddr3.dt0wrsratio0;
Heiko Schocher499c4982013-08-19 16:39:01 +0200232
Egli, Samuel097951b2014-05-05 16:50:43 +0200233 draco_ddr3_cmd_ctrl_data.cmd0csratio = settings.ddr3.ddr3_sratio;
234 draco_ddr3_cmd_ctrl_data.cmd0iclkout = settings.ddr3.iclkout;
235 draco_ddr3_cmd_ctrl_data.cmd1csratio = settings.ddr3.ddr3_sratio;
236 draco_ddr3_cmd_ctrl_data.cmd1iclkout = settings.ddr3.iclkout;
237 draco_ddr3_cmd_ctrl_data.cmd2csratio = settings.ddr3.ddr3_sratio;
238 draco_ddr3_cmd_ctrl_data.cmd2iclkout = settings.ddr3.iclkout;
Heiko Schocher499c4982013-08-19 16:39:01 +0200239
Egli, Samuel097951b2014-05-05 16:50:43 +0200240 draco_ddr3_ioregs.cm0ioctl = settings.ddr3.ioctr_val,
241 draco_ddr3_ioregs.cm1ioctl = settings.ddr3.ioctr_val,
242 draco_ddr3_ioregs.cm2ioctl = settings.ddr3.ioctr_val,
243 draco_ddr3_ioregs.dt0ioctl = settings.ddr3.ioctr_val,
244 draco_ddr3_ioregs.dt1ioctl = settings.ddr3.ioctr_val,
Lokesh Vutla303b2672013-12-10 15:02:21 +0530245
Egli, Samuel097951b2014-05-05 16:50:43 +0200246 config_ddr(DDR_PLL_FREQ, &draco_ddr3_ioregs, &draco_ddr3_data,
247 &draco_ddr3_cmd_ctrl_data, &draco_ddr3_emif_reg_data, 0);
Heiko Schocher499c4982013-08-19 16:39:01 +0200248}
249
250static void spl_siemens_board_init(void)
251{
252 return;
253}
254#endif /* if def CONFIG_SPL_BUILD */
255
Heiko Schocherd17c3fc2015-06-16 14:59:34 +0200256#ifdef CONFIG_BOARD_LATE_INIT
257int board_late_init(void)
258{
Heiko Schocher4453d7a2016-06-07 08:55:43 +0200259 int ret;
260
261 ret = draco_read_nand_geometry();
262 if (ret != 0)
263 return ret;
264
265 nand_curr_device = 0;
266 omap_nand_switch_ecc(1, ecc_type);
Heiko Schochercbec11a2016-06-07 08:55:45 +0200267#ifdef CONFIG_TARGET_ETAMIN
268 nand_curr_device = 1;
269 omap_nand_switch_ecc(1, ecc_type);
270#endif
Heiko Schocherd17c3fc2015-06-16 14:59:34 +0200271#ifdef CONFIG_FACTORYSET
272 /* Set ASN in environment*/
273 if (factory_dat.asn[0] != 0) {
Simon Glass6a38e412017-08-03 12:22:09 -0600274 env_set("dtb_name", (char *)factory_dat.asn);
Heiko Schocherd17c3fc2015-06-16 14:59:34 +0200275 } else {
276 /* dtb suffix gets added in load script */
Simon Glass6a38e412017-08-03 12:22:09 -0600277 env_set("dtb_name", "am335x-draco");
Heiko Schocherd17c3fc2015-06-16 14:59:34 +0200278 }
279#else
Simon Glass6a38e412017-08-03 12:22:09 -0600280 env_set("dtb_name", "am335x-draco");
Heiko Schocherd17c3fc2015-06-16 14:59:34 +0200281#endif
282
283 return 0;
284}
285#endif
286
Heiko Schocher499c4982013-08-19 16:39:01 +0200287#if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) || \
288 (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD))
289static void cpsw_control(int enabled)
290{
291 /* VTP can be added here */
292
293 return;
294}
295
296static struct cpsw_slave_data cpsw_slaves[] = {
297 {
298 .slave_reg_ofs = 0x208,
299 .sliver_reg_ofs = 0xd80,
Mugunthan V N4944f372014-02-18 07:31:52 -0500300 .phy_addr = 0,
Heiko Schocher499c4982013-08-19 16:39:01 +0200301 .phy_if = PHY_INTERFACE_MODE_MII,
302 },
303};
304
305static struct cpsw_platform_data cpsw_data = {
306 .mdio_base = CPSW_MDIO_BASE,
307 .cpsw_base = CPSW_BASE,
308 .mdio_div = 0xff,
309 .channels = 4,
310 .cpdma_reg_ofs = 0x800,
311 .slaves = 1,
312 .slave_data = cpsw_slaves,
313 .ale_reg_ofs = 0xd00,
314 .ale_entries = 1024,
315 .host_port_reg_ofs = 0x108,
316 .hw_stats_reg_ofs = 0x900,
317 .bd_ram_ofs = 0x2000,
318 .mac_control = (1 << 5),
319 .control = cpsw_control,
320 .host_port_num = 0,
321 .version = CPSW_CTRL_VERSION_2,
322};
323
324#if defined(CONFIG_DRIVER_TI_CPSW) || \
Paul Kocialkowskif34dfcb2015-08-04 17:04:06 +0200325 (defined(CONFIG_USB_ETHER) && defined(CONFIG_USB_MUSB_GADGET))
Heiko Schocher499c4982013-08-19 16:39:01 +0200326int board_eth_init(bd_t *bis)
327{
328 struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
329 int n = 0;
330 int rv;
331
Simon Glass6a38e412017-08-03 12:22:09 -0600332 factoryset_env_set();
Heiko Schocher499c4982013-08-19 16:39:01 +0200333
Heiko Schocher499c4982013-08-19 16:39:01 +0200334 /* Set rgmii mode and enable rmii clock to be sourced from chip */
335 writel((RMII_MODE_ENABLE | RMII_CHIPCKL_ENABLE), &cdev->miisel);
336
337 rv = cpsw_register(&cpsw_data);
338 if (rv < 0)
339 printf("Error %d registering CPSW switch\n", rv);
340 else
341 n += rv;
342 return n;
343}
Stefan Roese9aee57f2014-03-12 10:45:41 +0100344
345static int do_switch_reset(cmd_tbl_t *cmdtp, int flag, int argc,
Heiko Schochercbec11a2016-06-07 08:55:45 +0200346 char *const argv[])
Stefan Roese9aee57f2014-03-12 10:45:41 +0100347{
348 /* Reset SMSC LAN9303 switch for default configuration */
349 gpio_request(GPIO_LAN9303_NRST, "nRST");
350 gpio_direction_output(GPIO_LAN9303_NRST, 0);
351 /* assert active low reset for 200us */
352 udelay(200);
353 gpio_set_value(GPIO_LAN9303_NRST, 1);
354
355 return 0;
356};
357
358U_BOOT_CMD(
359 switch_rst, CONFIG_SYS_MAXARGS, 1, do_switch_reset,
360 "Reset LAN9303 switch via its reset pin",
361 ""
362);
Heiko Schocher499c4982013-08-19 16:39:01 +0200363#endif /* #if defined(CONFIG_DRIVER_TI_CPSW) */
364#endif /* #if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) */
365
Heiko Schochercbec11a2016-06-07 08:55:45 +0200366#ifdef CONFIG_NAND_CS_INIT
367/* GPMC definitions for second nand cs1 */
368static const u32 gpmc_nand_config[] = {
369 ETAMIN_NAND_GPMC_CONFIG1,
370 ETAMIN_NAND_GPMC_CONFIG2,
371 ETAMIN_NAND_GPMC_CONFIG3,
372 ETAMIN_NAND_GPMC_CONFIG4,
373 ETAMIN_NAND_GPMC_CONFIG5,
374 ETAMIN_NAND_GPMC_CONFIG6,
375 /*CONFIG7- computed as params */
376};
377
378static void board_nand_cs_init(void)
379{
380 enable_gpmc_cs_config(gpmc_nand_config, &gpmc_cfg->cs[1],
381 0x18000000, GPMC_SIZE_16M);
382}
383#endif
384
Heiko Schocher499c4982013-08-19 16:39:01 +0200385#include "../common/board.c"