blob: 53df4761f6033c41577f69ce348c152779b9f6cc [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
Marek Vasutbf4362f2011-11-08 23:18:27 +000055#ifdef CONFIG_CMD_USB
56 mxs_iomux_setup_pad(MX28_PAD_SSP2_SS1__USB1_OVERCURRENT);
57 mxs_iomux_setup_pad(MX28_PAD_AUART3_TX__GPIO_3_13 |
58 MXS_PAD_12MA | MXS_PAD_3V3 | MXS_PAD_PULLUP);
59 gpio_direction_output(MX28_PAD_AUART3_TX__GPIO_3_13, 0);
60#endif
61
Marek Vasut78687b72011-11-08 23:18:20 +000062 return 0;
63}
64
65int board_init(void)
66{
67 /* Adress of boot parameters */
68 gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
69
70 return 0;
71}
72
73int dram_init(void)
74{
Fabio Estevam93f3a892011-12-20 05:46:33 +000075 return mx28_dram_init();
Marek Vasut78687b72011-11-08 23:18:20 +000076}
77
78#ifdef CONFIG_CMD_MMC
79static int m28_mmc_wp(int id)
80{
81 if (id != 0) {
82 printf("MXS MMC: Invalid card selected (card id = %d)\n", id);
83 return 1;
84 }
85
86 return gpio_get_value(MX28_PAD_AUART2_CTS__GPIO_3_10);
87}
88
89int board_mmc_init(bd_t *bis)
90{
Marek Vasut08738192011-12-02 03:47:39 +000091 /* Configure WP as input. */
Marek Vasut78687b72011-11-08 23:18:20 +000092 gpio_direction_input(MX28_PAD_AUART2_CTS__GPIO_3_10);
93
94 return mxsmmc_initialize(bis, 0, m28_mmc_wp);
95}
96#endif
97
98#ifdef CONFIG_CMD_NET
99
100#define MII_OPMODE_STRAP_OVERRIDE 0x16
101#define MII_PHY_CTRL1 0x1e
102#define MII_PHY_CTRL2 0x1f
103
104int fecmxc_mii_postcall(int phy)
105{
106 miiphy_write("FEC1", phy, MII_BMCR, 0x9000);
107 miiphy_write("FEC1", phy, MII_OPMODE_STRAP_OVERRIDE, 0x0202);
108 if (phy == 3)
109 miiphy_write("FEC1", 3, MII_PHY_CTRL2, 0x8180);
110 return 0;
111}
112
113int board_eth_init(bd_t *bis)
114{
115 struct mx28_clkctrl_regs *clkctrl_regs =
116 (struct mx28_clkctrl_regs *)MXS_CLKCTRL_BASE;
117 struct eth_device *dev;
118 int ret;
119
120 ret = cpu_eth_init(bis);
121
122 clrsetbits_le32(&clkctrl_regs->hw_clkctrl_enet,
123 CLKCTRL_ENET_TIME_SEL_MASK | CLKCTRL_ENET_CLK_OUT_EN,
124 CLKCTRL_ENET_TIME_SEL_RMII_CLK);
125
126 ret = fecmxc_initialize_multi(bis, 0, 0, MXS_ENET0_BASE);
127 if (ret) {
128 printf("FEC MXS: Unable to init FEC0\n");
129 return ret;
130 }
131
132 ret = fecmxc_initialize_multi(bis, 1, 3, MXS_ENET1_BASE);
133 if (ret) {
134 printf("FEC MXS: Unable to init FEC1\n");
135 return ret;
136 }
137
138 dev = eth_get_dev_by_name("FEC0");
139 if (!dev) {
140 printf("FEC MXS: Unable to get FEC0 device entry\n");
141 return -EINVAL;
142 }
143
144 ret = fecmxc_register_mii_postcall(dev, fecmxc_mii_postcall);
145 if (ret) {
146 printf("FEC MXS: Unable to register FEC0 mii postcall\n");
147 return ret;
148 }
149
150 dev = eth_get_dev_by_name("FEC1");
151 if (!dev) {
152 printf("FEC MXS: Unable to get FEC1 device entry\n");
153 return -EINVAL;
154 }
155
156 ret = fecmxc_register_mii_postcall(dev, fecmxc_mii_postcall);
157 if (ret) {
158 printf("FEC MXS: Unable to register FEC1 mii postcall\n");
159 return ret;
160 }
161
162 return ret;
163}
164
Marek Vasut78687b72011-11-08 23:18:20 +0000165#endif