blob: e561c8225314e53020be86a58091a7a52a54ce1e [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Lars Poeschel67b4a792013-01-11 00:53:31 +00002/*
3 * board.c
4 *
5 * Board functions for Phytec phyCORE-AM335x (pcm051) based boards
6 *
7 * Copyright (C) 2013 Lemonage Software GmbH
8 * Author Lars Poeschel <poeschel@lemonage.de>
Lars Poeschel67b4a792013-01-11 00:53:31 +00009 */
10
11#include <common.h>
Simon Glass5e6201b2019-08-01 09:46:51 -060012#include <env.h>
Lars Poeschel67b4a792013-01-11 00:53:31 +000013#include <errno.h>
Simon Glass274e0b02020-05-10 11:39:56 -060014#include <net.h>
Lars Poeschel67b4a792013-01-11 00:53:31 +000015#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/io.h>
25#include <asm/emif.h>
26#include <asm/gpio.h>
27#include <i2c.h>
28#include <miiphy.h>
29#include <cpsw.h>
30#include "board.h"
31
32DECLARE_GLOBAL_DATA_PTR;
33
Lars Poeschel67b4a792013-01-11 00:53:31 +000034/* MII mode defines */
Lars Poeschel67b4a792013-01-11 00:53:31 +000035#define RMII_RGMII2_MODE_ENABLE 0x49
36
37static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
38
Lars Poeschel67b4a792013-01-11 00:53:31 +000039#ifdef CONFIG_SPL_BUILD
Lars Poeschel67b4a792013-01-11 00:53:31 +000040
41/* DDR RAM defines */
42#define DDR_CLK_MHZ 303 /* DDR_DPLL_MULT value */
43
Lokesh Vutla89a83bf2013-07-30 10:48:52 +053044#define OSC (V_OSCK/1000000)
45const struct dpll_params dpll_ddr = {
46 DDR_CLK_MHZ, OSC-1, 1, -1, -1, -1, -1};
47
48const struct dpll_params *get_dpll_ddr_params(void)
49{
50 return &dpll_ddr;
51}
52
Lars Poeschel2fbf12a2013-11-19 11:22:18 +010053#ifdef CONFIG_REV1
Lokesh Vutla303b2672013-12-10 15:02:21 +053054const struct ctrl_ioregs ioregs = {
55 .cm0ioctl = MT41J256M8HX15E_IOCTRL_VALUE,
56 .cm1ioctl = MT41J256M8HX15E_IOCTRL_VALUE,
57 .cm2ioctl = MT41J256M8HX15E_IOCTRL_VALUE,
58 .dt0ioctl = MT41J256M8HX15E_IOCTRL_VALUE,
59 .dt1ioctl = MT41J256M8HX15E_IOCTRL_VALUE,
60};
61
Lars Poeschel67b4a792013-01-11 00:53:31 +000062static const struct ddr_data ddr3_data = {
63 .datardsratio0 = MT41J256M8HX15E_RD_DQS,
64 .datawdsratio0 = MT41J256M8HX15E_WR_DQS,
65 .datafwsratio0 = MT41J256M8HX15E_PHY_FIFO_WE,
66 .datawrsratio0 = MT41J256M8HX15E_PHY_WR_DATA,
Lars Poeschel67b4a792013-01-11 00:53:31 +000067};
68
69static const struct cmd_control ddr3_cmd_ctrl_data = {
70 .cmd0csratio = MT41J256M8HX15E_RATIO,
Lars Poeschel67b4a792013-01-11 00:53:31 +000071 .cmd0iclkout = MT41J256M8HX15E_INVERT_CLKOUT,
72
73 .cmd1csratio = MT41J256M8HX15E_RATIO,
Lars Poeschel67b4a792013-01-11 00:53:31 +000074 .cmd1iclkout = MT41J256M8HX15E_INVERT_CLKOUT,
75
76 .cmd2csratio = MT41J256M8HX15E_RATIO,
Lars Poeschel67b4a792013-01-11 00:53:31 +000077 .cmd2iclkout = MT41J256M8HX15E_INVERT_CLKOUT,
78};
79
80static struct emif_regs ddr3_emif_reg_data = {
81 .sdram_config = MT41J256M8HX15E_EMIF_SDCFG,
82 .ref_ctrl = MT41J256M8HX15E_EMIF_SDREF,
83 .sdram_tim1 = MT41J256M8HX15E_EMIF_TIM1,
84 .sdram_tim2 = MT41J256M8HX15E_EMIF_TIM2,
85 .sdram_tim3 = MT41J256M8HX15E_EMIF_TIM3,
86 .zq_config = MT41J256M8HX15E_ZQ_CFG,
Lars Poeschel3ccf01a2013-04-03 04:37:52 +000087 .emif_ddr_phy_ctlr_1 = MT41J256M8HX15E_EMIF_READ_LATENCY |
88 PHY_EN_DYN_PWRDN,
Lars Poeschel67b4a792013-01-11 00:53:31 +000089};
Lars Poeschel67b4a792013-01-11 00:53:31 +000090
Lars Poeschel2fbf12a2013-11-19 11:22:18 +010091void sdram_init(void)
92{
Lokesh Vutla303b2672013-12-10 15:02:21 +053093 config_ddr(DDR_CLK_MHZ, &ioregs, &ddr3_data,
Lars Poeschel2fbf12a2013-11-19 11:22:18 +010094 &ddr3_cmd_ctrl_data, &ddr3_emif_reg_data, 0);
95}
96#else
Lokesh Vutla303b2672013-12-10 15:02:21 +053097const struct ctrl_ioregs ioregs = {
98 .cm0ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
99 .cm1ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
100 .cm2ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
101 .dt0ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
102 .dt1ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
103};
104
Lars Poeschel2fbf12a2013-11-19 11:22:18 +0100105static const struct ddr_data ddr3_data = {
106 .datardsratio0 = MT41K256M16HA125E_RD_DQS,
107 .datawdsratio0 = MT41K256M16HA125E_WR_DQS,
108 .datafwsratio0 = MT41K256M16HA125E_PHY_FIFO_WE,
109 .datawrsratio0 = MT41K256M16HA125E_PHY_WR_DATA,
Lars Poeschel2fbf12a2013-11-19 11:22:18 +0100110};
111
112static const struct cmd_control ddr3_cmd_ctrl_data = {
113 .cmd0csratio = MT41K256M16HA125E_RATIO,
Lars Poeschel2fbf12a2013-11-19 11:22:18 +0100114 .cmd0iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
115
116 .cmd1csratio = MT41K256M16HA125E_RATIO,
Lars Poeschel2fbf12a2013-11-19 11:22:18 +0100117 .cmd1iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
118
119 .cmd2csratio = MT41K256M16HA125E_RATIO,
Lars Poeschel2fbf12a2013-11-19 11:22:18 +0100120 .cmd2iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
121};
122
123static struct emif_regs ddr3_emif_reg_data = {
124 .sdram_config = MT41K256M16HA125E_EMIF_SDCFG,
125 .ref_ctrl = MT41K256M16HA125E_EMIF_SDREF,
126 .sdram_tim1 = MT41K256M16HA125E_EMIF_TIM1,
127 .sdram_tim2 = MT41K256M16HA125E_EMIF_TIM2,
128 .sdram_tim3 = MT41K256M16HA125E_EMIF_TIM3,
129 .zq_config = MT41K256M16HA125E_ZQ_CFG,
130 .emif_ddr_phy_ctlr_1 = MT41K256M16HA125E_EMIF_READ_LATENCY |
131 PHY_EN_DYN_PWRDN,
132};
133
134void sdram_init(void)
135{
Lokesh Vutla303b2672013-12-10 15:02:21 +0530136 config_ddr(DDR_CLK_MHZ, &ioregs, &ddr3_data,
Lars Poeschel2fbf12a2013-11-19 11:22:18 +0100137 &ddr3_cmd_ctrl_data, &ddr3_emif_reg_data, 0);
138}
139#endif
140
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530141void set_uart_mux_conf(void)
Lars Poeschel67b4a792013-01-11 00:53:31 +0000142{
Lars Poeschel67b4a792013-01-11 00:53:31 +0000143 enable_uart0_pin_mux();
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530144}
Lars Poeschel67b4a792013-01-11 00:53:31 +0000145
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530146void set_mux_conf_regs(void)
147{
Lars Poeschel67b4a792013-01-11 00:53:31 +0000148 /* Initalize the board header */
149 enable_i2c0_pin_mux();
Heiko Schocherf53f2b82013-10-22 11:03:18 +0200150 i2c_init(CONFIG_SYS_OMAP24_I2C_SPEED, CONFIG_SYS_OMAP24_I2C_SLAVE);
Lars Poeschel67b4a792013-01-11 00:53:31 +0000151
152 enable_board_pin_mux();
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530153}
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530154#endif
Lars Poeschel67b4a792013-01-11 00:53:31 +0000155
156/*
157 * Basic board specific setup. Pinmux has been handled already.
158 */
159int board_init(void)
160{
Heiko Schocherf53f2b82013-10-22 11:03:18 +0200161 i2c_init(CONFIG_SYS_OMAP24_I2C_SPEED, CONFIG_SYS_OMAP24_I2C_SLAVE);
Lars Poeschel67b4a792013-01-11 00:53:31 +0000162
Tom Rinif3b6a1d2013-08-09 11:22:13 -0400163 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
Lars Poeschel67b4a792013-01-11 00:53:31 +0000164
165 return 0;
166}
167
168#ifdef CONFIG_DRIVER_TI_CPSW
169static void cpsw_control(int enabled)
170{
171 /* VTP can be added here */
172
173 return;
174}
175
176static struct cpsw_slave_data cpsw_slaves[] = {
177 {
178 .slave_reg_ofs = 0x208,
179 .sliver_reg_ofs = 0xd80,
Mugunthan V N4944f372014-02-18 07:31:52 -0500180 .phy_addr = 0,
Lars Poeschel67b4a792013-01-11 00:53:31 +0000181 .phy_if = PHY_INTERFACE_MODE_RGMII,
182 },
183 {
184 .slave_reg_ofs = 0x308,
185 .sliver_reg_ofs = 0xdc0,
Mugunthan V N4944f372014-02-18 07:31:52 -0500186 .phy_addr = 1,
Lars Poeschel67b4a792013-01-11 00:53:31 +0000187 .phy_if = PHY_INTERFACE_MODE_RGMII,
188 },
189};
190
191static struct cpsw_platform_data cpsw_data = {
Matt Portere24646f2013-03-15 10:07:02 +0000192 .mdio_base = CPSW_MDIO_BASE,
193 .cpsw_base = CPSW_BASE,
Lars Poeschel67b4a792013-01-11 00:53:31 +0000194 .mdio_div = 0xff,
195 .channels = 8,
196 .cpdma_reg_ofs = 0x800,
197 .slaves = 1,
198 .slave_data = cpsw_slaves,
199 .ale_reg_ofs = 0xd00,
200 .ale_entries = 1024,
201 .host_port_reg_ofs = 0x108,
202 .hw_stats_reg_ofs = 0x900,
Lars Poeschel949a6ad2013-09-30 09:51:34 +0200203 .bd_ram_ofs = 0x2000,
Lars Poeschel67b4a792013-01-11 00:53:31 +0000204 .mac_control = (1 << 5),
205 .control = cpsw_control,
206 .host_port_num = 0,
207 .version = CPSW_CTRL_VERSION_2,
208};
209#endif
210
211#if defined(CONFIG_DRIVER_TI_CPSW) || \
Paul Kocialkowskif34dfcb2015-08-04 17:04:06 +0200212 (defined(CONFIG_USB_ETHER) && defined(CONFIG_USB_MUSB_GADGET))
Lars Poeschel67b4a792013-01-11 00:53:31 +0000213int board_eth_init(bd_t *bis)
214{
215 int rv, n = 0;
216#ifdef CONFIG_DRIVER_TI_CPSW
217 uint8_t mac_addr[6];
218 uint32_t mac_hi, mac_lo;
219
Simon Glass399a9ce2017-08-03 12:22:14 -0600220 if (!eth_env_get_enetaddr("ethaddr", mac_addr)) {
Lars Poeschel67b4a792013-01-11 00:53:31 +0000221 printf("<ethaddr> not set. Reading from E-fuse\n");
222 /* try reading mac address from efuse */
223 mac_lo = readl(&cdev->macid0l);
224 mac_hi = readl(&cdev->macid0h);
225 mac_addr[0] = mac_hi & 0xFF;
226 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
227 mac_addr[2] = (mac_hi & 0xFF0000) >> 16;
228 mac_addr[3] = (mac_hi & 0xFF000000) >> 24;
229 mac_addr[4] = mac_lo & 0xFF;
230 mac_addr[5] = (mac_lo & 0xFF00) >> 8;
231
Joe Hershberger8ecdbed2015-04-08 01:41:04 -0500232 if (is_valid_ethaddr(mac_addr))
Simon Glass8551d552017-08-03 12:22:11 -0600233 eth_env_set_enetaddr("ethaddr", mac_addr);
Lars Poeschel67b4a792013-01-11 00:53:31 +0000234 else
235 goto try_usbether;
236 }
237
238 writel(RMII_RGMII2_MODE_ENABLE, &cdev->miisel);
239
240 rv = cpsw_register(&cpsw_data);
241 if (rv < 0)
242 printf("Error %d registering CPSW switch\n", rv);
243 else
244 n += rv;
245try_usbether:
246#endif
247
248#if defined(CONFIG_USB_ETHER) && !defined(CONFIG_SPL_BUILD)
249 rv = usb_eth_initialize(bis);
250 if (rv < 0)
251 printf("Error %d registering USB_ETHER\n", rv);
252 else
253 n += rv;
254#endif
255 return n;
256}
257#endif