blob: 034886ad5d9da980ffbd6c7cfe5a0c64491b0d8d [file] [log] [blame]
Lars Poeschel1c1b7c32013-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 Denk1a459662013-07-08 09:37:19 +02009 * SPDX-License-Identifier: GPL-2.0+
Lars Poeschel1c1b7c32013-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 Poeschel1c1b7c32013-01-11 00:53:31 +000033/* MII mode defines */
Lars Poeschel1c1b7c32013-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 Poeschel1c1b7c32013-01-11 00:53:31 +000038#ifdef CONFIG_SPL_BUILD
Lars Poeschel1c1b7c32013-01-11 00:53:31 +000039
40/* DDR RAM defines */
41#define DDR_CLK_MHZ 303 /* DDR_DPLL_MULT value */
42
Lokesh Vutla94d77fb2013-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 Poeschel1c1b7c32013-01-11 00:53:31 +000052static const struct ddr_data ddr3_data = {
53 .datardsratio0 = MT41J256M8HX15E_RD_DQS,
54 .datawdsratio0 = MT41J256M8HX15E_WR_DQS,
55 .datafwsratio0 = MT41J256M8HX15E_PHY_FIFO_WE,
56 .datawrsratio0 = MT41J256M8HX15E_PHY_WR_DATA,
57 .datadldiff0 = PHY_DLL_LOCK_DIFF,
58};
59
60static const struct cmd_control ddr3_cmd_ctrl_data = {
61 .cmd0csratio = MT41J256M8HX15E_RATIO,
62 .cmd0dldiff = MT41J256M8HX15E_DLL_LOCK_DIFF,
63 .cmd0iclkout = MT41J256M8HX15E_INVERT_CLKOUT,
64
65 .cmd1csratio = MT41J256M8HX15E_RATIO,
66 .cmd1dldiff = MT41J256M8HX15E_DLL_LOCK_DIFF,
67 .cmd1iclkout = MT41J256M8HX15E_INVERT_CLKOUT,
68
69 .cmd2csratio = MT41J256M8HX15E_RATIO,
70 .cmd2dldiff = MT41J256M8HX15E_DLL_LOCK_DIFF,
71 .cmd2iclkout = MT41J256M8HX15E_INVERT_CLKOUT,
72};
73
74static struct emif_regs ddr3_emif_reg_data = {
75 .sdram_config = MT41J256M8HX15E_EMIF_SDCFG,
76 .ref_ctrl = MT41J256M8HX15E_EMIF_SDREF,
77 .sdram_tim1 = MT41J256M8HX15E_EMIF_TIM1,
78 .sdram_tim2 = MT41J256M8HX15E_EMIF_TIM2,
79 .sdram_tim3 = MT41J256M8HX15E_EMIF_TIM3,
80 .zq_config = MT41J256M8HX15E_ZQ_CFG,
Lars Poeschelcecac322013-04-03 04:37:52 +000081 .emif_ddr_phy_ctlr_1 = MT41J256M8HX15E_EMIF_READ_LATENCY |
82 PHY_EN_DYN_PWRDN,
Lars Poeschel1c1b7c32013-01-11 00:53:31 +000083};
Lars Poeschel1c1b7c32013-01-11 00:53:31 +000084
Heiko Schocher06604812013-07-30 10:48:54 +053085void set_uart_mux_conf(void)
Lars Poeschel1c1b7c32013-01-11 00:53:31 +000086{
Lars Poeschel1c1b7c32013-01-11 00:53:31 +000087 enable_uart0_pin_mux();
Heiko Schocher06604812013-07-30 10:48:54 +053088}
Lars Poeschel1c1b7c32013-01-11 00:53:31 +000089
Heiko Schocher06604812013-07-30 10:48:54 +053090void set_mux_conf_regs(void)
91{
Lars Poeschel1c1b7c32013-01-11 00:53:31 +000092 /* Initalize the board header */
93 enable_i2c0_pin_mux();
Heiko Schocher6789e842013-10-22 11:03:18 +020094 i2c_init(CONFIG_SYS_OMAP24_I2C_SPEED, CONFIG_SYS_OMAP24_I2C_SLAVE);
Lars Poeschel1c1b7c32013-01-11 00:53:31 +000095
96 enable_board_pin_mux();
Heiko Schocher06604812013-07-30 10:48:54 +053097}
Lars Poeschel1c1b7c32013-01-11 00:53:31 +000098
Heiko Schocher06604812013-07-30 10:48:54 +053099void sdram_init(void)
100{
Lars Poeschel1c1b7c32013-01-11 00:53:31 +0000101 config_ddr(DDR_CLK_MHZ, MT41J256M8HX15E_IOCTRL_VALUE, &ddr3_data,
Matt Porter3ba65f92013-03-15 10:07:03 +0000102 &ddr3_cmd_ctrl_data, &ddr3_emif_reg_data, 0);
Lars Poeschel1c1b7c32013-01-11 00:53:31 +0000103}
Heiko Schocher06604812013-07-30 10:48:54 +0530104#endif
Lars Poeschel1c1b7c32013-01-11 00:53:31 +0000105
106/*
107 * Basic board specific setup. Pinmux has been handled already.
108 */
109int board_init(void)
110{
Heiko Schocher6789e842013-10-22 11:03:18 +0200111 i2c_init(CONFIG_SYS_OMAP24_I2C_SPEED, CONFIG_SYS_OMAP24_I2C_SLAVE);
Lars Poeschel1c1b7c32013-01-11 00:53:31 +0000112
Tom Rini73feefd2013-08-09 11:22:13 -0400113 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
Lars Poeschel1c1b7c32013-01-11 00:53:31 +0000114
115 return 0;
116}
117
118#ifdef CONFIG_DRIVER_TI_CPSW
119static void cpsw_control(int enabled)
120{
121 /* VTP can be added here */
122
123 return;
124}
125
126static struct cpsw_slave_data cpsw_slaves[] = {
127 {
128 .slave_reg_ofs = 0x208,
129 .sliver_reg_ofs = 0xd80,
130 .phy_id = 0,
131 .phy_if = PHY_INTERFACE_MODE_RGMII,
132 },
133 {
134 .slave_reg_ofs = 0x308,
135 .sliver_reg_ofs = 0xdc0,
136 .phy_id = 1,
137 .phy_if = PHY_INTERFACE_MODE_RGMII,
138 },
139};
140
141static struct cpsw_platform_data cpsw_data = {
Matt Porter81df2ba2013-03-15 10:07:02 +0000142 .mdio_base = CPSW_MDIO_BASE,
143 .cpsw_base = CPSW_BASE,
Lars Poeschel1c1b7c32013-01-11 00:53:31 +0000144 .mdio_div = 0xff,
145 .channels = 8,
146 .cpdma_reg_ofs = 0x800,
147 .slaves = 1,
148 .slave_data = cpsw_slaves,
149 .ale_reg_ofs = 0xd00,
150 .ale_entries = 1024,
151 .host_port_reg_ofs = 0x108,
152 .hw_stats_reg_ofs = 0x900,
Lars Poeschel6478cde2013-09-30 09:51:34 +0200153 .bd_ram_ofs = 0x2000,
Lars Poeschel1c1b7c32013-01-11 00:53:31 +0000154 .mac_control = (1 << 5),
155 .control = cpsw_control,
156 .host_port_num = 0,
157 .version = CPSW_CTRL_VERSION_2,
158};
159#endif
160
161#if defined(CONFIG_DRIVER_TI_CPSW) || \
162 (defined(CONFIG_USB_ETHER) && defined(CONFIG_MUSB_GADGET))
163int board_eth_init(bd_t *bis)
164{
165 int rv, n = 0;
166#ifdef CONFIG_DRIVER_TI_CPSW
167 uint8_t mac_addr[6];
168 uint32_t mac_hi, mac_lo;
169
170 if (!eth_getenv_enetaddr("ethaddr", mac_addr)) {
171 printf("<ethaddr> not set. Reading from E-fuse\n");
172 /* try reading mac address from efuse */
173 mac_lo = readl(&cdev->macid0l);
174 mac_hi = readl(&cdev->macid0h);
175 mac_addr[0] = mac_hi & 0xFF;
176 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
177 mac_addr[2] = (mac_hi & 0xFF0000) >> 16;
178 mac_addr[3] = (mac_hi & 0xFF000000) >> 24;
179 mac_addr[4] = mac_lo & 0xFF;
180 mac_addr[5] = (mac_lo & 0xFF00) >> 8;
181
182 if (is_valid_ether_addr(mac_addr))
183 eth_setenv_enetaddr("ethaddr", mac_addr);
184 else
185 goto try_usbether;
186 }
187
188 writel(RMII_RGMII2_MODE_ENABLE, &cdev->miisel);
189
190 rv = cpsw_register(&cpsw_data);
191 if (rv < 0)
192 printf("Error %d registering CPSW switch\n", rv);
193 else
194 n += rv;
195try_usbether:
196#endif
197
198#if defined(CONFIG_USB_ETHER) && !defined(CONFIG_SPL_BUILD)
199 rv = usb_eth_initialize(bis);
200 if (rv < 0)
201 printf("Error %d registering USB_ETHER\n", rv);
202 else
203 n += rv;
204#endif
205 return n;
206}
207#endif