Merge branch 'for-2.6.39' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie...
[pandora-kernel.git] / arch / arm / mach-mxs / module-tx28.c
1 /*
2  * Copyright (C) 2010 <LW@KARO-electronics.de>
3  *
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.
7  */
8
9 #include <linux/delay.h>
10 #include <linux/fec.h>
11 #include <linux/gpio.h>
12
13 #include <mach/iomux-mx28.h>
14 #include "../devices-mx28.h"
15
16 #include "module-tx28.h"
17
18 #define TX28_FEC_PHY_POWER      MXS_GPIO_NR(3, 29)
19 #define TX28_FEC_PHY_RESET      MXS_GPIO_NR(4, 13)
20
21 static const iomux_cfg_t tx28_fec_gpio_pads[] __initconst = {
22         /* PHY POWER */
23         MX28_PAD_PWM4__GPIO_3_29 |
24                 MXS_PAD_4MA | MXS_PAD_NOPULL | MXS_PAD_3V3,
25         /* PHY RESET */
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,
35         /* nINT */
36         MX28_PAD_ENET0_TX_CLK__GPIO_4_5 |
37                 MXS_PAD_4MA | MXS_PAD_NOPULL | MXS_PAD_3V3,
38
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,
45 };
46
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,
58 };
59
60 static const struct fec_platform_data tx28_fec_data __initconst = {
61         .phy = PHY_INTERFACE_MODE_RMII,
62 };
63
64 int __init tx28_add_fec0(void)
65 {
66         int i, ret;
67
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]));
74
75                 ret = gpio_request(gpio, "FEC");
76                 if (ret) {
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);
80                         goto free_gpios;
81                 }
82                 ret = gpio_direction_output(gpio, 0);
83                 if (ret) {
84                         pr_err("Failed to set direction of GPIO_%d_%d to output: %d\n",
85                                         gpio / 32 + 1, gpio % 32, ret);
86                         goto free_gpios;
87                 }
88         }
89
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);
93         if (ret) {
94                 pr_err("Failed to power on PHY: %d\n", ret);
95                 goto free_gpios;
96         }
97         mdelay(26); /* 25ms according to data sheet */
98
99         /* nINT */
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);
105
106         udelay(100); /* minimum assertion time for nRST */
107
108         pr_debug("%s: Deasserting FEC PHY RESET\n", __func__);
109         gpio_set_value(TX28_FEC_PHY_RESET, 1);
110
111         ret = mxs_iomux_setup_multiple_pads(tx28_fec_pads,
112                         ARRAY_SIZE(tx28_fec_pads));
113         if (ret) {
114                 pr_debug("%s: mxs_iomux_setup_multiple_pads() failed with rc: %d\n",
115                                 __func__, ret);
116                 goto free_gpios;
117         }
118         pr_debug("%s: Registering FEC device\n", __func__);
119         mx28_add_fec(0, &tx28_fec_data);
120         return 0;
121
122 free_gpios:
123         while (--i >= 0) {
124                 unsigned int gpio = MXS_GPIO_NR(PAD_BANK(tx28_fec_gpio_pads[i]),
125                         PAD_PIN(tx28_fec_gpio_pads[i]));
126
127                 gpio_free(gpio);
128         }
129
130         return ret;
131 }