Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Marek Vasut | fc10272 | 2011-11-08 23:18:20 +0000 | [diff] [blame] | 2 | /* |
Marek Vasut | fcea480 | 2017-04-05 13:31:01 +0200 | [diff] [blame] | 3 | * Aries M28 module |
Marek Vasut | fc10272 | 2011-11-08 23:18:20 +0000 | [diff] [blame] | 4 | * |
| 5 | * Copyright (C) 2011 Marek Vasut <marek.vasut@gmail.com> |
| 6 | * on behalf of DENX Software Engineering GmbH |
Marek Vasut | fc10272 | 2011-11-08 23:18:20 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <common.h> |
| 10 | #include <asm/gpio.h> |
| 11 | #include <asm/io.h> |
| 12 | #include <asm/arch/imx-regs.h> |
| 13 | #include <asm/arch/iomux-mx28.h> |
| 14 | #include <asm/arch/clock.h> |
| 15 | #include <asm/arch/sys_proto.h> |
| 16 | #include <linux/mii.h> |
| 17 | #include <miiphy.h> |
| 18 | #include <netdev.h> |
| 19 | #include <errno.h> |
| 20 | |
| 21 | DECLARE_GLOBAL_DATA_PTR; |
| 22 | |
| 23 | /* |
| 24 | * Functions |
| 25 | */ |
| 26 | int board_early_init_f(void) |
| 27 | { |
| 28 | /* IO0 clock at 480MHz */ |
Otavio Salvador | bf48fcb | 2013-01-11 03:19:03 +0000 | [diff] [blame] | 29 | mxs_set_ioclk(MXC_IOCLK0, 480000); |
Marek Vasut | fc10272 | 2011-11-08 23:18:20 +0000 | [diff] [blame] | 30 | /* IO1 clock at 480MHz */ |
Otavio Salvador | bf48fcb | 2013-01-11 03:19:03 +0000 | [diff] [blame] | 31 | mxs_set_ioclk(MXC_IOCLK1, 480000); |
Marek Vasut | fc10272 | 2011-11-08 23:18:20 +0000 | [diff] [blame] | 32 | |
| 33 | /* SSP0 clock at 96MHz */ |
Otavio Salvador | bf48fcb | 2013-01-11 03:19:03 +0000 | [diff] [blame] | 34 | mxs_set_sspclk(MXC_SSPCLK0, 96000, 0); |
Marek Vasut | 1d6d5f9 | 2012-08-21 16:17:28 +0000 | [diff] [blame] | 35 | /* SSP2 clock at 160MHz */ |
Otavio Salvador | bf48fcb | 2013-01-11 03:19:03 +0000 | [diff] [blame] | 36 | mxs_set_sspclk(MXC_SSPCLK2, 160000, 0); |
Marek Vasut | fc10272 | 2011-11-08 23:18:20 +0000 | [diff] [blame] | 37 | |
Marek Vasut | 8f59bc1 | 2011-11-08 23:18:27 +0000 | [diff] [blame] | 38 | #ifdef CONFIG_CMD_USB |
| 39 | mxs_iomux_setup_pad(MX28_PAD_SSP2_SS1__USB1_OVERCURRENT); |
| 40 | mxs_iomux_setup_pad(MX28_PAD_AUART3_TX__GPIO_3_13 | |
| 41 | MXS_PAD_12MA | MXS_PAD_3V3 | MXS_PAD_PULLUP); |
| 42 | gpio_direction_output(MX28_PAD_AUART3_TX__GPIO_3_13, 0); |
Marek Vasut | f94669f | 2013-02-23 02:43:03 +0000 | [diff] [blame] | 43 | |
| 44 | mxs_iomux_setup_pad(MX28_PAD_AUART3_RX__GPIO_3_12 | |
| 45 | MXS_PAD_12MA | MXS_PAD_3V3 | MXS_PAD_PULLUP); |
| 46 | gpio_direction_output(MX28_PAD_AUART3_RX__GPIO_3_12, 0); |
Marek Vasut | 8f59bc1 | 2011-11-08 23:18:27 +0000 | [diff] [blame] | 47 | #endif |
| 48 | |
Marek Vasut | fc10272 | 2011-11-08 23:18:20 +0000 | [diff] [blame] | 49 | return 0; |
| 50 | } |
| 51 | |
| 52 | int board_init(void) |
| 53 | { |
| 54 | /* Adress of boot parameters */ |
| 55 | gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100; |
| 56 | |
| 57 | return 0; |
| 58 | } |
| 59 | |
| 60 | int dram_init(void) |
| 61 | { |
Otavio Salvador | 72f8ebf | 2012-08-19 04:58:30 +0000 | [diff] [blame] | 62 | return mxs_dram_init(); |
Marek Vasut | fc10272 | 2011-11-08 23:18:20 +0000 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | #ifdef CONFIG_CMD_MMC |
| 66 | static int m28_mmc_wp(int id) |
| 67 | { |
| 68 | if (id != 0) { |
| 69 | printf("MXS MMC: Invalid card selected (card id = %d)\n", id); |
| 70 | return 1; |
| 71 | } |
| 72 | |
| 73 | return gpio_get_value(MX28_PAD_AUART2_CTS__GPIO_3_10); |
| 74 | } |
| 75 | |
| 76 | int board_mmc_init(bd_t *bis) |
| 77 | { |
Marek Vasut | 74cf05f | 2011-12-02 03:47:39 +0000 | [diff] [blame] | 78 | /* Configure WP as input. */ |
Marek Vasut | fc10272 | 2011-11-08 23:18:20 +0000 | [diff] [blame] | 79 | gpio_direction_input(MX28_PAD_AUART2_CTS__GPIO_3_10); |
Marek Vasut | b7154ec | 2012-05-01 11:09:42 +0000 | [diff] [blame] | 80 | /* Turn on the power to the card. */ |
| 81 | gpio_direction_output(MX28_PAD_PWM3__GPIO_3_28, 0); |
Marek Vasut | fc10272 | 2011-11-08 23:18:20 +0000 | [diff] [blame] | 82 | |
Marek Vasut | 90bc2bf | 2013-01-22 15:01:03 +0000 | [diff] [blame] | 83 | return mxsmmc_initialize(bis, 0, m28_mmc_wp, NULL); |
Marek Vasut | fc10272 | 2011-11-08 23:18:20 +0000 | [diff] [blame] | 84 | } |
| 85 | #endif |
| 86 | |
| 87 | #ifdef CONFIG_CMD_NET |
| 88 | |
| 89 | #define MII_OPMODE_STRAP_OVERRIDE 0x16 |
| 90 | #define MII_PHY_CTRL1 0x1e |
| 91 | #define MII_PHY_CTRL2 0x1f |
| 92 | |
| 93 | int fecmxc_mii_postcall(int phy) |
| 94 | { |
Marek Vasut | fcea480 | 2017-04-05 13:31:01 +0200 | [diff] [blame] | 95 | #if defined(CONFIG_ARIES_M28_V11) || defined(CONFIG_ARIES_M28_V10) |
Marek Vasut | b7154ec | 2012-05-01 11:09:42 +0000 | [diff] [blame] | 96 | /* KZ8031 PHY on old boards. */ |
| 97 | const uint32_t freq = 0x0080; |
| 98 | #else |
| 99 | /* KZ8021 PHY on new boards. */ |
| 100 | const uint32_t freq = 0x0000; |
| 101 | #endif |
| 102 | |
Marek Vasut | fc10272 | 2011-11-08 23:18:20 +0000 | [diff] [blame] | 103 | miiphy_write("FEC1", phy, MII_BMCR, 0x9000); |
| 104 | miiphy_write("FEC1", phy, MII_OPMODE_STRAP_OVERRIDE, 0x0202); |
| 105 | if (phy == 3) |
Marek Vasut | b7154ec | 2012-05-01 11:09:42 +0000 | [diff] [blame] | 106 | miiphy_write("FEC1", 3, MII_PHY_CTRL2, 0x8100 | freq); |
Marek Vasut | fc10272 | 2011-11-08 23:18:20 +0000 | [diff] [blame] | 107 | return 0; |
| 108 | } |
| 109 | |
| 110 | int board_eth_init(bd_t *bis) |
| 111 | { |
Otavio Salvador | 9c47114 | 2012-08-05 09:05:31 +0000 | [diff] [blame] | 112 | struct mxs_clkctrl_regs *clkctrl_regs = |
| 113 | (struct mxs_clkctrl_regs *)MXS_CLKCTRL_BASE; |
Marek Vasut | fc10272 | 2011-11-08 23:18:20 +0000 | [diff] [blame] | 114 | struct eth_device *dev; |
| 115 | int ret; |
| 116 | |
| 117 | ret = cpu_eth_init(bis); |
Fabio Estevam | 17cc236 | 2013-09-20 16:30:49 -0300 | [diff] [blame] | 118 | if (ret) |
| 119 | return ret; |
Marek Vasut | fc10272 | 2011-11-08 23:18:20 +0000 | [diff] [blame] | 120 | |
| 121 | clrsetbits_le32(&clkctrl_regs->hw_clkctrl_enet, |
| 122 | CLKCTRL_ENET_TIME_SEL_MASK | CLKCTRL_ENET_CLK_OUT_EN, |
| 123 | CLKCTRL_ENET_TIME_SEL_RMII_CLK); |
| 124 | |
Marek Vasut | fcea480 | 2017-04-05 13:31:01 +0200 | [diff] [blame] | 125 | #if !defined(CONFIG_ARIES_M28_V11) && !defined(CONFIG_ARIES_M28_V10) |
Marek Vasut | b7154ec | 2012-05-01 11:09:42 +0000 | [diff] [blame] | 126 | /* Reset the new PHY */ |
| 127 | gpio_direction_output(MX28_PAD_AUART2_RTS__GPIO_3_11, 0); |
| 128 | udelay(10000); |
| 129 | gpio_set_value(MX28_PAD_AUART2_RTS__GPIO_3_11, 1); |
| 130 | udelay(10000); |
| 131 | #endif |
| 132 | |
Marek Vasut | fc10272 | 2011-11-08 23:18:20 +0000 | [diff] [blame] | 133 | ret = fecmxc_initialize_multi(bis, 0, 0, MXS_ENET0_BASE); |
| 134 | if (ret) { |
| 135 | printf("FEC MXS: Unable to init FEC0\n"); |
| 136 | return ret; |
| 137 | } |
| 138 | |
| 139 | ret = fecmxc_initialize_multi(bis, 1, 3, MXS_ENET1_BASE); |
| 140 | if (ret) { |
| 141 | printf("FEC MXS: Unable to init FEC1\n"); |
| 142 | return ret; |
| 143 | } |
| 144 | |
| 145 | dev = eth_get_dev_by_name("FEC0"); |
| 146 | if (!dev) { |
| 147 | printf("FEC MXS: Unable to get FEC0 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 FEC0 mii postcall\n"); |
| 154 | return ret; |
| 155 | } |
| 156 | |
| 157 | dev = eth_get_dev_by_name("FEC1"); |
| 158 | if (!dev) { |
| 159 | printf("FEC MXS: Unable to get FEC1 device entry\n"); |
| 160 | return -EINVAL; |
| 161 | } |
| 162 | |
| 163 | ret = fecmxc_register_mii_postcall(dev, fecmxc_mii_postcall); |
| 164 | if (ret) { |
| 165 | printf("FEC MXS: Unable to register FEC1 mii postcall\n"); |
| 166 | return ret; |
| 167 | } |
| 168 | |
| 169 | return ret; |
| 170 | } |
| 171 | |
Marek Vasut | fc10272 | 2011-11-08 23:18:20 +0000 | [diff] [blame] | 172 | #endif |