1*83d290c5STom Rini // SPDX-License-Identifier: GPL-2.0+
2425faf74STENART Antoine /*
3425faf74STENART Antoine * evm.c
4425faf74STENART Antoine *
5425faf74STENART Antoine * Copyright (C) 2013, Adeneo Embedded <www.adeneo-embedded.com>
6425faf74STENART Antoine * Antoine Tenart, <atenart@adeneo-embedded.com>
7425faf74STENART Antoine */
8425faf74STENART Antoine
9425faf74STENART Antoine #include <common.h>
109925f1dbSAlex Kiernan #include <environment.h>
11425faf74STENART Antoine #include <spl.h>
12de820365STom Rini #include <netdev.h>
13425faf74STENART Antoine #include <asm/cache.h>
14425faf74STENART Antoine #include <asm/io.h>
15425faf74STENART Antoine #include <asm/arch/clock.h>
16425faf74STENART Antoine #include <asm/arch/cpu.h>
17425faf74STENART Antoine #include <asm/arch/ddr_defs.h>
18425faf74STENART Antoine #include <asm/arch/hardware.h>
19425faf74STENART Antoine #include <asm/arch/sys_proto.h>
20425faf74STENART Antoine #include <asm/arch/mmc_host_def.h>
21425faf74STENART Antoine #include <asm/arch/mem.h>
22425faf74STENART Antoine #include <asm/arch/mux.h>
23425faf74STENART Antoine
24425faf74STENART Antoine DECLARE_GLOBAL_DATA_PTR;
25425faf74STENART Antoine
board_init(void)26425faf74STENART Antoine int board_init(void)
27425faf74STENART Antoine {
281d7f6ad2STom Rini gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
2977e99277STom Rini #if defined(CONFIG_NAND)
3077e99277STom Rini gpmc_init();
3177e99277STom Rini #endif
32425faf74STENART Antoine return 0;
33425faf74STENART Antoine }
34425faf74STENART Antoine
board_eth_init(bd_t * bis)35de820365STom Rini int board_eth_init(bd_t *bis)
36de820365STom Rini {
37de820365STom Rini uint8_t mac_addr[6];
38de820365STom Rini uint32_t mac_hi, mac_lo;
39de820365STom Rini struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
40de820365STom Rini
4135affd7aSSimon Glass if (!eth_env_get_enetaddr("ethaddr", mac_addr)) {
42de820365STom Rini printf("<ethaddr> not set. Reading from E-fuse\n");
43de820365STom Rini /* try reading mac address from efuse */
44de820365STom Rini mac_lo = readl(&cdev->macid0l);
45de820365STom Rini mac_hi = readl(&cdev->macid0h);
46de820365STom Rini mac_addr[0] = mac_hi & 0xFF;
47de820365STom Rini mac_addr[1] = (mac_hi & 0xFF00) >> 8;
48de820365STom Rini mac_addr[2] = (mac_hi & 0xFF0000) >> 16;
49de820365STom Rini mac_addr[3] = (mac_hi & 0xFF000000) >> 24;
50de820365STom Rini mac_addr[4] = mac_lo & 0xFF;
51de820365STom Rini mac_addr[5] = (mac_lo & 0xFF00) >> 8;
52de820365STom Rini
53de820365STom Rini if (is_valid_ethaddr(mac_addr))
54fd1e959eSSimon Glass eth_env_set_enetaddr("ethaddr", mac_addr);
55de820365STom Rini else
56de820365STom Rini printf("Unable to read MAC address. Set <ethaddr>\n");
57de820365STom Rini }
58de820365STom Rini
59de820365STom Rini return davinci_emac_initialize();
60de820365STom Rini }
61de820365STom Rini
62425faf74STENART Antoine #ifdef CONFIG_SPL_BUILD
63425faf74STENART Antoine static struct module_pin_mux mmc_pin_mux[] = {
64425faf74STENART Antoine { OFFSET(pincntl157), PULLDOWN_EN | PULLUDDIS | MODE(0x0) },
65425faf74STENART Antoine { OFFSET(pincntl158), PULLDOWN_EN | PULLUDEN | MODE(0x0) },
66425faf74STENART Antoine { OFFSET(pincntl159), PULLUP_EN | PULLUDDIS | MODE(0x0) },
67425faf74STENART Antoine { OFFSET(pincntl160), PULLUP_EN | PULLUDDIS | MODE(0x0) },
68425faf74STENART Antoine { OFFSET(pincntl161), PULLUP_EN | PULLUDDIS | MODE(0x0) },
69425faf74STENART Antoine { OFFSET(pincntl162), PULLUP_EN | PULLUDDIS | MODE(0x0) },
70425faf74STENART Antoine { OFFSET(pincntl163), PULLUP_EN | PULLUDDIS | MODE(0x0) },
71425faf74STENART Antoine { -1 },
72425faf74STENART Antoine };
73425faf74STENART Antoine
set_uart_mux_conf(void)7486277339STom Rini void set_uart_mux_conf(void) {}
7586277339STom Rini
set_mux_conf_regs(void)7686277339STom Rini void set_mux_conf_regs(void)
7786277339STom Rini {
7886277339STom Rini configure_module_pin_mux(mmc_pin_mux);
7986277339STom Rini }
80425faf74STENART Antoine
81425faf74STENART Antoine /*
8286277339STom Rini * EMIF Paramters. Refer the EMIF register documentation and the
8386277339STom Rini * memory datasheet for details. This is for 796 MHz.
84425faf74STENART Antoine */
85425faf74STENART Antoine #define EMIF_TIM1 0x1779C9FE
86425faf74STENART Antoine #define EMIF_TIM2 0x50608074
87425faf74STENART Antoine #define EMIF_TIM3 0x009F857F
8886277339STom Rini #define EMIF_SDREF 0x10001841
8986277339STom Rini #define EMIF_SDCFG 0x62A73832
90425faf74STENART Antoine #define EMIF_PHYCFG 0x00000110
9186277339STom Rini static const struct emif_regs ddr3_emif_regs = {
9286277339STom Rini .sdram_config = EMIF_SDCFG,
9386277339STom Rini .ref_ctrl = EMIF_SDREF,
9486277339STom Rini .sdram_tim1 = EMIF_TIM1,
9586277339STom Rini .sdram_tim2 = EMIF_TIM2,
9686277339STom Rini .sdram_tim3 = EMIF_TIM3,
9786277339STom Rini .emif_ddr_phy_ctlr_1 = EMIF_PHYCFG,
9886277339STom Rini };
99425faf74STENART Antoine
10086277339STom Rini static const struct cmd_control ddr3_ctrl = {
10186277339STom Rini .cmd0csratio = 0x100,
10286277339STom Rini .cmd0iclkout = 0x001,
10386277339STom Rini .cmd1csratio = 0x100,
10486277339STom Rini .cmd1iclkout = 0x001,
10586277339STom Rini .cmd2csratio = 0x100,
10686277339STom Rini .cmd2iclkout = 0x001,
10786277339STom Rini };
10886277339STom Rini
10986277339STom Rini /* These values are obtained from the CCS app */
11086277339STom Rini #define RD_DQS_GATE (0x1B3)
11186277339STom Rini #define RD_DQS (0x35)
11286277339STom Rini #define WR_DQS (0x93)
113425faf74STENART Antoine static struct ddr_data ddr3_data = {
114425faf74STENART Antoine .datardsratio0 = ((RD_DQS<<10) | (RD_DQS<<0)),
115425faf74STENART Antoine .datawdsratio0 = ((WR_DQS<<10) | (WR_DQS<<0)),
116425faf74STENART Antoine .datawiratio0 = ((0x20<<10) | 0x20<<0),
117425faf74STENART Antoine .datagiratio0 = ((0x20<<10) | 0x20<<0),
118425faf74STENART Antoine .datafwsratio0 = ((RD_DQS_GATE<<10) | (RD_DQS_GATE<<0)),
119425faf74STENART Antoine .datawrsratio0 = (((WR_DQS+0x40)<<10) | ((WR_DQS+0x40)<<0)),
120425faf74STENART Antoine };
121425faf74STENART Antoine
12286277339STom Rini static const struct dmm_lisa_map_regs evm_lisa_map_regs = {
12386277339STom Rini .dmm_lisa_map_0 = 0x00000000,
12486277339STom Rini .dmm_lisa_map_1 = 0x00000000,
12586277339STom Rini .dmm_lisa_map_2 = 0x80640300,
12686277339STom Rini .dmm_lisa_map_3 = 0xC0640320,
127425faf74STENART Antoine };
128425faf74STENART Antoine
sdram_init(void)129425faf74STENART Antoine void sdram_init(void)
130425faf74STENART Antoine {
13186277339STom Rini /*
13286277339STom Rini * Pass in our DDR3 config information and that we have 2 EMIFs to
13386277339STom Rini * configure.
13486277339STom Rini */
13586277339STom Rini config_ddr(&ddr3_data, &ddr3_ctrl, &ddr3_emif_regs,
13686277339STom Rini &evm_lisa_map_regs, 2);
137425faf74STENART Antoine }
138425faf74STENART Antoine #endif /* CONFIG_SPL_BUILD */
139