2 * Board functions for Gumstix Pepper and AM335x-based boards
4 * Copyright (C) 2014, Gumstix, Incorporated - http://www.gumstix.com/
5 * Based on board/ti/am335x/board.c from Texas Instruments, Inc.
7 * SPDX-License-Identifier: GPL-2.0+
13 #include <asm/arch/cpu.h>
14 #include <asm/arch/hardware.h>
15 #include <asm/arch/omap.h>
16 #include <asm/arch/ddr_defs.h>
17 #include <asm/arch/clock.h>
18 #include <asm/arch/gpio.h>
19 #include <asm/arch/mmc_host_def.h>
20 #include <asm/arch/sys_proto.h>
21 #include <asm/arch/mem.h>
28 #include <power/tps65217.h>
29 #include <environment.h>
33 DECLARE_GLOBAL_DATA_PTR;
35 #ifdef CONFIG_SPL_BUILD
36 static const struct ddr_data ddr2_data = {
37 .datardsratio0 = ((MT47H128M16RT25E_RD_DQS<<30) |
38 (MT47H128M16RT25E_RD_DQS<<20) |
39 (MT47H128M16RT25E_RD_DQS<<10) |
40 (MT47H128M16RT25E_RD_DQS<<0)),
41 .datawdsratio0 = ((MT47H128M16RT25E_WR_DQS<<30) |
42 (MT47H128M16RT25E_WR_DQS<<20) |
43 (MT47H128M16RT25E_WR_DQS<<10) |
44 (MT47H128M16RT25E_WR_DQS<<0)),
45 .datawiratio0 = ((MT47H128M16RT25E_PHY_WRLVL<<30) |
46 (MT47H128M16RT25E_PHY_WRLVL<<20) |
47 (MT47H128M16RT25E_PHY_WRLVL<<10) |
48 (MT47H128M16RT25E_PHY_WRLVL<<0)),
49 .datagiratio0 = ((MT47H128M16RT25E_PHY_GATELVL<<30) |
50 (MT47H128M16RT25E_PHY_GATELVL<<20) |
51 (MT47H128M16RT25E_PHY_GATELVL<<10) |
52 (MT47H128M16RT25E_PHY_GATELVL<<0)),
53 .datafwsratio0 = ((MT47H128M16RT25E_PHY_FIFO_WE<<30) |
54 (MT47H128M16RT25E_PHY_FIFO_WE<<20) |
55 (MT47H128M16RT25E_PHY_FIFO_WE<<10) |
56 (MT47H128M16RT25E_PHY_FIFO_WE<<0)),
57 .datawrsratio0 = ((MT47H128M16RT25E_PHY_WR_DATA<<30) |
58 (MT47H128M16RT25E_PHY_WR_DATA<<20) |
59 (MT47H128M16RT25E_PHY_WR_DATA<<10) |
60 (MT47H128M16RT25E_PHY_WR_DATA<<0)),
63 static const struct cmd_control ddr2_cmd_ctrl_data = {
64 .cmd0csratio = MT47H128M16RT25E_RATIO,
65 .cmd0iclkout = MT47H128M16RT25E_INVERT_CLKOUT,
67 .cmd1csratio = MT47H128M16RT25E_RATIO,
68 .cmd1iclkout = MT47H128M16RT25E_INVERT_CLKOUT,
70 .cmd2csratio = MT47H128M16RT25E_RATIO,
71 .cmd2iclkout = MT47H128M16RT25E_INVERT_CLKOUT,
74 static const struct emif_regs ddr2_emif_reg_data = {
75 .sdram_config = MT47H128M16RT25E_EMIF_SDCFG,
76 .ref_ctrl = MT47H128M16RT25E_EMIF_SDREF,
77 .sdram_tim1 = MT47H128M16RT25E_EMIF_TIM1,
78 .sdram_tim2 = MT47H128M16RT25E_EMIF_TIM2,
79 .sdram_tim3 = MT47H128M16RT25E_EMIF_TIM3,
80 .emif_ddr_phy_ctlr_1 = MT47H128M16RT25E_EMIF_READ_LATENCY,
83 #ifdef CONFIG_SPL_OS_BOOT
84 int spl_start_uboot(void)
86 /* break into full u-boot on 'c' */
87 return serial_tstc() && serial_getc() == 'c';
91 #define OSC (V_OSCK/1000000)
92 const struct dpll_params dpll_ddr = {266, OSC-1, 1, -1, -1, -1, -1};
94 const struct dpll_params *get_dpll_ddr_params(void)
99 void set_uart_mux_conf(void)
101 enable_uart0_pin_mux();
104 void set_mux_conf_regs(void)
106 enable_board_pin_mux();
109 const struct ctrl_ioregs ioregs = {
110 .cm0ioctl = MT47H128M16RT25E_IOCTRL_VALUE,
111 .cm1ioctl = MT47H128M16RT25E_IOCTRL_VALUE,
112 .cm2ioctl = MT47H128M16RT25E_IOCTRL_VALUE,
113 .dt0ioctl = MT47H128M16RT25E_IOCTRL_VALUE,
114 .dt1ioctl = MT47H128M16RT25E_IOCTRL_VALUE,
117 void sdram_init(void)
119 config_ddr(266, &ioregs, &ddr2_data,
120 &ddr2_cmd_ctrl_data, &ddr2_emif_reg_data, 0);
126 #if defined(CONFIG_HW_WATCHDOG)
130 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
136 #if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) || \
137 (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD))
138 static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
140 static void cpsw_control(int enabled)
142 /* VTP can be added here */
147 static struct cpsw_slave_data cpsw_slaves[] = {
149 .slave_reg_ofs = 0x208,
150 .sliver_reg_ofs = 0xd80,
152 .phy_if = PHY_INTERFACE_MODE_RGMII,
156 static struct cpsw_platform_data cpsw_data = {
157 .mdio_base = CPSW_MDIO_BASE,
158 .cpsw_base = CPSW_BASE,
161 .cpdma_reg_ofs = 0x800,
163 .slave_data = cpsw_slaves,
164 .ale_reg_ofs = 0xd00,
166 .host_port_reg_ofs = 0x108,
167 .hw_stats_reg_ofs = 0x900,
168 .bd_ram_ofs = 0x2000,
169 .mac_control = (1 << 5),
170 .control = cpsw_control,
172 .version = CPSW_CTRL_VERSION_2,
175 int board_eth_init(bd_t *bis)
179 uint32_t mac_hi, mac_lo;
182 if (!eth_getenv_enetaddr("ethaddr", mac_addr)) {
183 /* try reading mac address from efuse */
184 mac_lo = readl(&cdev->macid0l);
185 mac_hi = readl(&cdev->macid0h);
186 mac_addr[0] = mac_hi & 0xFF;
187 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
188 mac_addr[2] = (mac_hi & 0xFF0000) >> 16;
189 mac_addr[3] = (mac_hi & 0xFF000000) >> 24;
190 mac_addr[4] = mac_lo & 0xFF;
191 mac_addr[5] = (mac_lo & 0xFF00) >> 8;
192 if (is_valid_ether_addr(mac_addr))
193 eth_setenv_enetaddr("ethaddr", mac_addr);
196 writel((RGMII_MODE_ENABLE | RGMII_INT_DELAY), &cdev->miisel);
198 rv = cpsw_register(&cpsw_data);
200 printf("Error %d registering CPSW switch\n", rv);
206 * CPSW RGMII Internal Delay Mode is not supported in all PVT
207 * operating points. So we must set the TX clock delay feature
208 * in the KSZ9021 PHY. Since we only support a single ethernet
209 * device in U-Boot, we only do this for the current instance.
211 devname = miiphy_get_current_dev();
212 /* max rx/tx clock delay, min rx/tx control delay */
213 miiphy_write(devname, 0x0, 0x0b, 0x8104);
214 miiphy_write(devname, 0x0, 0xc, 0xa0a0);
216 /* min rx data delay */
217 miiphy_write(devname, 0x0, 0x0b, 0x8105);
218 miiphy_write(devname, 0x0, 0x0c, 0x0000);
220 /* min tx data delay */
221 miiphy_write(devname, 0x0, 0x0b, 0x8106);
222 miiphy_write(devname, 0x0, 0x0c, 0x0000);