blob: e3c9d9e75529711ef0079f984104386107de9bad [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Lothar Felten8c6324f2014-01-31 17:34:14 +01002/*
3 * board.c
4 *
5 * Copyright (C) 2013 Lothar Felten <lothar.felten@gmail.com>
Lothar Felten8c6324f2014-01-31 17:34:14 +01006 */
7
8#include <common.h>
Simon Glass5e6201b2019-08-01 09:46:51 -06009#include <env.h>
Simon Glass97589732020-05-10 11:40:02 -060010#include <init.h>
Simon Glass274e0b02020-05-10 11:39:56 -060011#include <net.h>
Simon Glass36736182019-11-14 12:57:24 -070012#include <serial.h>
Lothar Felten8c6324f2014-01-31 17:34:14 +010013#include <asm/arch/cpu.h>
14#include <asm/arch/hardware.h>
15#include <asm/arch/ddr_defs.h>
16#include <asm/arch/clock.h>
17#include <asm/arch/sys_proto.h>
18#include <i2c.h>
19#include <phy.h>
20#include <cpsw.h>
21#include "board.h"
22
23DECLARE_GLOBAL_DATA_PTR;
24
25static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
26
27#if defined(CONFIG_SPL_BUILD)
28
29/* DDR3 RAM timings */
30static const struct ddr_data ddr3_data = {
31 .datardsratio0 = MT41K128MJT187E_RD_DQS,
32 .datawdsratio0 = MT41K128MJT187E_WR_DQS,
33 .datafwsratio0 = MT41K128MJT187E_PHY_FIFO_WE,
34 .datawrsratio0 = MT41K128MJT187E_PHY_WR_DATA,
35};
36
37static const struct cmd_control ddr3_cmd_ctrl_data = {
38 .cmd0csratio = MT41K128MJT187E_RATIO,
39 .cmd0iclkout = MT41K128MJT187E_INVERT_CLKOUT,
40 .cmd1csratio = MT41K128MJT187E_RATIO,
41 .cmd1iclkout = MT41K128MJT187E_INVERT_CLKOUT,
42 .cmd2csratio = MT41K128MJT187E_RATIO,
43 .cmd2iclkout = MT41K128MJT187E_INVERT_CLKOUT,
44};
45
46static struct emif_regs ddr3_emif_reg_data = {
47 .sdram_config = MT41K128MJT187E_EMIF_SDCFG,
48 .ref_ctrl = MT41K128MJT187E_EMIF_SDREF,
49 .sdram_tim1 = MT41K128MJT187E_EMIF_TIM1,
50 .sdram_tim2 = MT41K128MJT187E_EMIF_TIM2,
51 .sdram_tim3 = MT41K128MJT187E_EMIF_TIM3,
52 .zq_config = MT41K128MJT187E_ZQ_CFG,
53 .emif_ddr_phy_ctlr_1 = MT41K128MJT187E_EMIF_READ_LATENCY |
54 PHY_EN_DYN_PWRDN,
55};
56
57const struct ctrl_ioregs ddr3_ioregs = {
58 .cm0ioctl = MT41K128MJT187E_IOCTRL_VALUE,
59 .cm1ioctl = MT41K128MJT187E_IOCTRL_VALUE,
60 .cm2ioctl = MT41K128MJT187E_IOCTRL_VALUE,
61 .dt0ioctl = MT41K128MJT187E_IOCTRL_VALUE,
62 .dt1ioctl = MT41K128MJT187E_IOCTRL_VALUE,
63};
64
65#ifdef CONFIG_SPL_OS_BOOT
66int spl_start_uboot(void)
67{
68 /* break into full u-boot on 'c' */
69 return serial_tstc() && serial_getc() == 'c';
70}
71#endif
72
73#define OSC (V_OSCK/1000000)
74const struct dpll_params dpll_ddr_266 = {
75 266, OSC-1, 1, -1, -1, -1, -1};
76const struct dpll_params dpll_ddr_303 = {
77 303, OSC-1, 1, -1, -1, -1, -1};
78const struct dpll_params dpll_ddr_400 = {
79 400, OSC-1, 1, -1, -1, -1, -1};
80
81void am33xx_spl_board_init(void)
82{
83 /*
84 * The pengwyn board uses the TPS650250 PMIC without I2C
85 * interface and will output the following fixed voltages:
86 * DCDC1=3V3 (IO) DCDC2=1V5 (DDR) DCDC3=1V26 (Vmpu)
87 * VLDO1=1V8 (IO) VLDO2=1V8(IO)
88 * Vcore=1V1 is fixed, generated by TPS62231
89 */
90
91 /* Get the frequency */
92 dpll_mpu_opp100.m = am335x_get_efuse_mpu_max_freq(cdev);
93
94 /* Set CORE Frequencies to OPP100 */
95 do_setup_dpll(&dpll_core_regs, &dpll_core_opp100);
96
97 /* 720MHz cpu, this might change on newer board revisions */
98 dpll_mpu_opp100.m = MPUPLL_M_720;
99 do_setup_dpll(&dpll_mpu_regs, &dpll_mpu_opp100);
100}
101
102const struct dpll_params *get_dpll_ddr_params(void)
103{
104 /* future configs can return other clock settings */
105 return &dpll_ddr_303;
106}
107
108void set_uart_mux_conf(void)
109{
110 enable_uart0_pin_mux();
111}
112
113void set_mux_conf_regs(void)
114{
115 enable_board_pin_mux();
116}
117
118void sdram_init(void)
119{
120 config_ddr(303, &ddr3_ioregs, &ddr3_data,
121 &ddr3_cmd_ctrl_data, &ddr3_emif_reg_data, 0);
122}
123#endif /* if CONFIG_SPL_BUILD */
124
125/*
126 * Basic board specific setup. Pinmux has been handled already.
127 */
128int board_init(void)
129{
130 i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
131 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
132 gpmc_init();
133 return 0;
134}
135
136#ifdef CONFIG_DRIVER_TI_CPSW
137static void cpsw_control(int enabled)
138{
139 /* VTP can be added here */
140 return;
141}
142
143static struct cpsw_slave_data cpsw_slaves[] = {
144 {
145 .slave_reg_ofs = 0x208,
146 .sliver_reg_ofs = 0xd80,
Mugunthan V N4944f372014-02-18 07:31:52 -0500147 .phy_addr = 1,
Lothar Felten8c6324f2014-01-31 17:34:14 +0100148 .phy_if = PHY_INTERFACE_MODE_MII,
149 },
150};
151
152static struct cpsw_platform_data cpsw_data = {
153 .mdio_base = CPSW_MDIO_BASE,
154 .cpsw_base = CPSW_BASE,
155 .mdio_div = 0xff,
156 .channels = 8,
157 .cpdma_reg_ofs = 0x800,
158 .slaves = 1,
159 .slave_data = cpsw_slaves,
160 .ale_reg_ofs = 0xd00,
161 .ale_entries = 1024,
162 .host_port_reg_ofs = 0x108,
163 .hw_stats_reg_ofs = 0x900,
164 .bd_ram_ofs = 0x2000,
165 .mac_control = (1 << 5),
166 .control = cpsw_control,
167 .host_port_num = 0,
168 .version = CPSW_CTRL_VERSION_2,
169};
170
171int board_eth_init(bd_t *bis)
172{
173 int rv, n = 0;
174 uint8_t mac_addr[6];
175 uint32_t mac_hi, mac_lo;
176
Simon Glass399a9ce2017-08-03 12:22:14 -0600177 if (!eth_env_get_enetaddr("ethaddr", mac_addr)) {
Lothar Felten8c6324f2014-01-31 17:34:14 +0100178 printf("<ethaddr> not set. Reading from E-fuse\n");
179 /* try reading mac address from efuse */
180 mac_lo = readl(&cdev->macid0l);
181 mac_hi = readl(&cdev->macid0h);
182 mac_addr[0] = mac_hi & 0xFF;
183 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
184 mac_addr[2] = (mac_hi & 0xFF0000) >> 16;
185 mac_addr[3] = (mac_hi & 0xFF000000) >> 24;
186 mac_addr[4] = mac_lo & 0xFF;
187 mac_addr[5] = (mac_lo & 0xFF00) >> 8;
188
Joe Hershberger8ecdbed2015-04-08 01:41:04 -0500189 if (is_valid_ethaddr(mac_addr))
Simon Glass8551d552017-08-03 12:22:11 -0600190 eth_env_set_enetaddr("ethaddr", mac_addr);
Lothar Felten8c6324f2014-01-31 17:34:14 +0100191 else
192 return n;
193 }
194
195 writel(MII_MODE_ENABLE, &cdev->miisel);
196
197 rv = cpsw_register(&cpsw_data);
198 if (rv < 0)
199 printf("Error %d registering CPSW switch\n", rv);
200 else
201 n += rv;
202 return n;
203}
204#endif /* if CONFIG_DRIVER_TI_CPSW */