2 * Board functions for TI AM335X based draco board
3 * (C) Copyright 2013 Siemens Schweiz AG
4 * (C) Heiko Schocher, DENX Software Engineering, hs@denx.de.
8 * Board functions for TI AM335X based boards
9 * u-boot:/board/ti/am335x/board.c
11 * Copyright (C) 2011, Texas Instruments, Incorporated - http://www.ti.com/
13 * SPDX-License-Identifier: GPL-2.0+
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>
27 #include <asm/arch/mem.h>
36 #include "../common/factoryset.h"
39 DECLARE_GLOBAL_DATA_PTR
;
41 #ifdef CONFIG_SPL_BUILD
42 static struct draco_baseboard_id
__attribute__((section(".data"))) settings
;
44 #if DDR_PLL_FREQ == 303
45 #if !defined(CONFIG_TARGET_ETAMIN)
46 /* Default@303MHz-i0 */
47 const struct ddr3_data ddr3_default
= {
48 0x33524444, 0x56312e35, 0x0080, 0x0000, 0x003A, 0x003F, 0x009F,
49 0x0079, 0x0888A39B, 0x26517FDA, 0x501F84EF, 0x00100206, 0x61A44A32,
50 0x0000093B, 0x0000014A,
51 "default name @303MHz \0",
56 const struct ddr3_data ddr3_default
= {
57 0x33524444, 0x56312e36, 0x0080, 0x0000, 0x003A, 0x0010, 0x009F,
58 0x0050, 0x0888A39B, 0x266D7FDA, 0x501F86AF, 0x00100206, 0x61A44BB2,
59 0x0000093B, 0x0000018A,
64 #elif DDR_PLL_FREQ == 400
65 /* Default@400MHz-i0 */
66 const struct ddr3_data ddr3_default
= {
67 0x33524444, 0x56312e35, 0x0080, 0x0000, 0x0039, 0x0046, 0x00ab,
68 0x0080, 0x0AAAA4DB, 0x26307FDA, 0x501F821F, 0x00100207, 0x61A45232,
69 0x00000618, 0x0000014A,
70 "default name @400MHz \0",
75 static void set_default_ddr3_timings(void)
77 printf("Set default DDR3 settings\n");
78 settings
.ddr3
= ddr3_default
;
81 static void print_ddr3_timings(void)
84 printf("clock:\t\t%d MHz\n", DDR_PLL_FREQ
);
85 printf("device:\t\t%s\n", settings
.ddr3
.manu_name
);
86 printf("marking:\t%s\n", settings
.ddr3
.manu_marking
);
87 printf("%-20s, %-8s, %-8s, %-4s\n", "timing parameters", "eeprom",
91 PRINTARGS(ddr3_sratio
);
94 PRINTARGS(dt0rdsratio0
);
95 PRINTARGS(dt0wdsratio0
);
96 PRINTARGS(dt0fwsratio0
);
97 PRINTARGS(dt0wrsratio0
);
99 PRINTARGS(sdram_tim1
);
100 PRINTARGS(sdram_tim2
);
101 PRINTARGS(sdram_tim3
);
103 PRINTARGS(emif_ddr_phy_ctlr_1
);
105 PRINTARGS(sdram_config
);
107 PRINTARGS(ioctr_val
);
110 static void print_chip_data(void)
112 struct ctrl_dev
*cdev
= (struct ctrl_dev
*)CTRL_DEVICE_BASE
;
113 dpll_mpu_opp100
.m
= am335x_get_efuse_mpu_max_freq(cdev
);
114 printf("\nCPU BOARD\n");
115 printf("device: \t'%s'\n", settings
.chip
.sdevname
);
116 printf("hw version: \t'%s'\n", settings
.chip
.shwver
);
117 printf("max freq: \t%d MHz\n", dpll_mpu_opp100
.m
);
119 #endif /* CONFIG_SPL_BUILD */
121 #define AM335X_NAND_ECC_MASK 0x0f
122 #define AM335X_NAND_ECC_TYPE_16 0x02
126 struct am335x_nand_geometry
{
133 static int draco_read_nand_geometry(void)
135 struct am335x_nand_geometry geo
;
137 /* Read NAND geometry */
138 if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR
, 0x80, 2,
139 (uchar
*)&geo
, sizeof(struct am335x_nand_geometry
))) {
140 printf("Could not read the NAND geomtery; something fundamentally wrong on the I2C bus.\n");
143 if (geo
.magic
!= 0xa657b310) {
144 printf("%s: bad magic: %x\n", __func__
, geo
.magic
);
147 if ((geo
.nand_bus
& AM335X_NAND_ECC_MASK
) == AM335X_NAND_ECC_TYPE_16
)
156 * Read header information from EEPROM into global structure.
158 static int read_eeprom(void)
160 /* Check if baseboard eeprom is available */
161 if (i2c_probe(CONFIG_SYS_I2C_EEPROM_ADDR
)) {
162 printf("Could not probe the EEPROM; something fundamentally wrong on the I2C bus.\n");
166 #ifdef CONFIG_SPL_BUILD
167 /* Read Siemens eeprom data (DDR3) */
168 if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR
, EEPROM_ADDR_DDR3
, 2,
169 (uchar
*)&settings
.ddr3
, sizeof(struct ddr3_data
))) {
170 printf("Could not read the EEPROM; something fundamentally wrong on the I2C bus.\nUse default DDR3 timings\n");
171 set_default_ddr3_timings();
173 /* Read Siemens eeprom data (CHIP) */
174 if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR
, EEPROM_ADDR_CHIP
, 2,
175 (uchar
*)&settings
.chip
, sizeof(settings
.chip
)))
176 printf("Could not read chip settings\n");
178 if (ddr3_default
.magic
== settings
.ddr3
.magic
&&
179 ddr3_default
.version
== settings
.ddr3
.version
) {
180 printf("Using DDR3 settings from EEPROM\n");
182 if (ddr3_default
.magic
!= settings
.ddr3
.magic
)
183 printf("Warning: No valid DDR3 data in eeprom.\n");
184 if (ddr3_default
.version
!= settings
.ddr3
.version
)
185 printf("Warning: DDR3 data version does not match.\n");
187 printf("Using default settings\n");
188 set_default_ddr3_timings();
191 if (MAGIC_CHIP
== settings
.chip
.magic
)
194 printf("Warning: No chip data in eeprom\n");
196 print_ddr3_timings();
198 return draco_read_nand_geometry();
203 #ifdef CONFIG_SPL_BUILD
204 static void board_init_ddr(void)
206 struct emif_regs draco_ddr3_emif_reg_data
= {
207 .zq_config
= 0x50074BE4,
210 struct ddr_data draco_ddr3_data
= {
213 struct cmd_control draco_ddr3_cmd_ctrl_data
= {
216 struct ctrl_ioregs draco_ddr3_ioregs
= {
219 /* pass values from eeprom */
220 draco_ddr3_emif_reg_data
.sdram_tim1
= settings
.ddr3
.sdram_tim1
;
221 draco_ddr3_emif_reg_data
.sdram_tim2
= settings
.ddr3
.sdram_tim2
;
222 draco_ddr3_emif_reg_data
.sdram_tim3
= settings
.ddr3
.sdram_tim3
;
223 draco_ddr3_emif_reg_data
.emif_ddr_phy_ctlr_1
=
224 settings
.ddr3
.emif_ddr_phy_ctlr_1
;
225 draco_ddr3_emif_reg_data
.sdram_config
= settings
.ddr3
.sdram_config
;
226 draco_ddr3_emif_reg_data
.sdram_config2
= 0x08000000;
227 draco_ddr3_emif_reg_data
.ref_ctrl
= settings
.ddr3
.ref_ctrl
;
229 draco_ddr3_data
.datardsratio0
= settings
.ddr3
.dt0rdsratio0
;
230 draco_ddr3_data
.datawdsratio0
= settings
.ddr3
.dt0wdsratio0
;
231 draco_ddr3_data
.datafwsratio0
= settings
.ddr3
.dt0fwsratio0
;
232 draco_ddr3_data
.datawrsratio0
= settings
.ddr3
.dt0wrsratio0
;
234 draco_ddr3_cmd_ctrl_data
.cmd0csratio
= settings
.ddr3
.ddr3_sratio
;
235 draco_ddr3_cmd_ctrl_data
.cmd0iclkout
= settings
.ddr3
.iclkout
;
236 draco_ddr3_cmd_ctrl_data
.cmd1csratio
= settings
.ddr3
.ddr3_sratio
;
237 draco_ddr3_cmd_ctrl_data
.cmd1iclkout
= settings
.ddr3
.iclkout
;
238 draco_ddr3_cmd_ctrl_data
.cmd2csratio
= settings
.ddr3
.ddr3_sratio
;
239 draco_ddr3_cmd_ctrl_data
.cmd2iclkout
= settings
.ddr3
.iclkout
;
241 draco_ddr3_ioregs
.cm0ioctl
= settings
.ddr3
.ioctr_val
,
242 draco_ddr3_ioregs
.cm1ioctl
= settings
.ddr3
.ioctr_val
,
243 draco_ddr3_ioregs
.cm2ioctl
= settings
.ddr3
.ioctr_val
,
244 draco_ddr3_ioregs
.dt0ioctl
= settings
.ddr3
.ioctr_val
,
245 draco_ddr3_ioregs
.dt1ioctl
= settings
.ddr3
.ioctr_val
,
247 config_ddr(DDR_PLL_FREQ
, &draco_ddr3_ioregs
, &draco_ddr3_data
,
248 &draco_ddr3_cmd_ctrl_data
, &draco_ddr3_emif_reg_data
, 0);
251 static void spl_siemens_board_init(void)
255 #endif /* if def CONFIG_SPL_BUILD */
257 #ifdef CONFIG_BOARD_LATE_INIT
258 int board_late_init(void)
262 ret
= draco_read_nand_geometry();
266 nand_curr_device
= 0;
267 omap_nand_switch_ecc(1, ecc_type
);
268 #ifdef CONFIG_TARGET_ETAMIN
269 nand_curr_device
= 1;
270 omap_nand_switch_ecc(1, ecc_type
);
272 #ifdef CONFIG_FACTORYSET
273 /* Set ASN in environment*/
274 if (factory_dat
.asn
[0] != 0) {
275 env_set("dtb_name", (char *)factory_dat
.asn
);
277 /* dtb suffix gets added in load script */
278 env_set("dtb_name", "am335x-draco");
281 env_set("dtb_name", "am335x-draco");
288 #if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) || \
289 (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD))
290 static void cpsw_control(int enabled
)
292 /* VTP can be added here */
297 static struct cpsw_slave_data cpsw_slaves
[] = {
299 .slave_reg_ofs
= 0x208,
300 .sliver_reg_ofs
= 0xd80,
302 .phy_if
= PHY_INTERFACE_MODE_MII
,
306 static struct cpsw_platform_data cpsw_data
= {
307 .mdio_base
= CPSW_MDIO_BASE
,
308 .cpsw_base
= CPSW_BASE
,
311 .cpdma_reg_ofs
= 0x800,
313 .slave_data
= cpsw_slaves
,
314 .ale_reg_ofs
= 0xd00,
316 .host_port_reg_ofs
= 0x108,
317 .hw_stats_reg_ofs
= 0x900,
318 .bd_ram_ofs
= 0x2000,
319 .mac_control
= (1 << 5),
320 .control
= cpsw_control
,
322 .version
= CPSW_CTRL_VERSION_2
,
325 #if defined(CONFIG_DRIVER_TI_CPSW) || \
326 (defined(CONFIG_USB_ETHER) && defined(CONFIG_USB_MUSB_GADGET))
327 int board_eth_init(bd_t
*bis
)
329 struct ctrl_dev
*cdev
= (struct ctrl_dev
*)CTRL_DEVICE_BASE
;
333 factoryset_env_set();
335 /* Set rgmii mode and enable rmii clock to be sourced from chip */
336 writel((RMII_MODE_ENABLE
| RMII_CHIPCKL_ENABLE
), &cdev
->miisel
);
338 rv
= cpsw_register(&cpsw_data
);
340 printf("Error %d registering CPSW switch\n", rv
);
346 static int do_switch_reset(cmd_tbl_t
*cmdtp
, int flag
, int argc
,
349 /* Reset SMSC LAN9303 switch for default configuration */
350 gpio_request(GPIO_LAN9303_NRST
, "nRST");
351 gpio_direction_output(GPIO_LAN9303_NRST
, 0);
352 /* assert active low reset for 200us */
354 gpio_set_value(GPIO_LAN9303_NRST
, 1);
360 switch_rst
, CONFIG_SYS_MAXARGS
, 1, do_switch_reset
,
361 "Reset LAN9303 switch via its reset pin",
364 #endif /* #if defined(CONFIG_DRIVER_TI_CPSW) */
365 #endif /* #if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) */
367 #ifdef CONFIG_NAND_CS_INIT
368 /* GPMC definitions for second nand cs1 */
369 static const u32 gpmc_nand_config
[] = {
370 ETAMIN_NAND_GPMC_CONFIG1
,
371 ETAMIN_NAND_GPMC_CONFIG2
,
372 ETAMIN_NAND_GPMC_CONFIG3
,
373 ETAMIN_NAND_GPMC_CONFIG4
,
374 ETAMIN_NAND_GPMC_CONFIG5
,
375 ETAMIN_NAND_GPMC_CONFIG6
,
376 /*CONFIG7- computed as params */
379 static void board_nand_cs_init(void)
381 enable_gpmc_cs_config(gpmc_nand_config
, &gpmc_cfg
->cs
[1],
382 0x18000000, GPMC_SIZE_16M
);
386 #include "../common/board.c"