2 * Copyright (C) 2010 <LW@KARO-electronics.de>
4 * This program is free software; you can redistribute it and/or modify it under
5 * the terms of the GNU General Public License version 2 as published by the
6 * Free Software Foundation.
9 #include <linux/delay.h>
10 #include <linux/fec.h>
11 #include <linux/gpio.h>
13 #include <mach/iomux-mx28.h>
14 #include "../devices-mx28.h"
16 #include "module-tx28.h"
18 #define TX28_FEC_PHY_POWER MXS_GPIO_NR(3, 29)
19 #define TX28_FEC_PHY_RESET MXS_GPIO_NR(4, 13)
21 static const iomux_cfg_t tx28_fec_gpio_pads
[] __initconst
= {
23 MX28_PAD_PWM4__GPIO_3_29
|
24 MXS_PAD_4MA
| MXS_PAD_NOPULL
| MXS_PAD_3V3
,
26 MX28_PAD_ENET0_RX_CLK__GPIO_4_13
|
27 MXS_PAD_4MA
| MXS_PAD_NOPULL
| MXS_PAD_3V3
,
28 /* Mode strap pins 0-2 */
29 MX28_PAD_ENET0_RXD0__GPIO_4_3
|
30 MXS_PAD_8MA
| MXS_PAD_PULLUP
| MXS_PAD_3V3
,
31 MX28_PAD_ENET0_RXD1__GPIO_4_4
|
32 MXS_PAD_8MA
| MXS_PAD_PULLUP
| MXS_PAD_3V3
,
33 MX28_PAD_ENET0_RX_EN__GPIO_4_2
|
34 MXS_PAD_8MA
| MXS_PAD_PULLUP
| MXS_PAD_3V3
,
36 MX28_PAD_ENET0_TX_CLK__GPIO_4_5
|
37 MXS_PAD_4MA
| MXS_PAD_NOPULL
| MXS_PAD_3V3
,
39 MX28_PAD_ENET0_MDC__GPIO_4_0
,
40 MX28_PAD_ENET0_MDIO__GPIO_4_1
,
41 MX28_PAD_ENET0_TX_EN__GPIO_4_6
,
42 MX28_PAD_ENET0_TXD0__GPIO_4_7
,
43 MX28_PAD_ENET0_TXD1__GPIO_4_8
,
44 MX28_PAD_ENET_CLK__GPIO_4_16
,
47 #define FEC_MODE (MXS_PAD_8MA | MXS_PAD_PULLUP | MXS_PAD_3V3)
48 static const iomux_cfg_t tx28_fec_pads
[] __initconst
= {
49 MX28_PAD_ENET0_MDC__ENET0_MDC
| FEC_MODE
,
50 MX28_PAD_ENET0_MDIO__ENET0_MDIO
| FEC_MODE
,
51 MX28_PAD_ENET0_RX_EN__ENET0_RX_EN
| FEC_MODE
,
52 MX28_PAD_ENET0_RXD0__ENET0_RXD0
| FEC_MODE
,
53 MX28_PAD_ENET0_RXD1__ENET0_RXD1
| FEC_MODE
,
54 MX28_PAD_ENET0_TX_EN__ENET0_TX_EN
| FEC_MODE
,
55 MX28_PAD_ENET0_TXD0__ENET0_TXD0
| FEC_MODE
,
56 MX28_PAD_ENET0_TXD1__ENET0_TXD1
| FEC_MODE
,
57 MX28_PAD_ENET_CLK__CLKCTRL_ENET
| FEC_MODE
,
60 static const struct fec_platform_data tx28_fec_data __initconst
= {
61 .phy
= PHY_INTERFACE_MODE_RMII
,
64 int __init
tx28_add_fec0(void)
68 pr_debug("%s: Switching FEC PHY power off\n", __func__
);
69 ret
= mxs_iomux_setup_multiple_pads(tx28_fec_gpio_pads
,
70 ARRAY_SIZE(tx28_fec_gpio_pads
));
71 for (i
= 0; i
< ARRAY_SIZE(tx28_fec_gpio_pads
); i
++) {
72 unsigned int gpio
= MXS_GPIO_NR(PAD_BANK(tx28_fec_gpio_pads
[i
]),
73 PAD_PIN(tx28_fec_gpio_pads
[i
]));
75 ret
= gpio_request(gpio
, "FEC");
77 pr_err("Failed to request GPIO_%d_%d: %d\n",
78 PAD_BANK(tx28_fec_gpio_pads
[i
]),
79 PAD_PIN(tx28_fec_gpio_pads
[i
]), ret
);
82 ret
= gpio_direction_output(gpio
, 0);
84 pr_err("Failed to set direction of GPIO_%d_%d to output: %d\n",
85 gpio
/ 32 + 1, gpio
% 32, ret
);
90 /* Power up fec phy */
91 pr_debug("%s: Switching FEC PHY power on\n", __func__
);
92 ret
= gpio_direction_output(TX28_FEC_PHY_POWER
, 1);
94 pr_err("Failed to power on PHY: %d\n", ret
);
97 mdelay(26); /* 25ms according to data sheet */
100 gpio_direction_input(MXS_GPIO_NR(4, 5));
101 /* Mode strap pins */
102 gpio_direction_output(MXS_GPIO_NR(4, 2), 1);
103 gpio_direction_output(MXS_GPIO_NR(4, 3), 1);
104 gpio_direction_output(MXS_GPIO_NR(4, 4), 1);
106 udelay(100); /* minimum assertion time for nRST */
108 pr_debug("%s: Deasserting FEC PHY RESET\n", __func__
);
109 gpio_set_value(TX28_FEC_PHY_RESET
, 1);
111 ret
= mxs_iomux_setup_multiple_pads(tx28_fec_pads
,
112 ARRAY_SIZE(tx28_fec_pads
));
114 pr_debug("%s: mxs_iomux_setup_multiple_pads() failed with rc: %d\n",
118 pr_debug("%s: Registering FEC device\n", __func__
);
119 mx28_add_fec(0, &tx28_fec_data
);
124 unsigned int gpio
= MXS_GPIO_NR(PAD_BANK(tx28_fec_gpio_pads
[i
]),
125 PAD_PIN(tx28_fec_gpio_pads
[i
]));