blob: f4453d64abf18ae247de416f0f9cd53d6d605ba8 [file] [log] [blame]
Marek Vasutfc102722011-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 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02007 * SPDX-License-Identifier: GPL-2.0+
Marek Vasutfc102722011-11-08 23:18:20 +00008 */
9
10#include <common.h>
11#include <asm/gpio.h>
12#include <asm/io.h>
13#include <asm/arch/imx-regs.h>
14#include <asm/arch/iomux-mx28.h>
15#include <asm/arch/clock.h>
16#include <asm/arch/sys_proto.h>
17#include <linux/mii.h>
18#include <miiphy.h>
19#include <netdev.h>
20#include <errno.h>
21
22DECLARE_GLOBAL_DATA_PTR;
23
24/*
25 * Functions
26 */
27int board_early_init_f(void)
28{
29 /* IO0 clock at 480MHz */
Otavio Salvadorbf48fcb2013-01-11 03:19:03 +000030 mxs_set_ioclk(MXC_IOCLK0, 480000);
Marek Vasutfc102722011-11-08 23:18:20 +000031 /* IO1 clock at 480MHz */
Otavio Salvadorbf48fcb2013-01-11 03:19:03 +000032 mxs_set_ioclk(MXC_IOCLK1, 480000);
Marek Vasutfc102722011-11-08 23:18:20 +000033
34 /* SSP0 clock at 96MHz */
Otavio Salvadorbf48fcb2013-01-11 03:19:03 +000035 mxs_set_sspclk(MXC_SSPCLK0, 96000, 0);
Marek Vasut1d6d5f92012-08-21 16:17:28 +000036 /* SSP2 clock at 160MHz */
Otavio Salvadorbf48fcb2013-01-11 03:19:03 +000037 mxs_set_sspclk(MXC_SSPCLK2, 160000, 0);
Marek Vasutfc102722011-11-08 23:18:20 +000038
Marek Vasut8f59bc12011-11-08 23:18:27 +000039#ifdef CONFIG_CMD_USB
40 mxs_iomux_setup_pad(MX28_PAD_SSP2_SS1__USB1_OVERCURRENT);
41 mxs_iomux_setup_pad(MX28_PAD_AUART3_TX__GPIO_3_13 |
42 MXS_PAD_12MA | MXS_PAD_3V3 | MXS_PAD_PULLUP);
43 gpio_direction_output(MX28_PAD_AUART3_TX__GPIO_3_13, 0);
Marek Vasutf94669f2013-02-23 02:43:03 +000044
45 mxs_iomux_setup_pad(MX28_PAD_AUART3_RX__GPIO_3_12 |
46 MXS_PAD_12MA | MXS_PAD_3V3 | MXS_PAD_PULLUP);
47 gpio_direction_output(MX28_PAD_AUART3_RX__GPIO_3_12, 0);
Marek Vasut8f59bc12011-11-08 23:18:27 +000048#endif
49
Marek Vasutfc102722011-11-08 23:18:20 +000050 return 0;
51}
52
53int board_init(void)
54{
55 /* Adress of boot parameters */
56 gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
57
58 return 0;
59}
60
61int dram_init(void)
62{
Otavio Salvador72f8ebf2012-08-19 04:58:30 +000063 return mxs_dram_init();
Marek Vasutfc102722011-11-08 23:18:20 +000064}
65
66#ifdef CONFIG_CMD_MMC
67static int m28_mmc_wp(int id)
68{
69 if (id != 0) {
70 printf("MXS MMC: Invalid card selected (card id = %d)\n", id);
71 return 1;
72 }
73
74 return gpio_get_value(MX28_PAD_AUART2_CTS__GPIO_3_10);
75}
76
77int board_mmc_init(bd_t *bis)
78{
Marek Vasut74cf05f2011-12-02 03:47:39 +000079 /* Configure WP as input. */
Marek Vasutfc102722011-11-08 23:18:20 +000080 gpio_direction_input(MX28_PAD_AUART2_CTS__GPIO_3_10);
Marek Vasutb7154ec2012-05-01 11:09:42 +000081 /* Turn on the power to the card. */
82 gpio_direction_output(MX28_PAD_PWM3__GPIO_3_28, 0);
Marek Vasutfc102722011-11-08 23:18:20 +000083
Marek Vasut90bc2bf2013-01-22 15:01:03 +000084 return mxsmmc_initialize(bis, 0, m28_mmc_wp, NULL);
Marek Vasutfc102722011-11-08 23:18:20 +000085}
86#endif
87
88#ifdef CONFIG_CMD_NET
89
90#define MII_OPMODE_STRAP_OVERRIDE 0x16
91#define MII_PHY_CTRL1 0x1e
92#define MII_PHY_CTRL2 0x1f
93
94int fecmxc_mii_postcall(int phy)
95{
Marek Vasutb7154ec2012-05-01 11:09:42 +000096#if defined(CONFIG_DENX_M28_V11) || defined(CONFIG_DENX_M28_V10)
97 /* KZ8031 PHY on old boards. */
98 const uint32_t freq = 0x0080;
99#else
100 /* KZ8021 PHY on new boards. */
101 const uint32_t freq = 0x0000;
102#endif
103
Marek Vasutfc102722011-11-08 23:18:20 +0000104 miiphy_write("FEC1", phy, MII_BMCR, 0x9000);
105 miiphy_write("FEC1", phy, MII_OPMODE_STRAP_OVERRIDE, 0x0202);
106 if (phy == 3)
Marek Vasutb7154ec2012-05-01 11:09:42 +0000107 miiphy_write("FEC1", 3, MII_PHY_CTRL2, 0x8100 | freq);
Marek Vasutfc102722011-11-08 23:18:20 +0000108 return 0;
109}
110
111int board_eth_init(bd_t *bis)
112{
Otavio Salvador9c471142012-08-05 09:05:31 +0000113 struct mxs_clkctrl_regs *clkctrl_regs =
114 (struct mxs_clkctrl_regs *)MXS_CLKCTRL_BASE;
Marek Vasutfc102722011-11-08 23:18:20 +0000115 struct eth_device *dev;
116 int ret;
117
118 ret = cpu_eth_init(bis);
119
120 clrsetbits_le32(&clkctrl_regs->hw_clkctrl_enet,
121 CLKCTRL_ENET_TIME_SEL_MASK | CLKCTRL_ENET_CLK_OUT_EN,
122 CLKCTRL_ENET_TIME_SEL_RMII_CLK);
123
Marek Vasutb7154ec2012-05-01 11:09:42 +0000124#if !defined(CONFIG_DENX_M28_V11) && !defined(CONFIG_DENX_M28_V10)
125 /* Reset the new PHY */
126 gpio_direction_output(MX28_PAD_AUART2_RTS__GPIO_3_11, 0);
127 udelay(10000);
128 gpio_set_value(MX28_PAD_AUART2_RTS__GPIO_3_11, 1);
129 udelay(10000);
130#endif
131
Marek Vasutfc102722011-11-08 23:18:20 +0000132 ret = fecmxc_initialize_multi(bis, 0, 0, MXS_ENET0_BASE);
133 if (ret) {
134 printf("FEC MXS: Unable to init FEC0\n");
135 return ret;
136 }
137
138 ret = fecmxc_initialize_multi(bis, 1, 3, MXS_ENET1_BASE);
139 if (ret) {
140 printf("FEC MXS: Unable to init FEC1\n");
141 return ret;
142 }
143
144 dev = eth_get_dev_by_name("FEC0");
145 if (!dev) {
146 printf("FEC MXS: Unable to get FEC0 device entry\n");
147 return -EINVAL;
148 }
149
150 ret = fecmxc_register_mii_postcall(dev, fecmxc_mii_postcall);
151 if (ret) {
152 printf("FEC MXS: Unable to register FEC0 mii postcall\n");
153 return ret;
154 }
155
156 dev = eth_get_dev_by_name("FEC1");
157 if (!dev) {
158 printf("FEC MXS: Unable to get FEC1 device entry\n");
159 return -EINVAL;
160 }
161
162 ret = fecmxc_register_mii_postcall(dev, fecmxc_mii_postcall);
163 if (ret) {
164 printf("FEC MXS: Unable to register FEC1 mii postcall\n");
165 return ret;
166 }
167
168 return ret;
169}
170
Marek Vasutfc102722011-11-08 23:18:20 +0000171#endif