blob: ebb5a560c3af6d7f94fb9482ae303a4e86015782 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Ash Charles9cb110e2014-05-07 08:24:11 -07002/*
3 * Board functions for Gumstix Pepper and AM335x-based boards
4 *
5 * Copyright (C) 2014, Gumstix, Incorporated - http://www.gumstix.com/
6 * Based on board/ti/am335x/board.c from Texas Instruments, Inc.
Ash Charles9cb110e2014-05-07 08:24:11 -07007 */
8
9#include <common.h>
Simon Glass5e6201b2019-08-01 09:46:51 -060010#include <env.h>
Ash Charles9cb110e2014-05-07 08:24:11 -070011#include <errno.h>
Simon Glass97589732020-05-10 11:40:02 -060012#include <init.h>
Simon Glass274e0b02020-05-10 11:39:56 -060013#include <net.h>
Simon Glass36736182019-11-14 12:57:24 -070014#include <serial.h>
Ash Charles9cb110e2014-05-07 08:24:11 -070015#include <spl.h>
16#include <asm/arch/cpu.h>
17#include <asm/arch/hardware.h>
18#include <asm/arch/omap.h>
19#include <asm/arch/ddr_defs.h>
20#include <asm/arch/clock.h>
21#include <asm/arch/gpio.h>
22#include <asm/arch/mmc_host_def.h>
23#include <asm/arch/sys_proto.h>
24#include <asm/arch/mem.h>
25#include <asm/io.h>
26#include <asm/emif.h>
27#include <asm/gpio.h>
28#include <i2c.h>
29#include <miiphy.h>
30#include <cpsw.h>
31#include <power/tps65217.h>
Ash Charles9cb110e2014-05-07 08:24:11 -070032#include <watchdog.h>
33#include "board.h"
34
35DECLARE_GLOBAL_DATA_PTR;
36
37#ifdef CONFIG_SPL_BUILD
Adam YH Lee3dc3c982015-06-01 14:29:09 -070038#define OSC (V_OSCK/1000000)
39
40static const struct ddr_data ddr3_data = {
41 .datardsratio0 = MT41K256M16HA125E_RD_DQS,
42 .datawdsratio0 = MT41K256M16HA125E_WR_DQS,
43 .datafwsratio0 = MT41K256M16HA125E_PHY_FIFO_WE,
44 .datawrsratio0 = MT41K256M16HA125E_PHY_WR_DATA,
45};
46
47static const struct cmd_control ddr3_cmd_ctrl_data = {
48 .cmd0csratio = MT41K256M16HA125E_RATIO,
49 .cmd0iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
50
51 .cmd1csratio = MT41K256M16HA125E_RATIO,
52 .cmd1iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
53
54 .cmd2csratio = MT41K256M16HA125E_RATIO,
55 .cmd2iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
56};
57
58static struct emif_regs ddr3_emif_reg_data = {
59 .sdram_config = MT41K256M16HA125E_EMIF_SDCFG,
60 .ref_ctrl = MT41K256M16HA125E_EMIF_SDREF,
61 .sdram_tim1 = MT41K256M16HA125E_EMIF_TIM1,
62 .sdram_tim2 = MT41K256M16HA125E_EMIF_TIM2,
63 .sdram_tim3 = MT41K256M16HA125E_EMIF_TIM3,
64 .zq_config = MT41K256M16HA125E_ZQ_CFG,
65 .emif_ddr_phy_ctlr_1 = MT41K256M16HA125E_EMIF_READ_LATENCY,
66};
67
68const struct dpll_params dpll_ddr3 = {400, OSC-1, 1, -1, -1, -1, -1};
69
70const struct ctrl_ioregs ioregs_ddr3 = {
71 .cm0ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
72 .cm1ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
73 .cm2ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
74 .dt0ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
75 .dt1ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
76};
77
Ash Charles9cb110e2014-05-07 08:24:11 -070078static const struct ddr_data ddr2_data = {
Tom Rini7f50a572014-07-07 21:40:16 -040079 .datardsratio0 = MT47H128M16RT25E_RD_DQS,
80 .datafwsratio0 = MT47H128M16RT25E_PHY_FIFO_WE,
81 .datawrsratio0 = MT47H128M16RT25E_PHY_WR_DATA,
Ash Charles9cb110e2014-05-07 08:24:11 -070082};
83
84static const struct cmd_control ddr2_cmd_ctrl_data = {
85 .cmd0csratio = MT47H128M16RT25E_RATIO,
Ash Charles9cb110e2014-05-07 08:24:11 -070086
87 .cmd1csratio = MT47H128M16RT25E_RATIO,
Ash Charles9cb110e2014-05-07 08:24:11 -070088
89 .cmd2csratio = MT47H128M16RT25E_RATIO,
Ash Charles9cb110e2014-05-07 08:24:11 -070090};
91
92static const struct emif_regs ddr2_emif_reg_data = {
93 .sdram_config = MT47H128M16RT25E_EMIF_SDCFG,
94 .ref_ctrl = MT47H128M16RT25E_EMIF_SDREF,
95 .sdram_tim1 = MT47H128M16RT25E_EMIF_TIM1,
96 .sdram_tim2 = MT47H128M16RT25E_EMIF_TIM2,
97 .sdram_tim3 = MT47H128M16RT25E_EMIF_TIM3,
98 .emif_ddr_phy_ctlr_1 = MT47H128M16RT25E_EMIF_READ_LATENCY,
99};
100
Adam YH Lee3dc3c982015-06-01 14:29:09 -0700101const struct dpll_params dpll_ddr2 = {266, OSC-1, 1, -1, -1, -1, -1};
102
103const struct ctrl_ioregs ioregs_ddr2 = {
104 .cm0ioctl = MT47H128M16RT25E_IOCTRL_VALUE,
105 .cm1ioctl = MT47H128M16RT25E_IOCTRL_VALUE,
106 .cm2ioctl = MT47H128M16RT25E_IOCTRL_VALUE,
107 .dt0ioctl = MT47H128M16RT25E_IOCTRL_VALUE,
108 .dt1ioctl = MT47H128M16RT25E_IOCTRL_VALUE,
109};
110
111static int read_eeprom(struct pepper_board_id *header)
112{
113 if (i2c_probe(CONFIG_SYS_I2C_EEPROM_ADDR)) {
114 return -ENODEV;
115 }
116
117 if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0, 1, (uchar *)header,
118 sizeof(struct pepper_board_id))) {
119 return -EIO;
120 }
121
122 return 0;
123}
124
125const struct dpll_params *get_dpll_ddr_params(void)
126{
127 struct pepper_board_id header;
128
129 enable_i2c0_pin_mux();
130 i2c_set_bus_num(0);
131
132 if (read_eeprom(&header) < 0)
133 return &dpll_ddr3;
134
135 switch (header.device_vendor) {
136 case GUMSTIX_PEPPER:
137 return &dpll_ddr2;
138 case GUMSTIX_PEPPER_DVI:
139 return &dpll_ddr3;
140 default:
141 return &dpll_ddr3;
142 }
143}
144
145void sdram_init(void)
146{
147 const struct dpll_params *dpll = get_dpll_ddr_params();
148
149 /*
150 * Here we are assuming PLL clock reveals the type of RAM.
151 * DDR2 = 266
152 * DDR3 = 400
153 * Note that DDR3 is the default.
154 */
155 if (dpll->m == 266) {
156 config_ddr(dpll->m, &ioregs_ddr2, &ddr2_data,
157 &ddr2_cmd_ctrl_data, &ddr2_emif_reg_data, 0);
158 }
159 else if (dpll->m == 400) {
160 config_ddr(dpll->m, &ioregs_ddr3, &ddr3_data,
161 &ddr3_cmd_ctrl_data, &ddr3_emif_reg_data, 0);
162 }
163}
164
Ash Charles9cb110e2014-05-07 08:24:11 -0700165#ifdef CONFIG_SPL_OS_BOOT
166int spl_start_uboot(void)
167{
168 /* break into full u-boot on 'c' */
169 return serial_tstc() && serial_getc() == 'c';
170}
171#endif
172
Ash Charles9cb110e2014-05-07 08:24:11 -0700173void set_uart_mux_conf(void)
174{
175 enable_uart0_pin_mux();
176}
177
178void set_mux_conf_regs(void)
179{
180 enable_board_pin_mux();
181}
182
Ash Charles9cb110e2014-05-07 08:24:11 -0700183
Ash Charles9cb110e2014-05-07 08:24:11 -0700184#endif
185
186int board_init(void)
187{
188#if defined(CONFIG_HW_WATCHDOG)
189 hw_watchdog_init();
190#endif
191
192 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
193 gpmc_init();
194
195 return 0;
196}
197
198#if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) || \
199 (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD))
200static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
201
202static void cpsw_control(int enabled)
203{
204 /* VTP can be added here */
205
206 return;
207}
208
209static struct cpsw_slave_data cpsw_slaves[] = {
210 {
211 .slave_reg_ofs = 0x208,
212 .sliver_reg_ofs = 0xd80,
213 .phy_addr = 0,
214 .phy_if = PHY_INTERFACE_MODE_RGMII,
215 },
216};
217
218static struct cpsw_platform_data cpsw_data = {
219 .mdio_base = CPSW_MDIO_BASE,
220 .cpsw_base = CPSW_BASE,
221 .mdio_div = 0xff,
222 .channels = 8,
223 .cpdma_reg_ofs = 0x800,
224 .slaves = 1,
225 .slave_data = cpsw_slaves,
226 .ale_reg_ofs = 0xd00,
227 .ale_entries = 1024,
228 .host_port_reg_ofs = 0x108,
229 .hw_stats_reg_ofs = 0x900,
230 .bd_ram_ofs = 0x2000,
231 .mac_control = (1 << 5),
232 .control = cpsw_control,
233 .host_port_num = 0,
234 .version = CPSW_CTRL_VERSION_2,
235};
236
237int board_eth_init(bd_t *bis)
238{
239 int rv, n = 0;
240 uint8_t mac_addr[6];
241 uint32_t mac_hi, mac_lo;
242 const char *devname;
243
Simon Glass399a9ce2017-08-03 12:22:14 -0600244 if (!eth_env_get_enetaddr("ethaddr", mac_addr)) {
Ash Charles9cb110e2014-05-07 08:24:11 -0700245 /* try reading mac address from efuse */
246 mac_lo = readl(&cdev->macid0l);
247 mac_hi = readl(&cdev->macid0h);
248 mac_addr[0] = mac_hi & 0xFF;
249 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
250 mac_addr[2] = (mac_hi & 0xFF0000) >> 16;
251 mac_addr[3] = (mac_hi & 0xFF000000) >> 24;
252 mac_addr[4] = mac_lo & 0xFF;
253 mac_addr[5] = (mac_lo & 0xFF00) >> 8;
Joe Hershberger8ecdbed2015-04-08 01:41:04 -0500254 if (is_valid_ethaddr(mac_addr))
Simon Glass8551d552017-08-03 12:22:11 -0600255 eth_env_set_enetaddr("ethaddr", mac_addr);
Ash Charles9cb110e2014-05-07 08:24:11 -0700256 }
257
258 writel((RGMII_MODE_ENABLE | RGMII_INT_DELAY), &cdev->miisel);
259
260 rv = cpsw_register(&cpsw_data);
261 if (rv < 0)
262 printf("Error %d registering CPSW switch\n", rv);
263 else
264 n += rv;
265
266 /*
267 *
268 * CPSW RGMII Internal Delay Mode is not supported in all PVT
269 * operating points. So we must set the TX clock delay feature
270 * in the KSZ9021 PHY. Since we only support a single ethernet
271 * device in U-Boot, we only do this for the current instance.
272 */
273 devname = miiphy_get_current_dev();
274 /* max rx/tx clock delay, min rx/tx control delay */
275 miiphy_write(devname, 0x0, 0x0b, 0x8104);
276 miiphy_write(devname, 0x0, 0xc, 0xa0a0);
277
278 /* min rx data delay */
279 miiphy_write(devname, 0x0, 0x0b, 0x8105);
280 miiphy_write(devname, 0x0, 0x0c, 0x0000);
281
282 /* min tx data delay */
283 miiphy_write(devname, 0x0, 0x0b, 0x8106);
284 miiphy_write(devname, 0x0, 0x0c, 0x0000);
285
286 return n;
287}
288#endif