Merge branch 'connlimit' of git://dev.medozas.de/linux
[pandora-kernel.git] / arch / arm / mach-mxs / mach-mx28evk.c
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
31 #define MX28EVK_FEC_PHY_POWER   MXS_GPIO_NR(2, 15)
32 #define MX28EVK_FEC_PHY_RESET   MXS_GPIO_NR(4, 13)
33
34 static const iomux_cfg_t mx28evk_pads[] __initconst = {
35         /* duart */
36         MX28_PAD_PWM0__DUART_RX |
37                 (MXS_PAD_4MA | MXS_PAD_3V3 | MXS_PAD_NOPULL),
38         MX28_PAD_PWM1__DUART_TX |
39                 (MXS_PAD_4MA | MXS_PAD_3V3 | MXS_PAD_NOPULL),
40
41         /* fec0 */
42         MX28_PAD_ENET0_MDC__ENET0_MDC |
43                 (MXS_PAD_8MA | MXS_PAD_3V3 | MXS_PAD_PULLUP),
44         MX28_PAD_ENET0_MDIO__ENET0_MDIO |
45                 (MXS_PAD_8MA | MXS_PAD_3V3 | MXS_PAD_PULLUP),
46         MX28_PAD_ENET0_RX_EN__ENET0_RX_EN |
47                 (MXS_PAD_8MA | MXS_PAD_3V3 | MXS_PAD_PULLUP),
48         MX28_PAD_ENET0_RXD0__ENET0_RXD0 |
49                 (MXS_PAD_8MA | MXS_PAD_3V3 | MXS_PAD_PULLUP),
50         MX28_PAD_ENET0_RXD1__ENET0_RXD1 |
51                 (MXS_PAD_8MA | MXS_PAD_3V3 | MXS_PAD_PULLUP),
52         MX28_PAD_ENET0_TX_EN__ENET0_TX_EN |
53                 (MXS_PAD_8MA | MXS_PAD_3V3 | MXS_PAD_PULLUP),
54         MX28_PAD_ENET0_TXD0__ENET0_TXD0 |
55                 (MXS_PAD_8MA | MXS_PAD_3V3 | MXS_PAD_PULLUP),
56         MX28_PAD_ENET0_TXD1__ENET0_TXD1 |
57                 (MXS_PAD_8MA | MXS_PAD_3V3 | MXS_PAD_PULLUP),
58         MX28_PAD_ENET_CLK__CLKCTRL_ENET |
59                 (MXS_PAD_8MA | MXS_PAD_3V3 | MXS_PAD_PULLUP),
60         /* fec1 */
61         MX28_PAD_ENET0_CRS__ENET1_RX_EN |
62                 (MXS_PAD_8MA | MXS_PAD_3V3 | MXS_PAD_PULLUP),
63         MX28_PAD_ENET0_RXD2__ENET1_RXD0 |
64                 (MXS_PAD_8MA | MXS_PAD_3V3 | MXS_PAD_PULLUP),
65         MX28_PAD_ENET0_RXD3__ENET1_RXD1 |
66                 (MXS_PAD_8MA | MXS_PAD_3V3 | MXS_PAD_PULLUP),
67         MX28_PAD_ENET0_COL__ENET1_TX_EN |
68                 (MXS_PAD_8MA | MXS_PAD_3V3 | MXS_PAD_PULLUP),
69         MX28_PAD_ENET0_TXD2__ENET1_TXD0 |
70                 (MXS_PAD_8MA | MXS_PAD_3V3 | MXS_PAD_PULLUP),
71         MX28_PAD_ENET0_TXD3__ENET1_TXD1 |
72                 (MXS_PAD_8MA | MXS_PAD_3V3 | MXS_PAD_PULLUP),
73         /* phy power line */
74         MX28_PAD_SSP1_DATA3__GPIO_2_15 |
75                 (MXS_PAD_4MA | MXS_PAD_3V3 | MXS_PAD_NOPULL),
76         /* phy reset line */
77         MX28_PAD_ENET0_RX_CLK__GPIO_4_13 |
78                 (MXS_PAD_4MA | MXS_PAD_3V3 | MXS_PAD_NOPULL),
79 };
80
81 /* fec */
82 static void __init mx28evk_fec_reset(void)
83 {
84         int ret;
85         struct clk *clk;
86
87         /* Enable fec phy clock */
88         clk = clk_get_sys("pll2", NULL);
89         if (!IS_ERR(clk))
90                 clk_enable(clk);
91
92         /* Power up fec phy */
93         ret = gpio_request(MX28EVK_FEC_PHY_POWER, "fec-phy-power");
94         if (ret) {
95                 pr_err("Failed to request gpio fec-phy-%s: %d\n", "power", ret);
96                 return;
97         }
98
99         ret = gpio_direction_output(MX28EVK_FEC_PHY_POWER, 0);
100         if (ret) {
101                 pr_err("Failed to drive gpio fec-phy-%s: %d\n", "power", ret);
102                 return;
103         }
104
105         /* Reset fec phy */
106         ret = gpio_request(MX28EVK_FEC_PHY_RESET, "fec-phy-reset");
107         if (ret) {
108                 pr_err("Failed to request gpio fec-phy-%s: %d\n", "reset", ret);
109                 return;
110         }
111
112         gpio_direction_output(MX28EVK_FEC_PHY_RESET, 0);
113         if (ret) {
114                 pr_err("Failed to drive gpio fec-phy-%s: %d\n", "reset", ret);
115                 return;
116         }
117
118         mdelay(1);
119         gpio_set_value(MX28EVK_FEC_PHY_RESET, 1);
120 }
121
122 static struct fec_platform_data mx28_fec_pdata[] = {
123         {
124                 /* fec0 */
125                 .phy = PHY_INTERFACE_MODE_RMII,
126         }, {
127                 /* fec1 */
128                 .phy = PHY_INTERFACE_MODE_RMII,
129         },
130 };
131
132 static void __init mx28evk_init(void)
133 {
134         mxs_iomux_setup_multiple_pads(mx28evk_pads, ARRAY_SIZE(mx28evk_pads));
135
136         mx28_add_duart();
137
138         mx28evk_fec_reset();
139         mx28_add_fec(0, &mx28_fec_pdata[0]);
140         mx28_add_fec(1, &mx28_fec_pdata[1]);
141 }
142
143 static void __init mx28evk_timer_init(void)
144 {
145         mx28_clocks_init();
146 }
147
148 static struct sys_timer mx28evk_timer = {
149         .init   = mx28evk_timer_init,
150 };
151
152 MACHINE_START(MX28EVK, "Freescale MX28 EVK")
153         /* Maintainer: Freescale Semiconductor, Inc. */
154         .map_io         = mx28_map_io,
155         .init_irq       = mx28_init_irq,
156         .init_machine   = mx28evk_init,
157         .timer          = &mx28evk_timer,
158 MACHINE_END