Shawn Guo | 4afbbb7 | 2010-12-18 21:39:35 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2010 Freescale Semiconductor, Inc. All Rights Reserved. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License as published by |
| 6 | * the Free Software Foundation; either version 2 of the License, or |
| 7 | * (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | */ |
| 14 | |
| 15 | #include <linux/delay.h> |
| 16 | #include <linux/platform_device.h> |
| 17 | #include <linux/gpio.h> |
| 18 | #include <linux/irq.h> |
| 19 | #include <linux/clk.h> |
| 20 | |
| 21 | #include <asm/mach-types.h> |
| 22 | #include <asm/mach/arch.h> |
| 23 | #include <asm/mach/time.h> |
| 24 | |
| 25 | #include <mach/common.h> |
| 26 | #include <mach/iomux-mx28.h> |
| 27 | |
| 28 | #include "devices-mx28.h" |
| 29 | #include "gpio.h" |
| 30 | |
Shawn Guo | acc9cdc | 2011-03-03 22:13:38 +0800 | [diff] [blame^] | 31 | #define MX28EVK_FLEXCAN_SWITCH MXS_GPIO_NR(2, 13) |
Shawn Guo | 4afbbb7 | 2010-12-18 21:39:35 +0800 | [diff] [blame] | 32 | #define MX28EVK_FEC_PHY_POWER MXS_GPIO_NR(2, 15) |
| 33 | #define MX28EVK_FEC_PHY_RESET MXS_GPIO_NR(4, 13) |
| 34 | |
| 35 | static const iomux_cfg_t mx28evk_pads[] __initconst = { |
| 36 | /* duart */ |
Shawn Guo | db63a49 | 2011-03-06 00:40:19 +0800 | [diff] [blame] | 37 | MX28_PAD_PWM0__DUART_RX | MXS_PAD_CTRL, |
| 38 | MX28_PAD_PWM1__DUART_TX | MXS_PAD_CTRL, |
Shawn Guo | 4afbbb7 | 2010-12-18 21:39:35 +0800 | [diff] [blame] | 39 | |
Shawn Guo | 1580818 | 2011-02-17 14:28:52 +0800 | [diff] [blame] | 40 | /* auart0 */ |
Shawn Guo | db63a49 | 2011-03-06 00:40:19 +0800 | [diff] [blame] | 41 | MX28_PAD_AUART0_RX__AUART0_RX | MXS_PAD_CTRL, |
| 42 | MX28_PAD_AUART0_TX__AUART0_TX | MXS_PAD_CTRL, |
| 43 | MX28_PAD_AUART0_CTS__AUART0_CTS | MXS_PAD_CTRL, |
| 44 | MX28_PAD_AUART0_RTS__AUART0_RTS | MXS_PAD_CTRL, |
Shawn Guo | 1580818 | 2011-02-17 14:28:52 +0800 | [diff] [blame] | 45 | /* auart3 */ |
Shawn Guo | db63a49 | 2011-03-06 00:40:19 +0800 | [diff] [blame] | 46 | MX28_PAD_AUART3_RX__AUART3_RX | MXS_PAD_CTRL, |
| 47 | MX28_PAD_AUART3_TX__AUART3_TX | MXS_PAD_CTRL, |
| 48 | MX28_PAD_AUART3_CTS__AUART3_CTS | MXS_PAD_CTRL, |
| 49 | MX28_PAD_AUART3_RTS__AUART3_RTS | MXS_PAD_CTRL, |
Shawn Guo | 1580818 | 2011-02-17 14:28:52 +0800 | [diff] [blame] | 50 | |
Shawn Guo | db63a49 | 2011-03-06 00:40:19 +0800 | [diff] [blame] | 51 | #define MXS_PAD_FEC (MXS_PAD_8MA | MXS_PAD_3V3 | MXS_PAD_PULLUP) |
Shawn Guo | 4afbbb7 | 2010-12-18 21:39:35 +0800 | [diff] [blame] | 52 | /* fec0 */ |
Shawn Guo | db63a49 | 2011-03-06 00:40:19 +0800 | [diff] [blame] | 53 | MX28_PAD_ENET0_MDC__ENET0_MDC | MXS_PAD_FEC, |
| 54 | MX28_PAD_ENET0_MDIO__ENET0_MDIO | MXS_PAD_FEC, |
| 55 | MX28_PAD_ENET0_RX_EN__ENET0_RX_EN | MXS_PAD_FEC, |
| 56 | MX28_PAD_ENET0_RXD0__ENET0_RXD0 | MXS_PAD_FEC, |
| 57 | MX28_PAD_ENET0_RXD1__ENET0_RXD1 | MXS_PAD_FEC, |
| 58 | MX28_PAD_ENET0_TX_EN__ENET0_TX_EN | MXS_PAD_FEC, |
| 59 | MX28_PAD_ENET0_TXD0__ENET0_TXD0 | MXS_PAD_FEC, |
| 60 | MX28_PAD_ENET0_TXD1__ENET0_TXD1 | MXS_PAD_FEC, |
| 61 | MX28_PAD_ENET_CLK__CLKCTRL_ENET | MXS_PAD_FEC, |
Shawn Guo | 48f76ed | 2011-01-11 20:09:24 +0800 | [diff] [blame] | 62 | /* fec1 */ |
Shawn Guo | db63a49 | 2011-03-06 00:40:19 +0800 | [diff] [blame] | 63 | MX28_PAD_ENET0_CRS__ENET1_RX_EN | MXS_PAD_FEC, |
| 64 | MX28_PAD_ENET0_RXD2__ENET1_RXD0 | MXS_PAD_FEC, |
| 65 | MX28_PAD_ENET0_RXD3__ENET1_RXD1 | MXS_PAD_FEC, |
| 66 | MX28_PAD_ENET0_COL__ENET1_TX_EN | MXS_PAD_FEC, |
| 67 | MX28_PAD_ENET0_TXD2__ENET1_TXD0 | MXS_PAD_FEC, |
| 68 | MX28_PAD_ENET0_TXD3__ENET1_TXD1 | MXS_PAD_FEC, |
Shawn Guo | 4afbbb7 | 2010-12-18 21:39:35 +0800 | [diff] [blame] | 69 | /* phy power line */ |
Shawn Guo | db63a49 | 2011-03-06 00:40:19 +0800 | [diff] [blame] | 70 | MX28_PAD_SSP1_DATA3__GPIO_2_15 | MXS_PAD_CTRL, |
Shawn Guo | 4afbbb7 | 2010-12-18 21:39:35 +0800 | [diff] [blame] | 71 | /* phy reset line */ |
Shawn Guo | db63a49 | 2011-03-06 00:40:19 +0800 | [diff] [blame] | 72 | MX28_PAD_ENET0_RX_CLK__GPIO_4_13 | MXS_PAD_CTRL, |
Shawn Guo | acc9cdc | 2011-03-03 22:13:38 +0800 | [diff] [blame^] | 73 | |
| 74 | /* flexcan0 */ |
| 75 | MX28_PAD_GPMI_RDY2__CAN0_TX, |
| 76 | MX28_PAD_GPMI_RDY3__CAN0_RX, |
| 77 | /* flexcan1 */ |
| 78 | MX28_PAD_GPMI_CE2N__CAN1_TX, |
| 79 | MX28_PAD_GPMI_CE3N__CAN1_RX, |
| 80 | /* transceiver power control */ |
| 81 | MX28_PAD_SSP1_CMD__GPIO_2_13, |
Shawn Guo | 4afbbb7 | 2010-12-18 21:39:35 +0800 | [diff] [blame] | 82 | }; |
| 83 | |
| 84 | /* fec */ |
| 85 | static void __init mx28evk_fec_reset(void) |
| 86 | { |
| 87 | int ret; |
| 88 | struct clk *clk; |
| 89 | |
| 90 | /* Enable fec phy clock */ |
| 91 | clk = clk_get_sys("pll2", NULL); |
| 92 | if (!IS_ERR(clk)) |
| 93 | clk_enable(clk); |
| 94 | |
| 95 | /* Power up fec phy */ |
| 96 | ret = gpio_request(MX28EVK_FEC_PHY_POWER, "fec-phy-power"); |
| 97 | if (ret) { |
| 98 | pr_err("Failed to request gpio fec-phy-%s: %d\n", "power", ret); |
| 99 | return; |
| 100 | } |
| 101 | |
| 102 | ret = gpio_direction_output(MX28EVK_FEC_PHY_POWER, 0); |
| 103 | if (ret) { |
| 104 | pr_err("Failed to drive gpio fec-phy-%s: %d\n", "power", ret); |
| 105 | return; |
| 106 | } |
| 107 | |
| 108 | /* Reset fec phy */ |
| 109 | ret = gpio_request(MX28EVK_FEC_PHY_RESET, "fec-phy-reset"); |
| 110 | if (ret) { |
| 111 | pr_err("Failed to request gpio fec-phy-%s: %d\n", "reset", ret); |
| 112 | return; |
| 113 | } |
| 114 | |
| 115 | gpio_direction_output(MX28EVK_FEC_PHY_RESET, 0); |
| 116 | if (ret) { |
| 117 | pr_err("Failed to drive gpio fec-phy-%s: %d\n", "reset", ret); |
| 118 | return; |
| 119 | } |
| 120 | |
| 121 | mdelay(1); |
| 122 | gpio_set_value(MX28EVK_FEC_PHY_RESET, 1); |
| 123 | } |
| 124 | |
Shawn Guo | a320b27 | 2011-01-14 15:25:52 +0800 | [diff] [blame] | 125 | static struct fec_platform_data mx28_fec_pdata[] __initdata = { |
Shawn Guo | 48f76ed | 2011-01-11 20:09:24 +0800 | [diff] [blame] | 126 | { |
| 127 | /* fec0 */ |
| 128 | .phy = PHY_INTERFACE_MODE_RMII, |
| 129 | }, { |
| 130 | /* fec1 */ |
| 131 | .phy = PHY_INTERFACE_MODE_RMII, |
| 132 | }, |
Shawn Guo | 4afbbb7 | 2010-12-18 21:39:35 +0800 | [diff] [blame] | 133 | }; |
| 134 | |
Shawn Guo | a320b27 | 2011-01-14 15:25:52 +0800 | [diff] [blame] | 135 | static int __init mx28evk_fec_get_mac(void) |
| 136 | { |
| 137 | int i; |
| 138 | u32 val; |
| 139 | const u32 *ocotp = mxs_get_ocotp(); |
| 140 | |
| 141 | if (!ocotp) |
| 142 | goto error; |
| 143 | |
| 144 | /* |
| 145 | * OCOTP only stores the last 4 octets for each mac address, |
| 146 | * so hard-code Freescale OUI (00:04:9f) here. |
| 147 | */ |
| 148 | for (i = 0; i < 2; i++) { |
| 149 | val = ocotp[i * 4]; |
| 150 | mx28_fec_pdata[i].mac[0] = 0x00; |
| 151 | mx28_fec_pdata[i].mac[1] = 0x04; |
| 152 | mx28_fec_pdata[i].mac[2] = 0x9f; |
| 153 | mx28_fec_pdata[i].mac[3] = (val >> 16) & 0xff; |
| 154 | mx28_fec_pdata[i].mac[4] = (val >> 8) & 0xff; |
| 155 | mx28_fec_pdata[i].mac[5] = (val >> 0) & 0xff; |
| 156 | } |
| 157 | |
| 158 | return 0; |
| 159 | |
| 160 | error: |
| 161 | pr_err("%s: timeout when reading fec mac from OCOTP\n", __func__); |
| 162 | return -ETIMEDOUT; |
| 163 | } |
| 164 | |
Shawn Guo | acc9cdc | 2011-03-03 22:13:38 +0800 | [diff] [blame^] | 165 | /* |
| 166 | * MX28EVK_FLEXCAN_SWITCH is shared between both flexcan controllers |
| 167 | */ |
| 168 | static int flexcan0_en, flexcan1_en; |
| 169 | |
| 170 | static void mx28evk_flexcan_switch(void) |
| 171 | { |
| 172 | if (flexcan0_en || flexcan1_en) |
| 173 | gpio_set_value(MX28EVK_FLEXCAN_SWITCH, 1); |
| 174 | else |
| 175 | gpio_set_value(MX28EVK_FLEXCAN_SWITCH, 0); |
| 176 | } |
| 177 | |
| 178 | static void mx28evk_flexcan0_switch(int enable) |
| 179 | { |
| 180 | flexcan0_en = enable; |
| 181 | mx28evk_flexcan_switch(); |
| 182 | } |
| 183 | |
| 184 | static void mx28evk_flexcan1_switch(int enable) |
| 185 | { |
| 186 | flexcan1_en = enable; |
| 187 | mx28evk_flexcan_switch(); |
| 188 | } |
| 189 | |
| 190 | static const struct flexcan_platform_data |
| 191 | mx28evk_flexcan_pdata[] __initconst = { |
| 192 | { |
| 193 | .transceiver_switch = mx28evk_flexcan0_switch, |
| 194 | }, { |
| 195 | .transceiver_switch = mx28evk_flexcan1_switch, |
| 196 | } |
| 197 | }; |
| 198 | |
Shawn Guo | 4afbbb7 | 2010-12-18 21:39:35 +0800 | [diff] [blame] | 199 | static void __init mx28evk_init(void) |
| 200 | { |
Shawn Guo | acc9cdc | 2011-03-03 22:13:38 +0800 | [diff] [blame^] | 201 | int ret; |
| 202 | |
Shawn Guo | 4afbbb7 | 2010-12-18 21:39:35 +0800 | [diff] [blame] | 203 | mxs_iomux_setup_multiple_pads(mx28evk_pads, ARRAY_SIZE(mx28evk_pads)); |
| 204 | |
| 205 | mx28_add_duart(); |
Shawn Guo | 1580818 | 2011-02-17 14:28:52 +0800 | [diff] [blame] | 206 | mx28_add_auart0(); |
| 207 | mx28_add_auart3(); |
Shawn Guo | 4afbbb7 | 2010-12-18 21:39:35 +0800 | [diff] [blame] | 208 | |
Shawn Guo | a320b27 | 2011-01-14 15:25:52 +0800 | [diff] [blame] | 209 | if (mx28evk_fec_get_mac()) |
| 210 | pr_warn("%s: failed on fec mac setup\n", __func__); |
| 211 | |
Shawn Guo | 4afbbb7 | 2010-12-18 21:39:35 +0800 | [diff] [blame] | 212 | mx28evk_fec_reset(); |
Shawn Guo | 48f76ed | 2011-01-11 20:09:24 +0800 | [diff] [blame] | 213 | mx28_add_fec(0, &mx28_fec_pdata[0]); |
| 214 | mx28_add_fec(1, &mx28_fec_pdata[1]); |
Shawn Guo | acc9cdc | 2011-03-03 22:13:38 +0800 | [diff] [blame^] | 215 | |
| 216 | ret = gpio_request_one(MX28EVK_FLEXCAN_SWITCH, GPIOF_DIR_OUT, |
| 217 | "flexcan-switch"); |
| 218 | if (ret) { |
| 219 | pr_err("failed to request gpio flexcan-switch: %d\n", ret); |
| 220 | } else { |
| 221 | mx28_add_flexcan(0, &mx28evk_flexcan_pdata[0]); |
| 222 | mx28_add_flexcan(1, &mx28evk_flexcan_pdata[1]); |
| 223 | } |
Shawn Guo | 4afbbb7 | 2010-12-18 21:39:35 +0800 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | static void __init mx28evk_timer_init(void) |
| 227 | { |
| 228 | mx28_clocks_init(); |
| 229 | } |
| 230 | |
| 231 | static struct sys_timer mx28evk_timer = { |
| 232 | .init = mx28evk_timer_init, |
| 233 | }; |
| 234 | |
| 235 | MACHINE_START(MX28EVK, "Freescale MX28 EVK") |
| 236 | /* Maintainer: Freescale Semiconductor, Inc. */ |
| 237 | .map_io = mx28_map_io, |
| 238 | .init_irq = mx28_init_irq, |
| 239 | .init_machine = mx28evk_init, |
| 240 | .timer = &mx28evk_timer, |
| 241 | MACHINE_END |