blob: 4f3853ac4262ac347740369be63d1e550e46845a [file] [log] [blame]
Lars Poeschel67b4a792013-01-11 00:53:31 +00001/*
2 * board.c
3 *
4 * Board functions for Phytec phyCORE-AM335x (pcm051) based boards
5 *
6 * Copyright (C) 2013 Lemonage Software GmbH
7 * Author Lars Poeschel <poeschel@lemonage.de>
8 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02009 * SPDX-License-Identifier: GPL-2.0+
Lars Poeschel67b4a792013-01-11 00:53:31 +000010 */
11
12#include <common.h>
13#include <errno.h>
14#include <spl.h>
15#include <asm/arch/cpu.h>
16#include <asm/arch/hardware.h>
17#include <asm/arch/omap.h>
18#include <asm/arch/ddr_defs.h>
19#include <asm/arch/clock.h>
20#include <asm/arch/gpio.h>
21#include <asm/arch/mmc_host_def.h>
22#include <asm/arch/sys_proto.h>
23#include <asm/io.h>
24#include <asm/emif.h>
25#include <asm/gpio.h>
26#include <i2c.h>
27#include <miiphy.h>
28#include <cpsw.h>
29#include "board.h"
30
31DECLARE_GLOBAL_DATA_PTR;
32
Lars Poeschel67b4a792013-01-11 00:53:31 +000033/* MII mode defines */
Lars Poeschel67b4a792013-01-11 00:53:31 +000034#define RMII_RGMII2_MODE_ENABLE 0x49
35
36static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
37
Lars Poeschel67b4a792013-01-11 00:53:31 +000038#ifdef CONFIG_SPL_BUILD
Lars Poeschel67b4a792013-01-11 00:53:31 +000039
40/* DDR RAM defines */
41#define DDR_CLK_MHZ 303 /* DDR_DPLL_MULT value */
42
Lokesh Vutla89a83bf2013-07-30 10:48:52 +053043#define OSC (V_OSCK/1000000)
44const struct dpll_params dpll_ddr = {
45 DDR_CLK_MHZ, OSC-1, 1, -1, -1, -1, -1};
46
47const struct dpll_params *get_dpll_ddr_params(void)
48{
49 return &dpll_ddr;
50}
51
Lars Poeschel2fbf12a2013-11-19 11:22:18 +010052#ifdef CONFIG_REV1
Lokesh Vutla303b2672013-12-10 15:02:21 +053053const struct ctrl_ioregs ioregs = {
54 .cm0ioctl = MT41J256M8HX15E_IOCTRL_VALUE,
55 .cm1ioctl = MT41J256M8HX15E_IOCTRL_VALUE,
56 .cm2ioctl = MT41J256M8HX15E_IOCTRL_VALUE,
57 .dt0ioctl = MT41J256M8HX15E_IOCTRL_VALUE,
58 .dt1ioctl = MT41J256M8HX15E_IOCTRL_VALUE,
59};
60
Lars Poeschel67b4a792013-01-11 00:53:31 +000061static const struct ddr_data ddr3_data = {
62 .datardsratio0 = MT41J256M8HX15E_RD_DQS,
63 .datawdsratio0 = MT41J256M8HX15E_WR_DQS,
64 .datafwsratio0 = MT41J256M8HX15E_PHY_FIFO_WE,
65 .datawrsratio0 = MT41J256M8HX15E_PHY_WR_DATA,
Lars Poeschel67b4a792013-01-11 00:53:31 +000066};
67
68static const struct cmd_control ddr3_cmd_ctrl_data = {
69 .cmd0csratio = MT41J256M8HX15E_RATIO,
Lars Poeschel67b4a792013-01-11 00:53:31 +000070 .cmd0iclkout = MT41J256M8HX15E_INVERT_CLKOUT,
71
72 .cmd1csratio = MT41J256M8HX15E_RATIO,
Lars Poeschel67b4a792013-01-11 00:53:31 +000073 .cmd1iclkout = MT41J256M8HX15E_INVERT_CLKOUT,
74
75 .cmd2csratio = MT41J256M8HX15E_RATIO,
Lars Poeschel67b4a792013-01-11 00:53:31 +000076 .cmd2iclkout = MT41J256M8HX15E_INVERT_CLKOUT,
77};
78
79static struct emif_regs ddr3_emif_reg_data = {
80 .sdram_config = MT41J256M8HX15E_EMIF_SDCFG,
81 .ref_ctrl = MT41J256M8HX15E_EMIF_SDREF,
82 .sdram_tim1 = MT41J256M8HX15E_EMIF_TIM1,
83 .sdram_tim2 = MT41J256M8HX15E_EMIF_TIM2,
84 .sdram_tim3 = MT41J256M8HX15E_EMIF_TIM3,
85 .zq_config = MT41J256M8HX15E_ZQ_CFG,
Lars Poeschel3ccf01a2013-04-03 04:37:52 +000086 .emif_ddr_phy_ctlr_1 = MT41J256M8HX15E_EMIF_READ_LATENCY |
87 PHY_EN_DYN_PWRDN,
Lars Poeschel67b4a792013-01-11 00:53:31 +000088};
Lars Poeschel67b4a792013-01-11 00:53:31 +000089
Lars Poeschel2fbf12a2013-11-19 11:22:18 +010090void sdram_init(void)
91{
Lokesh Vutla303b2672013-12-10 15:02:21 +053092 config_ddr(DDR_CLK_MHZ, &ioregs, &ddr3_data,
Lars Poeschel2fbf12a2013-11-19 11:22:18 +010093 &ddr3_cmd_ctrl_data, &ddr3_emif_reg_data, 0);
94}
95#else
Lokesh Vutla303b2672013-12-10 15:02:21 +053096const struct ctrl_ioregs ioregs = {
97 .cm0ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
98 .cm1ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
99 .cm2ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
100 .dt0ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
101 .dt1ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
102};
103
Lars Poeschel2fbf12a2013-11-19 11:22:18 +0100104static const struct ddr_data ddr3_data = {
105 .datardsratio0 = MT41K256M16HA125E_RD_DQS,
106 .datawdsratio0 = MT41K256M16HA125E_WR_DQS,
107 .datafwsratio0 = MT41K256M16HA125E_PHY_FIFO_WE,
108 .datawrsratio0 = MT41K256M16HA125E_PHY_WR_DATA,
Lars Poeschel2fbf12a2013-11-19 11:22:18 +0100109};
110
111static const struct cmd_control ddr3_cmd_ctrl_data = {
112 .cmd0csratio = MT41K256M16HA125E_RATIO,
Lars Poeschel2fbf12a2013-11-19 11:22:18 +0100113 .cmd0iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
114
115 .cmd1csratio = MT41K256M16HA125E_RATIO,
Lars Poeschel2fbf12a2013-11-19 11:22:18 +0100116 .cmd1iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
117
118 .cmd2csratio = MT41K256M16HA125E_RATIO,
Lars Poeschel2fbf12a2013-11-19 11:22:18 +0100119 .cmd2iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
120};
121
122static struct emif_regs ddr3_emif_reg_data = {
123 .sdram_config = MT41K256M16HA125E_EMIF_SDCFG,
124 .ref_ctrl = MT41K256M16HA125E_EMIF_SDREF,
125 .sdram_tim1 = MT41K256M16HA125E_EMIF_TIM1,
126 .sdram_tim2 = MT41K256M16HA125E_EMIF_TIM2,
127 .sdram_tim3 = MT41K256M16HA125E_EMIF_TIM3,
128 .zq_config = MT41K256M16HA125E_ZQ_CFG,
129 .emif_ddr_phy_ctlr_1 = MT41K256M16HA125E_EMIF_READ_LATENCY |
130 PHY_EN_DYN_PWRDN,
131};
132
133void sdram_init(void)
134{
Lokesh Vutla303b2672013-12-10 15:02:21 +0530135 config_ddr(DDR_CLK_MHZ, &ioregs, &ddr3_data,
Lars Poeschel2fbf12a2013-11-19 11:22:18 +0100136 &ddr3_cmd_ctrl_data, &ddr3_emif_reg_data, 0);
137}
138#endif
139
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530140void set_uart_mux_conf(void)
Lars Poeschel67b4a792013-01-11 00:53:31 +0000141{
Lars Poeschel67b4a792013-01-11 00:53:31 +0000142 enable_uart0_pin_mux();
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530143}
Lars Poeschel67b4a792013-01-11 00:53:31 +0000144
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530145void set_mux_conf_regs(void)
146{
Lars Poeschel67b4a792013-01-11 00:53:31 +0000147 /* Initalize the board header */
148 enable_i2c0_pin_mux();
Heiko Schocherf53f2b82013-10-22 11:03:18 +0200149 i2c_init(CONFIG_SYS_OMAP24_I2C_SPEED, CONFIG_SYS_OMAP24_I2C_SLAVE);
Lars Poeschel67b4a792013-01-11 00:53:31 +0000150
151 enable_board_pin_mux();
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530152}
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530153#endif
Lars Poeschel67b4a792013-01-11 00:53:31 +0000154
155/*
156 * Basic board specific setup. Pinmux has been handled already.
157 */
158int board_init(void)
159{
Heiko Schocherf53f2b82013-10-22 11:03:18 +0200160 i2c_init(CONFIG_SYS_OMAP24_I2C_SPEED, CONFIG_SYS_OMAP24_I2C_SLAVE);
Lars Poeschel67b4a792013-01-11 00:53:31 +0000161
Tom Rinif3b6a1d2013-08-09 11:22:13 -0400162 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
Lars Poeschel67b4a792013-01-11 00:53:31 +0000163
164 return 0;
165}
166
167#ifdef CONFIG_DRIVER_TI_CPSW
168static void cpsw_control(int enabled)
169{
170 /* VTP can be added here */
171
172 return;
173}
174
175static struct cpsw_slave_data cpsw_slaves[] = {
176 {
177 .slave_reg_ofs = 0x208,
178 .sliver_reg_ofs = 0xd80,
Mugunthan V N4944f372014-02-18 07:31:52 -0500179 .phy_addr = 0,
Lars Poeschel67b4a792013-01-11 00:53:31 +0000180 .phy_if = PHY_INTERFACE_MODE_RGMII,
181 },
182 {
183 .slave_reg_ofs = 0x308,
184 .sliver_reg_ofs = 0xdc0,
Mugunthan V N4944f372014-02-18 07:31:52 -0500185 .phy_addr = 1,
Lars Poeschel67b4a792013-01-11 00:53:31 +0000186 .phy_if = PHY_INTERFACE_MODE_RGMII,
187 },
188};
189
190static struct cpsw_platform_data cpsw_data = {
Matt Portere24646f2013-03-15 10:07:02 +0000191 .mdio_base = CPSW_MDIO_BASE,
192 .cpsw_base = CPSW_BASE,
Lars Poeschel67b4a792013-01-11 00:53:31 +0000193 .mdio_div = 0xff,
194 .channels = 8,
195 .cpdma_reg_ofs = 0x800,
196 .slaves = 1,
197 .slave_data = cpsw_slaves,
198 .ale_reg_ofs = 0xd00,
199 .ale_entries = 1024,
200 .host_port_reg_ofs = 0x108,
201 .hw_stats_reg_ofs = 0x900,
Lars Poeschel949a6ad2013-09-30 09:51:34 +0200202 .bd_ram_ofs = 0x2000,
Lars Poeschel67b4a792013-01-11 00:53:31 +0000203 .mac_control = (1 << 5),
204 .control = cpsw_control,
205 .host_port_num = 0,
206 .version = CPSW_CTRL_VERSION_2,
207};
208#endif
209
210#if defined(CONFIG_DRIVER_TI_CPSW) || \
Paul Kocialkowskif34dfcb2015-08-04 17:04:06 +0200211 (defined(CONFIG_USB_ETHER) && defined(CONFIG_USB_MUSB_GADGET))
Lars Poeschel67b4a792013-01-11 00:53:31 +0000212int board_eth_init(bd_t *bis)
213{
214 int rv, n = 0;
215#ifdef CONFIG_DRIVER_TI_CPSW
216 uint8_t mac_addr[6];
217 uint32_t mac_hi, mac_lo;
218
219 if (!eth_getenv_enetaddr("ethaddr", mac_addr)) {
220 printf("<ethaddr> not set. Reading from E-fuse\n");
221 /* try reading mac address from efuse */
222 mac_lo = readl(&cdev->macid0l);
223 mac_hi = readl(&cdev->macid0h);
224 mac_addr[0] = mac_hi & 0xFF;
225 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
226 mac_addr[2] = (mac_hi & 0xFF0000) >> 16;
227 mac_addr[3] = (mac_hi & 0xFF000000) >> 24;
228 mac_addr[4] = mac_lo & 0xFF;
229 mac_addr[5] = (mac_lo & 0xFF00) >> 8;
230
Joe Hershberger8ecdbed2015-04-08 01:41:04 -0500231 if (is_valid_ethaddr(mac_addr))
Lars Poeschel67b4a792013-01-11 00:53:31 +0000232 eth_setenv_enetaddr("ethaddr", mac_addr);
233 else
234 goto try_usbether;
235 }
236
237 writel(RMII_RGMII2_MODE_ENABLE, &cdev->miisel);
238
239 rv = cpsw_register(&cpsw_data);
240 if (rv < 0)
241 printf("Error %d registering CPSW switch\n", rv);
242 else
243 n += rv;
244try_usbether:
245#endif
246
247#if defined(CONFIG_USB_ETHER) && !defined(CONFIG_SPL_BUILD)
248 rv = usb_eth_initialize(bis);
249 if (rv < 0)
250 printf("Error %d registering USB_ETHER\n", rv);
251 else
252 n += rv;
253#endif
254 return n;
255}
256#endif