blob: 6f1ada82c46b35697592170ca51061a0e065525c [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 Glass97589732020-05-10 11:40:02 -060014#include <init.h>
Simon Glass274e0b02020-05-10 11:39:56 -060015#include <net.h>
Lars Poeschel67b4a792013-01-11 00:53:31 +000016#include <spl.h>
17#include <asm/arch/cpu.h>
18#include <asm/arch/hardware.h>
19#include <asm/arch/omap.h>
20#include <asm/arch/ddr_defs.h>
21#include <asm/arch/clock.h>
22#include <asm/arch/gpio.h>
23#include <asm/arch/mmc_host_def.h>
24#include <asm/arch/sys_proto.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 "board.h"
32
33DECLARE_GLOBAL_DATA_PTR;
34
Lars Poeschel67b4a792013-01-11 00:53:31 +000035/* MII mode defines */
Lars Poeschel67b4a792013-01-11 00:53:31 +000036#define RMII_RGMII2_MODE_ENABLE 0x49
37
38static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
39
Lars Poeschel67b4a792013-01-11 00:53:31 +000040#ifdef CONFIG_SPL_BUILD
Lars Poeschel67b4a792013-01-11 00:53:31 +000041
42/* DDR RAM defines */
43#define DDR_CLK_MHZ 303 /* DDR_DPLL_MULT value */
44
Lokesh Vutla89a83bf2013-07-30 10:48:52 +053045#define OSC (V_OSCK/1000000)
46const struct dpll_params dpll_ddr = {
47 DDR_CLK_MHZ, OSC-1, 1, -1, -1, -1, -1};
48
49const struct dpll_params *get_dpll_ddr_params(void)
50{
51 return &dpll_ddr;
52}
53
Lars Poeschel2fbf12a2013-11-19 11:22:18 +010054#ifdef CONFIG_REV1
Lokesh Vutla303b2672013-12-10 15:02:21 +053055const struct ctrl_ioregs ioregs = {
56 .cm0ioctl = MT41J256M8HX15E_IOCTRL_VALUE,
57 .cm1ioctl = MT41J256M8HX15E_IOCTRL_VALUE,
58 .cm2ioctl = MT41J256M8HX15E_IOCTRL_VALUE,
59 .dt0ioctl = MT41J256M8HX15E_IOCTRL_VALUE,
60 .dt1ioctl = MT41J256M8HX15E_IOCTRL_VALUE,
61};
62
Lars Poeschel67b4a792013-01-11 00:53:31 +000063static const struct ddr_data ddr3_data = {
64 .datardsratio0 = MT41J256M8HX15E_RD_DQS,
65 .datawdsratio0 = MT41J256M8HX15E_WR_DQS,
66 .datafwsratio0 = MT41J256M8HX15E_PHY_FIFO_WE,
67 .datawrsratio0 = MT41J256M8HX15E_PHY_WR_DATA,
Lars Poeschel67b4a792013-01-11 00:53:31 +000068};
69
70static const struct cmd_control ddr3_cmd_ctrl_data = {
71 .cmd0csratio = MT41J256M8HX15E_RATIO,
Lars Poeschel67b4a792013-01-11 00:53:31 +000072 .cmd0iclkout = MT41J256M8HX15E_INVERT_CLKOUT,
73
74 .cmd1csratio = MT41J256M8HX15E_RATIO,
Lars Poeschel67b4a792013-01-11 00:53:31 +000075 .cmd1iclkout = MT41J256M8HX15E_INVERT_CLKOUT,
76
77 .cmd2csratio = MT41J256M8HX15E_RATIO,
Lars Poeschel67b4a792013-01-11 00:53:31 +000078 .cmd2iclkout = MT41J256M8HX15E_INVERT_CLKOUT,
79};
80
81static struct emif_regs ddr3_emif_reg_data = {
82 .sdram_config = MT41J256M8HX15E_EMIF_SDCFG,
83 .ref_ctrl = MT41J256M8HX15E_EMIF_SDREF,
84 .sdram_tim1 = MT41J256M8HX15E_EMIF_TIM1,
85 .sdram_tim2 = MT41J256M8HX15E_EMIF_TIM2,
86 .sdram_tim3 = MT41J256M8HX15E_EMIF_TIM3,
87 .zq_config = MT41J256M8HX15E_ZQ_CFG,
Lars Poeschel3ccf01a2013-04-03 04:37:52 +000088 .emif_ddr_phy_ctlr_1 = MT41J256M8HX15E_EMIF_READ_LATENCY |
89 PHY_EN_DYN_PWRDN,
Lars Poeschel67b4a792013-01-11 00:53:31 +000090};
Lars Poeschel67b4a792013-01-11 00:53:31 +000091
Lars Poeschel2fbf12a2013-11-19 11:22:18 +010092void sdram_init(void)
93{
Lokesh Vutla303b2672013-12-10 15:02:21 +053094 config_ddr(DDR_CLK_MHZ, &ioregs, &ddr3_data,
Lars Poeschel2fbf12a2013-11-19 11:22:18 +010095 &ddr3_cmd_ctrl_data, &ddr3_emif_reg_data, 0);
96}
97#else
Lokesh Vutla303b2672013-12-10 15:02:21 +053098const struct ctrl_ioregs ioregs = {
99 .cm0ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
100 .cm1ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
101 .cm2ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
102 .dt0ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
103 .dt1ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
104};
105
Lars Poeschel2fbf12a2013-11-19 11:22:18 +0100106static const struct ddr_data ddr3_data = {
107 .datardsratio0 = MT41K256M16HA125E_RD_DQS,
108 .datawdsratio0 = MT41K256M16HA125E_WR_DQS,
109 .datafwsratio0 = MT41K256M16HA125E_PHY_FIFO_WE,
110 .datawrsratio0 = MT41K256M16HA125E_PHY_WR_DATA,
Lars Poeschel2fbf12a2013-11-19 11:22:18 +0100111};
112
113static const struct cmd_control ddr3_cmd_ctrl_data = {
114 .cmd0csratio = MT41K256M16HA125E_RATIO,
Lars Poeschel2fbf12a2013-11-19 11:22:18 +0100115 .cmd0iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
116
117 .cmd1csratio = MT41K256M16HA125E_RATIO,
Lars Poeschel2fbf12a2013-11-19 11:22:18 +0100118 .cmd1iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
119
120 .cmd2csratio = MT41K256M16HA125E_RATIO,
Lars Poeschel2fbf12a2013-11-19 11:22:18 +0100121 .cmd2iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
122};
123
124static struct emif_regs ddr3_emif_reg_data = {
125 .sdram_config = MT41K256M16HA125E_EMIF_SDCFG,
126 .ref_ctrl = MT41K256M16HA125E_EMIF_SDREF,
127 .sdram_tim1 = MT41K256M16HA125E_EMIF_TIM1,
128 .sdram_tim2 = MT41K256M16HA125E_EMIF_TIM2,
129 .sdram_tim3 = MT41K256M16HA125E_EMIF_TIM3,
130 .zq_config = MT41K256M16HA125E_ZQ_CFG,
131 .emif_ddr_phy_ctlr_1 = MT41K256M16HA125E_EMIF_READ_LATENCY |
132 PHY_EN_DYN_PWRDN,
133};
134
135void sdram_init(void)
136{
Lokesh Vutla303b2672013-12-10 15:02:21 +0530137 config_ddr(DDR_CLK_MHZ, &ioregs, &ddr3_data,
Lars Poeschel2fbf12a2013-11-19 11:22:18 +0100138 &ddr3_cmd_ctrl_data, &ddr3_emif_reg_data, 0);
139}
140#endif
141
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530142void set_uart_mux_conf(void)
Lars Poeschel67b4a792013-01-11 00:53:31 +0000143{
Lars Poeschel67b4a792013-01-11 00:53:31 +0000144 enable_uart0_pin_mux();
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530145}
Lars Poeschel67b4a792013-01-11 00:53:31 +0000146
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530147void set_mux_conf_regs(void)
148{
Lars Poeschel67b4a792013-01-11 00:53:31 +0000149 /* Initalize the board header */
150 enable_i2c0_pin_mux();
Heiko Schocherf53f2b82013-10-22 11:03:18 +0200151 i2c_init(CONFIG_SYS_OMAP24_I2C_SPEED, CONFIG_SYS_OMAP24_I2C_SLAVE);
Lars Poeschel67b4a792013-01-11 00:53:31 +0000152
153 enable_board_pin_mux();
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530154}
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530155#endif
Lars Poeschel67b4a792013-01-11 00:53:31 +0000156
157/*
158 * Basic board specific setup. Pinmux has been handled already.
159 */
160int board_init(void)
161{
Heiko Schocherf53f2b82013-10-22 11:03:18 +0200162 i2c_init(CONFIG_SYS_OMAP24_I2C_SPEED, CONFIG_SYS_OMAP24_I2C_SLAVE);
Lars Poeschel67b4a792013-01-11 00:53:31 +0000163
Tom Rinif3b6a1d2013-08-09 11:22:13 -0400164 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
Lars Poeschel67b4a792013-01-11 00:53:31 +0000165
166 return 0;
167}
168
169#ifdef CONFIG_DRIVER_TI_CPSW
170static void cpsw_control(int enabled)
171{
172 /* VTP can be added here */
173
174 return;
175}
176
177static struct cpsw_slave_data cpsw_slaves[] = {
178 {
179 .slave_reg_ofs = 0x208,
180 .sliver_reg_ofs = 0xd80,
Mugunthan V N4944f372014-02-18 07:31:52 -0500181 .phy_addr = 0,
Lars Poeschel67b4a792013-01-11 00:53:31 +0000182 .phy_if = PHY_INTERFACE_MODE_RGMII,
183 },
184 {
185 .slave_reg_ofs = 0x308,
186 .sliver_reg_ofs = 0xdc0,
Mugunthan V N4944f372014-02-18 07:31:52 -0500187 .phy_addr = 1,
Lars Poeschel67b4a792013-01-11 00:53:31 +0000188 .phy_if = PHY_INTERFACE_MODE_RGMII,
189 },
190};
191
192static struct cpsw_platform_data cpsw_data = {
Matt Portere24646f2013-03-15 10:07:02 +0000193 .mdio_base = CPSW_MDIO_BASE,
194 .cpsw_base = CPSW_BASE,
Lars Poeschel67b4a792013-01-11 00:53:31 +0000195 .mdio_div = 0xff,
196 .channels = 8,
197 .cpdma_reg_ofs = 0x800,
198 .slaves = 1,
199 .slave_data = cpsw_slaves,
200 .ale_reg_ofs = 0xd00,
201 .ale_entries = 1024,
202 .host_port_reg_ofs = 0x108,
203 .hw_stats_reg_ofs = 0x900,
Lars Poeschel949a6ad2013-09-30 09:51:34 +0200204 .bd_ram_ofs = 0x2000,
Lars Poeschel67b4a792013-01-11 00:53:31 +0000205 .mac_control = (1 << 5),
206 .control = cpsw_control,
207 .host_port_num = 0,
208 .version = CPSW_CTRL_VERSION_2,
209};
210#endif
211
212#if defined(CONFIG_DRIVER_TI_CPSW) || \
Paul Kocialkowskif34dfcb2015-08-04 17:04:06 +0200213 (defined(CONFIG_USB_ETHER) && defined(CONFIG_USB_MUSB_GADGET))
Lars Poeschel67b4a792013-01-11 00:53:31 +0000214int board_eth_init(bd_t *bis)
215{
216 int rv, n = 0;
217#ifdef CONFIG_DRIVER_TI_CPSW
218 uint8_t mac_addr[6];
219 uint32_t mac_hi, mac_lo;
220
Simon Glass399a9ce2017-08-03 12:22:14 -0600221 if (!eth_env_get_enetaddr("ethaddr", mac_addr)) {
Lars Poeschel67b4a792013-01-11 00:53:31 +0000222 printf("<ethaddr> not set. Reading from E-fuse\n");
223 /* try reading mac address from efuse */
224 mac_lo = readl(&cdev->macid0l);
225 mac_hi = readl(&cdev->macid0h);
226 mac_addr[0] = mac_hi & 0xFF;
227 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
228 mac_addr[2] = (mac_hi & 0xFF0000) >> 16;
229 mac_addr[3] = (mac_hi & 0xFF000000) >> 24;
230 mac_addr[4] = mac_lo & 0xFF;
231 mac_addr[5] = (mac_lo & 0xFF00) >> 8;
232
Joe Hershberger8ecdbed2015-04-08 01:41:04 -0500233 if (is_valid_ethaddr(mac_addr))
Simon Glass8551d552017-08-03 12:22:11 -0600234 eth_env_set_enetaddr("ethaddr", mac_addr);
Lars Poeschel67b4a792013-01-11 00:53:31 +0000235 else
236 goto try_usbether;
237 }
238
239 writel(RMII_RGMII2_MODE_ENABLE, &cdev->miisel);
240
241 rv = cpsw_register(&cpsw_data);
242 if (rv < 0)
243 printf("Error %d registering CPSW switch\n", rv);
244 else
245 n += rv;
246try_usbether:
247#endif
248
249#if defined(CONFIG_USB_ETHER) && !defined(CONFIG_SPL_BUILD)
250 rv = usb_eth_initialize(bis);
251 if (rv < 0)
252 printf("Error %d registering USB_ETHER\n", rv);
253 else
254 n += rv;
255#endif
256 return n;
257}
258#endif