Marek Vasut | fc10272 | 2011-11-08 23:18:20 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
| 38 | DECLARE_GLOBAL_DATA_PTR; |
| 39 | |
| 40 | /* |
| 41 | * Functions |
| 42 | */ |
| 43 | int board_early_init_f(void) |
| 44 | { |
| 45 | /* IO0 clock at 480MHz */ |
Otavio Salvador | bf48fcb | 2013-01-11 03:19:03 +0000 | [diff] [blame] | 46 | mxs_set_ioclk(MXC_IOCLK0, 480000); |
Marek Vasut | fc10272 | 2011-11-08 23:18:20 +0000 | [diff] [blame] | 47 | /* IO1 clock at 480MHz */ |
Otavio Salvador | bf48fcb | 2013-01-11 03:19:03 +0000 | [diff] [blame] | 48 | mxs_set_ioclk(MXC_IOCLK1, 480000); |
Marek Vasut | fc10272 | 2011-11-08 23:18:20 +0000 | [diff] [blame] | 49 | |
| 50 | /* SSP0 clock at 96MHz */ |
Otavio Salvador | bf48fcb | 2013-01-11 03:19:03 +0000 | [diff] [blame] | 51 | mxs_set_sspclk(MXC_SSPCLK0, 96000, 0); |
Marek Vasut | 1d6d5f9 | 2012-08-21 16:17:28 +0000 | [diff] [blame] | 52 | /* SSP2 clock at 160MHz */ |
Otavio Salvador | bf48fcb | 2013-01-11 03:19:03 +0000 | [diff] [blame] | 53 | mxs_set_sspclk(MXC_SSPCLK2, 160000, 0); |
Marek Vasut | fc10272 | 2011-11-08 23:18:20 +0000 | [diff] [blame] | 54 | |
Marek Vasut | 8f59bc1 | 2011-11-08 23:18:27 +0000 | [diff] [blame] | 55 | #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); |
Marek Vasut | f94669f | 2013-02-23 02:43:03 +0000 | [diff] [blame^] | 60 | |
| 61 | mxs_iomux_setup_pad(MX28_PAD_AUART3_RX__GPIO_3_12 | |
| 62 | MXS_PAD_12MA | MXS_PAD_3V3 | MXS_PAD_PULLUP); |
| 63 | gpio_direction_output(MX28_PAD_AUART3_RX__GPIO_3_12, 0); |
Marek Vasut | 8f59bc1 | 2011-11-08 23:18:27 +0000 | [diff] [blame] | 64 | #endif |
| 65 | |
Marek Vasut | fc10272 | 2011-11-08 23:18:20 +0000 | [diff] [blame] | 66 | return 0; |
| 67 | } |
| 68 | |
| 69 | int board_init(void) |
| 70 | { |
| 71 | /* Adress of boot parameters */ |
| 72 | gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100; |
| 73 | |
| 74 | return 0; |
| 75 | } |
| 76 | |
| 77 | int dram_init(void) |
| 78 | { |
Otavio Salvador | 72f8ebf | 2012-08-19 04:58:30 +0000 | [diff] [blame] | 79 | return mxs_dram_init(); |
Marek Vasut | fc10272 | 2011-11-08 23:18:20 +0000 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | #ifdef CONFIG_CMD_MMC |
| 83 | static int m28_mmc_wp(int id) |
| 84 | { |
| 85 | if (id != 0) { |
| 86 | printf("MXS MMC: Invalid card selected (card id = %d)\n", id); |
| 87 | return 1; |
| 88 | } |
| 89 | |
| 90 | return gpio_get_value(MX28_PAD_AUART2_CTS__GPIO_3_10); |
| 91 | } |
| 92 | |
| 93 | int board_mmc_init(bd_t *bis) |
| 94 | { |
Marek Vasut | 74cf05f | 2011-12-02 03:47:39 +0000 | [diff] [blame] | 95 | /* Configure WP as input. */ |
Marek Vasut | fc10272 | 2011-11-08 23:18:20 +0000 | [diff] [blame] | 96 | gpio_direction_input(MX28_PAD_AUART2_CTS__GPIO_3_10); |
Marek Vasut | b7154ec | 2012-05-01 11:09:42 +0000 | [diff] [blame] | 97 | /* Turn on the power to the card. */ |
| 98 | gpio_direction_output(MX28_PAD_PWM3__GPIO_3_28, 0); |
Marek Vasut | fc10272 | 2011-11-08 23:18:20 +0000 | [diff] [blame] | 99 | |
Marek Vasut | 90bc2bf | 2013-01-22 15:01:03 +0000 | [diff] [blame] | 100 | return mxsmmc_initialize(bis, 0, m28_mmc_wp, NULL); |
Marek Vasut | fc10272 | 2011-11-08 23:18:20 +0000 | [diff] [blame] | 101 | } |
| 102 | #endif |
| 103 | |
| 104 | #ifdef CONFIG_CMD_NET |
| 105 | |
| 106 | #define MII_OPMODE_STRAP_OVERRIDE 0x16 |
| 107 | #define MII_PHY_CTRL1 0x1e |
| 108 | #define MII_PHY_CTRL2 0x1f |
| 109 | |
| 110 | int fecmxc_mii_postcall(int phy) |
| 111 | { |
Marek Vasut | b7154ec | 2012-05-01 11:09:42 +0000 | [diff] [blame] | 112 | #if defined(CONFIG_DENX_M28_V11) || defined(CONFIG_DENX_M28_V10) |
| 113 | /* KZ8031 PHY on old boards. */ |
| 114 | const uint32_t freq = 0x0080; |
| 115 | #else |
| 116 | /* KZ8021 PHY on new boards. */ |
| 117 | const uint32_t freq = 0x0000; |
| 118 | #endif |
| 119 | |
Marek Vasut | fc10272 | 2011-11-08 23:18:20 +0000 | [diff] [blame] | 120 | miiphy_write("FEC1", phy, MII_BMCR, 0x9000); |
| 121 | miiphy_write("FEC1", phy, MII_OPMODE_STRAP_OVERRIDE, 0x0202); |
| 122 | if (phy == 3) |
Marek Vasut | b7154ec | 2012-05-01 11:09:42 +0000 | [diff] [blame] | 123 | miiphy_write("FEC1", 3, MII_PHY_CTRL2, 0x8100 | freq); |
Marek Vasut | fc10272 | 2011-11-08 23:18:20 +0000 | [diff] [blame] | 124 | return 0; |
| 125 | } |
| 126 | |
| 127 | int board_eth_init(bd_t *bis) |
| 128 | { |
Otavio Salvador | 9c47114 | 2012-08-05 09:05:31 +0000 | [diff] [blame] | 129 | struct mxs_clkctrl_regs *clkctrl_regs = |
| 130 | (struct mxs_clkctrl_regs *)MXS_CLKCTRL_BASE; |
Marek Vasut | fc10272 | 2011-11-08 23:18:20 +0000 | [diff] [blame] | 131 | struct eth_device *dev; |
| 132 | int ret; |
| 133 | |
| 134 | ret = cpu_eth_init(bis); |
| 135 | |
| 136 | clrsetbits_le32(&clkctrl_regs->hw_clkctrl_enet, |
| 137 | CLKCTRL_ENET_TIME_SEL_MASK | CLKCTRL_ENET_CLK_OUT_EN, |
| 138 | CLKCTRL_ENET_TIME_SEL_RMII_CLK); |
| 139 | |
Marek Vasut | b7154ec | 2012-05-01 11:09:42 +0000 | [diff] [blame] | 140 | #if !defined(CONFIG_DENX_M28_V11) && !defined(CONFIG_DENX_M28_V10) |
| 141 | /* Reset the new PHY */ |
| 142 | gpio_direction_output(MX28_PAD_AUART2_RTS__GPIO_3_11, 0); |
| 143 | udelay(10000); |
| 144 | gpio_set_value(MX28_PAD_AUART2_RTS__GPIO_3_11, 1); |
| 145 | udelay(10000); |
| 146 | #endif |
| 147 | |
Marek Vasut | fc10272 | 2011-11-08 23:18:20 +0000 | [diff] [blame] | 148 | ret = fecmxc_initialize_multi(bis, 0, 0, MXS_ENET0_BASE); |
| 149 | if (ret) { |
| 150 | printf("FEC MXS: Unable to init FEC0\n"); |
| 151 | return ret; |
| 152 | } |
| 153 | |
| 154 | ret = fecmxc_initialize_multi(bis, 1, 3, MXS_ENET1_BASE); |
| 155 | if (ret) { |
| 156 | printf("FEC MXS: Unable to init FEC1\n"); |
| 157 | return ret; |
| 158 | } |
| 159 | |
| 160 | dev = eth_get_dev_by_name("FEC0"); |
| 161 | if (!dev) { |
| 162 | printf("FEC MXS: Unable to get FEC0 device entry\n"); |
| 163 | return -EINVAL; |
| 164 | } |
| 165 | |
| 166 | ret = fecmxc_register_mii_postcall(dev, fecmxc_mii_postcall); |
| 167 | if (ret) { |
| 168 | printf("FEC MXS: Unable to register FEC0 mii postcall\n"); |
| 169 | return ret; |
| 170 | } |
| 171 | |
| 172 | dev = eth_get_dev_by_name("FEC1"); |
| 173 | if (!dev) { |
| 174 | printf("FEC MXS: Unable to get FEC1 device entry\n"); |
| 175 | return -EINVAL; |
| 176 | } |
| 177 | |
| 178 | ret = fecmxc_register_mii_postcall(dev, fecmxc_mii_postcall); |
| 179 | if (ret) { |
| 180 | printf("FEC MXS: Unable to register FEC1 mii postcall\n"); |
| 181 | return ret; |
| 182 | } |
| 183 | |
| 184 | return ret; |
| 185 | } |
| 186 | |
Marek Vasut | fc10272 | 2011-11-08 23:18:20 +0000 | [diff] [blame] | 187 | #endif |