ARM: mxs/mx28evk: add auart devices
[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         /* auart0 */
42         MX28_PAD_AUART0_RX__AUART0_RX |
43                 (MXS_PAD_4MA | MXS_PAD_3V3 | MXS_PAD_NOPULL),
44         MX28_PAD_AUART0_TX__AUART0_TX |
45                 (MXS_PAD_4MA | MXS_PAD_3V3 | MXS_PAD_NOPULL),
46         MX28_PAD_AUART0_CTS__AUART0_CTS |
47                 (MXS_PAD_4MA | MXS_PAD_3V3 | MXS_PAD_NOPULL),
48         MX28_PAD_AUART0_RTS__AUART0_RTS |
49                 (MXS_PAD_4MA | MXS_PAD_3V3 | MXS_PAD_NOPULL),
50         /* auart3 */
51         MX28_PAD_AUART3_RX__AUART3_RX |
52                 (MXS_PAD_4MA | MXS_PAD_3V3 | MXS_PAD_NOPULL),
53         MX28_PAD_AUART3_TX__AUART3_TX |
54                 (MXS_PAD_4MA | MXS_PAD_3V3 | MXS_PAD_NOPULL),
55         MX28_PAD_AUART3_CTS__AUART3_CTS |
56                 (MXS_PAD_4MA | MXS_PAD_3V3 | MXS_PAD_NOPULL),
57         MX28_PAD_AUART3_RTS__AUART3_RTS |
58                 (MXS_PAD_4MA | MXS_PAD_3V3 | MXS_PAD_NOPULL),
59
60         /* fec0 */
61         MX28_PAD_ENET0_MDC__ENET0_MDC |
62                 (MXS_PAD_8MA | MXS_PAD_3V3 | MXS_PAD_PULLUP),
63         MX28_PAD_ENET0_MDIO__ENET0_MDIO |
64                 (MXS_PAD_8MA | MXS_PAD_3V3 | MXS_PAD_PULLUP),
65         MX28_PAD_ENET0_RX_EN__ENET0_RX_EN |
66                 (MXS_PAD_8MA | MXS_PAD_3V3 | MXS_PAD_PULLUP),
67         MX28_PAD_ENET0_RXD0__ENET0_RXD0 |
68                 (MXS_PAD_8MA | MXS_PAD_3V3 | MXS_PAD_PULLUP),
69         MX28_PAD_ENET0_RXD1__ENET0_RXD1 |
70                 (MXS_PAD_8MA | MXS_PAD_3V3 | MXS_PAD_PULLUP),
71         MX28_PAD_ENET0_TX_EN__ENET0_TX_EN |
72                 (MXS_PAD_8MA | MXS_PAD_3V3 | MXS_PAD_PULLUP),
73         MX28_PAD_ENET0_TXD0__ENET0_TXD0 |
74                 (MXS_PAD_8MA | MXS_PAD_3V3 | MXS_PAD_PULLUP),
75         MX28_PAD_ENET0_TXD1__ENET0_TXD1 |
76                 (MXS_PAD_8MA | MXS_PAD_3V3 | MXS_PAD_PULLUP),
77         MX28_PAD_ENET_CLK__CLKCTRL_ENET |
78                 (MXS_PAD_8MA | MXS_PAD_3V3 | MXS_PAD_PULLUP),
79         /* fec1 */
80         MX28_PAD_ENET0_CRS__ENET1_RX_EN |
81                 (MXS_PAD_8MA | MXS_PAD_3V3 | MXS_PAD_PULLUP),
82         MX28_PAD_ENET0_RXD2__ENET1_RXD0 |
83                 (MXS_PAD_8MA | MXS_PAD_3V3 | MXS_PAD_PULLUP),
84         MX28_PAD_ENET0_RXD3__ENET1_RXD1 |
85                 (MXS_PAD_8MA | MXS_PAD_3V3 | MXS_PAD_PULLUP),
86         MX28_PAD_ENET0_COL__ENET1_TX_EN |
87                 (MXS_PAD_8MA | MXS_PAD_3V3 | MXS_PAD_PULLUP),
88         MX28_PAD_ENET0_TXD2__ENET1_TXD0 |
89                 (MXS_PAD_8MA | MXS_PAD_3V3 | MXS_PAD_PULLUP),
90         MX28_PAD_ENET0_TXD3__ENET1_TXD1 |
91                 (MXS_PAD_8MA | MXS_PAD_3V3 | MXS_PAD_PULLUP),
92         /* phy power line */
93         MX28_PAD_SSP1_DATA3__GPIO_2_15 |
94                 (MXS_PAD_4MA | MXS_PAD_3V3 | MXS_PAD_NOPULL),
95         /* phy reset line */
96         MX28_PAD_ENET0_RX_CLK__GPIO_4_13 |
97                 (MXS_PAD_4MA | MXS_PAD_3V3 | MXS_PAD_NOPULL),
98 };
99
100 /* fec */
101 static void __init mx28evk_fec_reset(void)
102 {
103         int ret;
104         struct clk *clk;
105
106         /* Enable fec phy clock */
107         clk = clk_get_sys("pll2", NULL);
108         if (!IS_ERR(clk))
109                 clk_enable(clk);
110
111         /* Power up fec phy */
112         ret = gpio_request(MX28EVK_FEC_PHY_POWER, "fec-phy-power");
113         if (ret) {
114                 pr_err("Failed to request gpio fec-phy-%s: %d\n", "power", ret);
115                 return;
116         }
117
118         ret = gpio_direction_output(MX28EVK_FEC_PHY_POWER, 0);
119         if (ret) {
120                 pr_err("Failed to drive gpio fec-phy-%s: %d\n", "power", ret);
121                 return;
122         }
123
124         /* Reset fec phy */
125         ret = gpio_request(MX28EVK_FEC_PHY_RESET, "fec-phy-reset");
126         if (ret) {
127                 pr_err("Failed to request gpio fec-phy-%s: %d\n", "reset", ret);
128                 return;
129         }
130
131         gpio_direction_output(MX28EVK_FEC_PHY_RESET, 0);
132         if (ret) {
133                 pr_err("Failed to drive gpio fec-phy-%s: %d\n", "reset", ret);
134                 return;
135         }
136
137         mdelay(1);
138         gpio_set_value(MX28EVK_FEC_PHY_RESET, 1);
139 }
140
141 static struct fec_platform_data mx28_fec_pdata[] __initdata = {
142         {
143                 /* fec0 */
144                 .phy = PHY_INTERFACE_MODE_RMII,
145         }, {
146                 /* fec1 */
147                 .phy = PHY_INTERFACE_MODE_RMII,
148         },
149 };
150
151 static int __init mx28evk_fec_get_mac(void)
152 {
153         int i;
154         u32 val;
155         const u32 *ocotp = mxs_get_ocotp();
156
157         if (!ocotp)
158                 goto error;
159
160         /*
161          * OCOTP only stores the last 4 octets for each mac address,
162          * so hard-code Freescale OUI (00:04:9f) here.
163          */
164         for (i = 0; i < 2; i++) {
165                 val = ocotp[i * 4];
166                 mx28_fec_pdata[i].mac[0] = 0x00;
167                 mx28_fec_pdata[i].mac[1] = 0x04;
168                 mx28_fec_pdata[i].mac[2] = 0x9f;
169                 mx28_fec_pdata[i].mac[3] = (val >> 16) & 0xff;
170                 mx28_fec_pdata[i].mac[4] = (val >> 8) & 0xff;
171                 mx28_fec_pdata[i].mac[5] = (val >> 0) & 0xff;
172         }
173
174         return 0;
175
176 error:
177         pr_err("%s: timeout when reading fec mac from OCOTP\n", __func__);
178         return -ETIMEDOUT;
179 }
180
181 static void __init mx28evk_init(void)
182 {
183         mxs_iomux_setup_multiple_pads(mx28evk_pads, ARRAY_SIZE(mx28evk_pads));
184
185         mx28_add_duart();
186         mx28_add_auart0();
187         mx28_add_auart3();
188
189         if (mx28evk_fec_get_mac())
190                 pr_warn("%s: failed on fec mac setup\n", __func__);
191
192         mx28evk_fec_reset();
193         mx28_add_fec(0, &mx28_fec_pdata[0]);
194         mx28_add_fec(1, &mx28_fec_pdata[1]);
195 }
196
197 static void __init mx28evk_timer_init(void)
198 {
199         mx28_clocks_init();
200 }
201
202 static struct sys_timer mx28evk_timer = {
203         .init   = mx28evk_timer_init,
204 };
205
206 MACHINE_START(MX28EVK, "Freescale MX28 EVK")
207         /* Maintainer: Freescale Semiconductor, Inc. */
208         .map_io         = mx28_map_io,
209         .init_irq       = mx28_init_irq,
210         .init_machine   = mx28evk_init,
211         .timer          = &mx28evk_timer,
212 MACHINE_END