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 */ |
| 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 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); |
| 60 | #endif |
| 61 | |
Marek Vasut | fc10272 | 2011-11-08 23:18:20 +0000 | [diff] [blame] | 62 | return 0; |
| 63 | } |
| 64 | |
| 65 | int 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 | |
Marek Vasut | 3a4ce83 | 2011-11-08 23:18:24 +0000 | [diff] [blame] | 73 | #define HW_DIGCTRL_SCRATCH0 0x8001c280 |
| 74 | #define HW_DIGCTRL_SCRATCH1 0x8001c290 |
Marek Vasut | fc10272 | 2011-11-08 23:18:20 +0000 | [diff] [blame] | 75 | int dram_init(void) |
| 76 | { |
Marek Vasut | 3a4ce83 | 2011-11-08 23:18:24 +0000 | [diff] [blame] | 77 | uint32_t sz[2]; |
| 78 | |
| 79 | sz[0] = readl(HW_DIGCTRL_SCRATCH0); |
| 80 | sz[1] = readl(HW_DIGCTRL_SCRATCH1); |
| 81 | |
| 82 | if (sz[0] != sz[1]) { |
| 83 | printf("MX28:\n" |
| 84 | "Error, the RAM size in HW_DIGCTRL_SCRATCH0 and\n" |
| 85 | "HW_DIGCTRL_SCRATCH1 is not the same. Please\n" |
| 86 | "verify these two registers contain valid RAM size!\n"); |
| 87 | hang(); |
| 88 | } |
| 89 | |
| 90 | gd->ram_size = sz[0]; |
Marek Vasut | fc10272 | 2011-11-08 23:18:20 +0000 | [diff] [blame] | 91 | return 0; |
| 92 | } |
| 93 | |
| 94 | #ifdef CONFIG_CMD_MMC |
| 95 | static int m28_mmc_wp(int id) |
| 96 | { |
| 97 | if (id != 0) { |
| 98 | printf("MXS MMC: Invalid card selected (card id = %d)\n", id); |
| 99 | return 1; |
| 100 | } |
| 101 | |
| 102 | return gpio_get_value(MX28_PAD_AUART2_CTS__GPIO_3_10); |
| 103 | } |
| 104 | |
| 105 | int board_mmc_init(bd_t *bis) |
| 106 | { |
Marek Vasut | 74cf05f | 2011-12-02 03:47:39 +0000 | [diff] [blame] | 107 | /* Configure WP as input. */ |
Marek Vasut | fc10272 | 2011-11-08 23:18:20 +0000 | [diff] [blame] | 108 | gpio_direction_input(MX28_PAD_AUART2_CTS__GPIO_3_10); |
| 109 | |
| 110 | return mxsmmc_initialize(bis, 0, m28_mmc_wp); |
| 111 | } |
| 112 | #endif |
| 113 | |
| 114 | #ifdef CONFIG_CMD_NET |
| 115 | |
| 116 | #define MII_OPMODE_STRAP_OVERRIDE 0x16 |
| 117 | #define MII_PHY_CTRL1 0x1e |
| 118 | #define MII_PHY_CTRL2 0x1f |
| 119 | |
| 120 | int fecmxc_mii_postcall(int phy) |
| 121 | { |
| 122 | miiphy_write("FEC1", phy, MII_BMCR, 0x9000); |
| 123 | miiphy_write("FEC1", phy, MII_OPMODE_STRAP_OVERRIDE, 0x0202); |
| 124 | if (phy == 3) |
| 125 | miiphy_write("FEC1", 3, MII_PHY_CTRL2, 0x8180); |
| 126 | return 0; |
| 127 | } |
| 128 | |
| 129 | int board_eth_init(bd_t *bis) |
| 130 | { |
| 131 | struct mx28_clkctrl_regs *clkctrl_regs = |
| 132 | (struct mx28_clkctrl_regs *)MXS_CLKCTRL_BASE; |
| 133 | struct eth_device *dev; |
| 134 | int ret; |
| 135 | |
| 136 | ret = cpu_eth_init(bis); |
| 137 | |
| 138 | clrsetbits_le32(&clkctrl_regs->hw_clkctrl_enet, |
| 139 | CLKCTRL_ENET_TIME_SEL_MASK | CLKCTRL_ENET_CLK_OUT_EN, |
| 140 | CLKCTRL_ENET_TIME_SEL_RMII_CLK); |
| 141 | |
| 142 | ret = fecmxc_initialize_multi(bis, 0, 0, MXS_ENET0_BASE); |
| 143 | if (ret) { |
| 144 | printf("FEC MXS: Unable to init FEC0\n"); |
| 145 | return ret; |
| 146 | } |
| 147 | |
| 148 | ret = fecmxc_initialize_multi(bis, 1, 3, MXS_ENET1_BASE); |
| 149 | if (ret) { |
| 150 | printf("FEC MXS: Unable to init FEC1\n"); |
| 151 | return ret; |
| 152 | } |
| 153 | |
| 154 | dev = eth_get_dev_by_name("FEC0"); |
| 155 | if (!dev) { |
| 156 | printf("FEC MXS: Unable to get FEC0 device entry\n"); |
| 157 | return -EINVAL; |
| 158 | } |
| 159 | |
| 160 | ret = fecmxc_register_mii_postcall(dev, fecmxc_mii_postcall); |
| 161 | if (ret) { |
| 162 | printf("FEC MXS: Unable to register FEC0 mii postcall\n"); |
| 163 | return ret; |
| 164 | } |
| 165 | |
| 166 | dev = eth_get_dev_by_name("FEC1"); |
| 167 | if (!dev) { |
| 168 | printf("FEC MXS: Unable to get FEC1 device entry\n"); |
| 169 | return -EINVAL; |
| 170 | } |
| 171 | |
| 172 | ret = fecmxc_register_mii_postcall(dev, fecmxc_mii_postcall); |
| 173 | if (ret) { |
| 174 | printf("FEC MXS: Unable to register FEC1 mii postcall\n"); |
| 175 | return ret; |
| 176 | } |
| 177 | |
| 178 | return ret; |
| 179 | } |
| 180 | |
| 181 | #ifdef CONFIG_M28_FEC_MAC_IN_OCOTP |
| 182 | |
| 183 | #define MXS_OCOTP_MAX_TIMEOUT 1000000 |
| 184 | void imx_get_mac_from_fuse(char *mac) |
| 185 | { |
| 186 | struct mx28_ocotp_regs *ocotp_regs = |
| 187 | (struct mx28_ocotp_regs *)MXS_OCOTP_BASE; |
| 188 | uint32_t data; |
| 189 | |
| 190 | memset(mac, 0, 6); |
| 191 | |
| 192 | writel(OCOTP_CTRL_RD_BANK_OPEN, &ocotp_regs->hw_ocotp_ctrl_set); |
| 193 | |
| 194 | if (mx28_wait_mask_clr(&ocotp_regs->hw_ocotp_ctrl_reg, OCOTP_CTRL_BUSY, |
| 195 | MXS_OCOTP_MAX_TIMEOUT)) { |
| 196 | printf("MXS FEC: Can't get MAC from OCOTP\n"); |
| 197 | return; |
| 198 | } |
| 199 | |
| 200 | data = readl(&ocotp_regs->hw_ocotp_cust0); |
| 201 | |
| 202 | mac[0] = 0x00; |
| 203 | mac[1] = 0x04; |
| 204 | mac[2] = (data >> 24) & 0xff; |
| 205 | mac[3] = (data >> 16) & 0xff; |
| 206 | mac[4] = (data >> 8) & 0xff; |
| 207 | mac[5] = data & 0xff; |
| 208 | } |
| 209 | #else |
| 210 | void imx_get_mac_from_fuse(char *mac) |
| 211 | { |
| 212 | memset(mac, 0, 6); |
| 213 | } |
| 214 | #endif |
| 215 | |
| 216 | #endif |