blob: 118e2222a5d64240bae11be9cfb39420b84f7c11 [file] [log] [blame]
Marek Vasut78687b72011-11-08 23:18:20 +00001/*
2 * DENX M28 module
3 *
4 * Copyright (C) 2011 Marek Vasut <marek.vasut@gmail.com>
5 * on behalf of DENX Software Engineering GmbH
6 *
7 * See file CREDITS for list of people who contributed to this
8 * project.
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as
12 * published by the Free Software Foundation; either version 2 of
13 * the License, or (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
23 * MA 02111-1307 USA
24 */
25
26#include <common.h>
27#include <asm/gpio.h>
28#include <asm/io.h>
29#include <asm/arch/imx-regs.h>
30#include <asm/arch/iomux-mx28.h>
31#include <asm/arch/clock.h>
32#include <asm/arch/sys_proto.h>
33#include <linux/mii.h>
34#include <miiphy.h>
35#include <netdev.h>
36#include <errno.h>
37
38DECLARE_GLOBAL_DATA_PTR;
39
40/*
41 * Functions
42 */
43int board_early_init_f(void)
44{
45 /* IO0 clock at 480MHz */
46 mx28_set_ioclk(MXC_IOCLK0, 480000);
47 /* IO1 clock at 480MHz */
48 mx28_set_ioclk(MXC_IOCLK1, 480000);
49
50 /* SSP0 clock at 96MHz */
51 mx28_set_sspclk(MXC_SSPCLK0, 96000, 0);
52 /* SSP2 clock at 96MHz */
53 mx28_set_sspclk(MXC_SSPCLK2, 96000, 0);
54
55 return 0;
56}
57
58int board_init(void)
59{
60 /* Adress of boot parameters */
61 gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
62
63 return 0;
64}
65
66int dram_init(void)
67{
68 /* dram_init must store complete ramsize in gd->ram_size */
69 gd->ram_size = get_ram_size((long *)PHYS_SDRAM_1, PHYS_SDRAM_1_SIZE);
70 return 0;
71}
72
73#ifdef CONFIG_CMD_MMC
74static int m28_mmc_wp(int id)
75{
76 if (id != 0) {
77 printf("MXS MMC: Invalid card selected (card id = %d)\n", id);
78 return 1;
79 }
80
81 return gpio_get_value(MX28_PAD_AUART2_CTS__GPIO_3_10);
82}
83
84int board_mmc_init(bd_t *bis)
85{
86 /* Configure WP as output */
87 gpio_direction_input(MX28_PAD_AUART2_CTS__GPIO_3_10);
88
89 return mxsmmc_initialize(bis, 0, m28_mmc_wp);
90}
91#endif
92
93#ifdef CONFIG_CMD_NET
94
95#define MII_OPMODE_STRAP_OVERRIDE 0x16
96#define MII_PHY_CTRL1 0x1e
97#define MII_PHY_CTRL2 0x1f
98
99int fecmxc_mii_postcall(int phy)
100{
101 miiphy_write("FEC1", phy, MII_BMCR, 0x9000);
102 miiphy_write("FEC1", phy, MII_OPMODE_STRAP_OVERRIDE, 0x0202);
103 if (phy == 3)
104 miiphy_write("FEC1", 3, MII_PHY_CTRL2, 0x8180);
105 return 0;
106}
107
108int board_eth_init(bd_t *bis)
109{
110 struct mx28_clkctrl_regs *clkctrl_regs =
111 (struct mx28_clkctrl_regs *)MXS_CLKCTRL_BASE;
112 struct eth_device *dev;
113 int ret;
114
115 ret = cpu_eth_init(bis);
116
117 clrsetbits_le32(&clkctrl_regs->hw_clkctrl_enet,
118 CLKCTRL_ENET_TIME_SEL_MASK | CLKCTRL_ENET_CLK_OUT_EN,
119 CLKCTRL_ENET_TIME_SEL_RMII_CLK);
120
121 ret = fecmxc_initialize_multi(bis, 0, 0, MXS_ENET0_BASE);
122 if (ret) {
123 printf("FEC MXS: Unable to init FEC0\n");
124 return ret;
125 }
126
127 ret = fecmxc_initialize_multi(bis, 1, 3, MXS_ENET1_BASE);
128 if (ret) {
129 printf("FEC MXS: Unable to init FEC1\n");
130 return ret;
131 }
132
133 dev = eth_get_dev_by_name("FEC0");
134 if (!dev) {
135 printf("FEC MXS: Unable to get FEC0 device entry\n");
136 return -EINVAL;
137 }
138
139 ret = fecmxc_register_mii_postcall(dev, fecmxc_mii_postcall);
140 if (ret) {
141 printf("FEC MXS: Unable to register FEC0 mii postcall\n");
142 return ret;
143 }
144
145 dev = eth_get_dev_by_name("FEC1");
146 if (!dev) {
147 printf("FEC MXS: Unable to get FEC1 device entry\n");
148 return -EINVAL;
149 }
150
151 ret = fecmxc_register_mii_postcall(dev, fecmxc_mii_postcall);
152 if (ret) {
153 printf("FEC MXS: Unable to register FEC1 mii postcall\n");
154 return ret;
155 }
156
157 return ret;
158}
159
160#ifdef CONFIG_M28_FEC_MAC_IN_OCOTP
161
162#define MXS_OCOTP_MAX_TIMEOUT 1000000
163void imx_get_mac_from_fuse(char *mac)
164{
165 struct mx28_ocotp_regs *ocotp_regs =
166 (struct mx28_ocotp_regs *)MXS_OCOTP_BASE;
167 uint32_t data;
168
169 memset(mac, 0, 6);
170
171 writel(OCOTP_CTRL_RD_BANK_OPEN, &ocotp_regs->hw_ocotp_ctrl_set);
172
173 if (mx28_wait_mask_clr(&ocotp_regs->hw_ocotp_ctrl_reg, OCOTP_CTRL_BUSY,
174 MXS_OCOTP_MAX_TIMEOUT)) {
175 printf("MXS FEC: Can't get MAC from OCOTP\n");
176 return;
177 }
178
179 data = readl(&ocotp_regs->hw_ocotp_cust0);
180
181 mac[0] = 0x00;
182 mac[1] = 0x04;
183 mac[2] = (data >> 24) & 0xff;
184 mac[3] = (data >> 16) & 0xff;
185 mac[4] = (data >> 8) & 0xff;
186 mac[5] = data & 0xff;
187}
188#else
189void imx_get_mac_from_fuse(char *mac)
190{
191 memset(mac, 0, 6);
192}
193#endif
194
195#endif