1 // SPDX-License-Identifier: GPL-2.0+
3 * Board functions for Gumstix Pepper and AM335x-based boards
5 * Copyright (C) 2014, Gumstix, Incorporated - http://www.gumstix.com/
6 * Based on board/ti/am335x/board.c from Texas Instruments, Inc.
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>
31 #include <power/tps65217.h>
35 DECLARE_GLOBAL_DATA_PTR;
37 #ifdef CONFIG_SPL_BUILD
38 #define OSC (V_OSCK/1000000)
40 static 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,
47 static const struct cmd_control ddr3_cmd_ctrl_data = {
48 .cmd0csratio = MT41K256M16HA125E_RATIO,
49 .cmd0iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
51 .cmd1csratio = MT41K256M16HA125E_RATIO,
52 .cmd1iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
54 .cmd2csratio = MT41K256M16HA125E_RATIO,
55 .cmd2iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
58 static 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,
68 const struct dpll_params dpll_ddr3 = {400, OSC-1, 1, -1, -1, -1, -1};
70 const 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,
78 static const struct ddr_data ddr2_data = {
79 .datardsratio0 = MT47H128M16RT25E_RD_DQS,
80 .datafwsratio0 = MT47H128M16RT25E_PHY_FIFO_WE,
81 .datawrsratio0 = MT47H128M16RT25E_PHY_WR_DATA,
84 static const struct cmd_control ddr2_cmd_ctrl_data = {
85 .cmd0csratio = MT47H128M16RT25E_RATIO,
87 .cmd1csratio = MT47H128M16RT25E_RATIO,
89 .cmd2csratio = MT47H128M16RT25E_RATIO,
92 static 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,
101 const struct dpll_params dpll_ddr2 = {266, OSC-1, 1, -1, -1, -1, -1};
103 const 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,
111 static int read_eeprom(struct pepper_board_id *header)
113 if (i2c_probe(CONFIG_SYS_I2C_EEPROM_ADDR)) {
117 if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0, 1, (uchar *)header,
118 sizeof(struct pepper_board_id))) {
125 const struct dpll_params *get_dpll_ddr_params(void)
127 struct pepper_board_id header;
129 enable_i2c0_pin_mux();
132 if (read_eeprom(&header) < 0)
135 switch (header.device_vendor) {
138 case GUMSTIX_PEPPER_DVI:
145 void sdram_init(void)
147 const struct dpll_params *dpll = get_dpll_ddr_params();
150 * Here we are assuming PLL clock reveals the type of RAM.
153 * Note that DDR3 is the default.
155 if (dpll->m == 266) {
156 config_ddr(dpll->m, &ioregs_ddr2, &ddr2_data,
157 &ddr2_cmd_ctrl_data, &ddr2_emif_reg_data, 0);
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);
165 #ifdef CONFIG_SPL_OS_BOOT
166 int spl_start_uboot(void)
168 /* break into full u-boot on 'c' */
169 return serial_tstc() && serial_getc() == 'c';
173 void set_uart_mux_conf(void)
175 enable_uart0_pin_mux();
178 void set_mux_conf_regs(void)
180 enable_board_pin_mux();
188 #if defined(CONFIG_HW_WATCHDOG)
192 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
198 #if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) || \
199 (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD))
200 static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
202 static void cpsw_control(int enabled)
204 /* VTP can be added here */
209 static struct cpsw_slave_data cpsw_slaves[] = {
211 .slave_reg_ofs = 0x208,
212 .sliver_reg_ofs = 0xd80,
214 .phy_if = PHY_INTERFACE_MODE_RGMII,
218 static struct cpsw_platform_data cpsw_data = {
219 .mdio_base = CPSW_MDIO_BASE,
220 .cpsw_base = CPSW_BASE,
223 .cpdma_reg_ofs = 0x800,
225 .slave_data = cpsw_slaves,
226 .ale_reg_ofs = 0xd00,
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,
234 .version = CPSW_CTRL_VERSION_2,
237 int board_eth_init(bd_t *bis)
241 uint32_t mac_hi, mac_lo;
244 if (!eth_env_get_enetaddr("ethaddr", mac_addr)) {
245 /* 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;
254 if (is_valid_ethaddr(mac_addr))
255 eth_env_set_enetaddr("ethaddr", mac_addr);
258 writel((RGMII_MODE_ENABLE | RGMII_INT_DELAY), &cdev->miisel);
260 rv = cpsw_register(&cpsw_data);
262 printf("Error %d registering CPSW switch\n", rv);
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.
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);
278 /* min rx data delay */
279 miiphy_write(devname, 0x0, 0x0b, 0x8105);
280 miiphy_write(devname, 0x0, 0x0c, 0x0000);
282 /* min tx data delay */
283 miiphy_write(devname, 0x0, 0x0b, 0x8106);
284 miiphy_write(devname, 0x0, 0x0c, 0x0000);