Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/wq
[pandora-kernel.git] / arch / arm / mach-stmp378x / stmp378x_devb.c
1 /*
2  * Freescale STMP378X development board support
3  *
4  * Embedded Alley Solutions, Inc <source@embeddedalley.com>
5  *
6  * Copyright 2008 Freescale Semiconductor, Inc. All Rights Reserved.
7  * Copyright 2008 Embedded Alley Solutions, Inc All Rights Reserved.
8  */
9
10 /*
11  * The code contained herein is licensed under the GNU General Public
12  * License. You may obtain a copy of the GNU General Public License
13  * Version 2 or later at the following locations:
14  *
15  * http://www.opensource.org/licenses/gpl-license.html
16  * http://www.gnu.org/copyleft/gpl.html
17  */
18 #include <linux/kernel.h>
19 #include <linux/init.h>
20 #include <linux/io.h>
21 #include <linux/platform_device.h>
22 #include <linux/delay.h>
23 #include <linux/clk.h>
24 #include <linux/err.h>
25 #include <linux/spi/spi.h>
26
27 #include <asm/setup.h>
28 #include <asm/mach-types.h>
29 #include <asm/mach/arch.h>
30
31 #include <mach/pins.h>
32 #include <mach/pinmux.h>
33 #include <mach/platform.h>
34 #include <mach/stmp3xxx.h>
35 #include <mach/mmc.h>
36 #include <mach/gpmi.h>
37
38 #include "stmp378x.h"
39
40 static struct platform_device *devices[] = {
41         &stmp3xxx_dbguart,
42         &stmp3xxx_appuart,
43         &stmp3xxx_watchdog,
44         &stmp3xxx_touchscreen,
45         &stmp3xxx_rtc,
46         &stmp3xxx_keyboard,
47         &stmp3xxx_framebuffer,
48         &stmp3xxx_backlight,
49         &stmp3xxx_rotdec,
50         &stmp3xxx_persistent,
51         &stmp3xxx_dcp_bootstream,
52         &stmp3xxx_dcp,
53         &stmp3xxx_battery,
54         &stmp378x_pxp,
55         &stmp378x_i2c,
56 };
57
58 static struct pin_desc i2c_pins_desc[] = {
59         { PINID_I2C_SCL, PIN_FUN1, PIN_4MA, PIN_3_3V, 0 },
60         { PINID_I2C_SDA, PIN_FUN1, PIN_4MA, PIN_3_3V, 0 },
61 };
62
63 static struct pin_group i2c_pins = {
64         .pins           = i2c_pins_desc,
65         .nr_pins        = ARRAY_SIZE(i2c_pins_desc),
66 };
67
68 static struct pin_desc dbguart_pins_0[] = {
69         { PINID_PWM0, PIN_FUN3, },
70         { PINID_PWM1, PIN_FUN3, },
71 };
72
73 static struct pin_group dbguart_pins[] = {
74         [0] = {
75                 .pins           = dbguart_pins_0,
76                 .nr_pins        = ARRAY_SIZE(dbguart_pins_0),
77         },
78 };
79
80 static int dbguart_pins_control(int id, int request)
81 {
82         int r = 0;
83
84         if (request)
85                 r = stmp3xxx_request_pin_group(&dbguart_pins[id], "debug uart");
86         else
87                 stmp3xxx_release_pin_group(&dbguart_pins[id], "debug uart");
88         return r;
89 }
90
91 static struct pin_desc appuart_pins_0[] = {
92         { PINID_AUART1_CTS, PIN_FUN1, PIN_4MA, PIN_1_8V, 0, },
93         { PINID_AUART1_RTS, PIN_FUN1, PIN_4MA, PIN_1_8V, 0, },
94         { PINID_AUART1_RX, PIN_FUN1, PIN_4MA, PIN_1_8V, 0, },
95         { PINID_AUART1_TX, PIN_FUN1, PIN_4MA, PIN_1_8V, 0, },
96 };
97
98 static struct pin_desc appuart_pins_1[] = {
99 #if 0 /* enable these when second appuart will be connected */
100         { PINID_AUART2_CTS, PIN_FUN1, PIN_4MA, PIN_1_8V, 0, },
101         { PINID_AUART2_RTS, PIN_FUN1, PIN_4MA, PIN_1_8V, 0, },
102         { PINID_AUART2_RX, PIN_FUN1, PIN_4MA, PIN_1_8V, 0, },
103         { PINID_AUART2_TX, PIN_FUN1, PIN_4MA, PIN_1_8V, 0, },
104 #endif
105 };
106
107 static struct pin_desc mmc_pins_desc[] = {
108         { PINID_SSP1_DATA0, PIN_FUN1, PIN_8MA, PIN_3_3V, 1 },
109         { PINID_SSP1_DATA1, PIN_FUN1, PIN_8MA, PIN_3_3V, 1 },
110         { PINID_SSP1_DATA2, PIN_FUN1, PIN_8MA, PIN_3_3V, 1 },
111         { PINID_SSP1_DATA3, PIN_FUN1, PIN_8MA, PIN_3_3V, 1 },
112         { PINID_SSP1_CMD, PIN_FUN1, PIN_8MA, PIN_3_3V, 1 },
113         { PINID_SSP1_SCK, PIN_FUN1, PIN_8MA, PIN_3_3V, 0 },
114         { PINID_SSP1_DETECT, PIN_FUN1, PIN_8MA, PIN_3_3V, 0 },
115 };
116
117 static struct pin_group mmc_pins = {
118         .pins           = mmc_pins_desc,
119         .nr_pins        = ARRAY_SIZE(mmc_pins_desc),
120 };
121
122 static int stmp3xxxmmc_get_wp(void)
123 {
124         return gpio_get_value(PINID_PWM4);
125 }
126
127 static int stmp3xxxmmc_hw_init_ssp1(void)
128 {
129         int ret;
130
131         ret = stmp3xxx_request_pin_group(&mmc_pins, "mmc");
132         if (ret)
133                 goto out;
134
135         /* Configure write protect GPIO pin */
136         ret = gpio_request(PINID_PWM4, "mmc wp");
137         if (ret)
138                 goto out_wp;
139
140         gpio_direction_input(PINID_PWM4);
141
142         /* Configure POWER pin as gpio to drive power to MMC slot */
143         ret = gpio_request(PINID_PWM3, "mmc power");
144         if (ret)
145                 goto out_power;
146
147         gpio_direction_output(PINID_PWM3, 0);
148         mdelay(100);
149
150         return 0;
151
152 out_power:
153         gpio_free(PINID_PWM4);
154 out_wp:
155         stmp3xxx_release_pin_group(&mmc_pins, "mmc");
156 out:
157         return ret;
158 }
159
160 static void stmp3xxxmmc_hw_release_ssp1(void)
161 {
162         gpio_free(PINID_PWM3);
163         gpio_free(PINID_PWM4);
164         stmp3xxx_release_pin_group(&mmc_pins, "mmc");
165 }
166
167 static void stmp3xxxmmc_cmd_pullup_ssp1(int enable)
168 {
169         stmp3xxx_pin_pullup(PINID_SSP1_CMD, enable, "mmc");
170 }
171
172 static unsigned long
173 stmp3xxxmmc_setclock_ssp1(void __iomem *base, unsigned long hz)
174 {
175         struct clk *ssp, *parent;
176         char *p;
177         long r;
178
179         ssp = clk_get(NULL, "ssp");
180
181         /* using SSP1, no timeout, clock rate 1 */
182         writel(BF(2, SSP_TIMING_CLOCK_DIVIDE) |
183                BF(0xFFFF, SSP_TIMING_TIMEOUT),
184                base + HW_SSP_TIMING);
185
186         p = (hz > 1000000) ? "io" : "osc_24M";
187         parent = clk_get(NULL, p);
188         clk_set_parent(ssp, parent);
189         r = clk_set_rate(ssp, 2 * hz / 1000);
190         clk_put(parent);
191         clk_put(ssp);
192
193         return hz;
194 }
195
196 static struct stmp3xxxmmc_platform_data mmc_data = {
197         .hw_init        = stmp3xxxmmc_hw_init_ssp1,
198         .hw_release     = stmp3xxxmmc_hw_release_ssp1,
199         .get_wp         = stmp3xxxmmc_get_wp,
200         .cmd_pullup     = stmp3xxxmmc_cmd_pullup_ssp1,
201         .setclock       = stmp3xxxmmc_setclock_ssp1,
202 };
203
204
205 static struct pin_group appuart_pins[] = {
206         [0] = {
207                 .pins           = appuart_pins_0,
208                 .nr_pins        = ARRAY_SIZE(appuart_pins_0),
209         },
210         [1] = {
211                 .pins           = appuart_pins_1,
212                 .nr_pins        = ARRAY_SIZE(appuart_pins_1),
213         },
214 };
215
216 static struct pin_desc ssp1_pins_desc[] = {
217         { PINID_SSP1_SCK,       PIN_FUN1, PIN_8MA, PIN_3_3V, 0, },
218         { PINID_SSP1_CMD,       PIN_FUN1, PIN_4MA, PIN_3_3V, 0, },
219         { PINID_SSP1_DATA0,     PIN_FUN1, PIN_4MA, PIN_3_3V, 0, },
220         { PINID_SSP1_DATA3,     PIN_FUN1, PIN_4MA, PIN_3_3V, 0, },
221 };
222
223 static struct pin_desc ssp2_pins_desc[] = {
224         { PINID_GPMI_WRN,       PIN_FUN3, PIN_8MA, PIN_3_3V, 0, },
225         { PINID_GPMI_RDY1,      PIN_FUN3, PIN_4MA, PIN_3_3V, 0, },
226         { PINID_GPMI_D00,       PIN_FUN3, PIN_4MA, PIN_3_3V, 0, },
227         { PINID_GPMI_D03,       PIN_FUN3, PIN_4MA, PIN_3_3V, 0, },
228 };
229
230 static struct pin_group ssp1_pins = {
231         .pins = ssp1_pins_desc,
232         .nr_pins = ARRAY_SIZE(ssp1_pins_desc),
233 };
234
235 static struct pin_group ssp2_pins = {
236         .pins = ssp1_pins_desc,
237         .nr_pins = ARRAY_SIZE(ssp2_pins_desc),
238 };
239
240 static struct pin_desc gpmi_pins_desc[] = {
241         { PINID_GPMI_CE0N, PIN_FUN1, PIN_4MA, PIN_3_3V, 0 },
242         { PINID_GPMI_CE1N, PIN_FUN1, PIN_4MA, PIN_3_3V, 0 },
243         { PINID_GMPI_CE2N, PIN_FUN1, PIN_4MA, PIN_3_3V, 0 },
244         { PINID_GPMI_CLE, PIN_FUN1, PIN_4MA, PIN_3_3V, 0 },
245         { PINID_GPMI_ALE, PIN_FUN1, PIN_4MA, PIN_3_3V, 0 },
246         { PINID_GPMI_WPN, PIN_FUN1, PIN_12MA, PIN_3_3V, 0 },
247         { PINID_GPMI_RDY1, PIN_FUN1, PIN_4MA, PIN_3_3V, 0 },
248         { PINID_GPMI_D00, PIN_FUN1, PIN_4MA, PIN_3_3V, 0 },
249         { PINID_GPMI_D01, PIN_FUN1, PIN_4MA, PIN_3_3V, 0 },
250         { PINID_GPMI_D02, PIN_FUN1, PIN_4MA, PIN_3_3V, 0 },
251         { PINID_GPMI_D03, PIN_FUN1, PIN_4MA, PIN_3_3V, 0 },
252         { PINID_GPMI_D04, PIN_FUN1, PIN_4MA, PIN_3_3V, 0 },
253         { PINID_GPMI_D05, PIN_FUN1, PIN_4MA, PIN_3_3V, 0 },
254         { PINID_GPMI_D06, PIN_FUN1, PIN_4MA, PIN_3_3V, 0 },
255         { PINID_GPMI_D07, PIN_FUN1, PIN_4MA, PIN_3_3V, 0 },
256         { PINID_GPMI_RDY0, PIN_FUN1, PIN_4MA, PIN_3_3V, 0 },
257         { PINID_GPMI_RDY2, PIN_FUN1, PIN_4MA, PIN_3_3V, 0 },
258         { PINID_GPMI_RDY3, PIN_FUN1, PIN_4MA, PIN_3_3V, 0 },
259         { PINID_GPMI_WRN, PIN_FUN1, PIN_12MA, PIN_3_3V, 0 },
260         { PINID_GPMI_RDN, PIN_FUN1, PIN_12MA, PIN_3_3V, 0 },
261 };
262
263 static struct pin_group gpmi_pins = {
264         .pins           = gpmi_pins_desc,
265         .nr_pins        = ARRAY_SIZE(gpmi_pins_desc),
266 };
267
268 static struct mtd_partition gpmi_partitions[] = {
269         [0] = {
270                 .name   = "boot",
271                 .size   = 10 * SZ_1M,
272                 .offset = 0,
273         },
274         [1] = {
275                 .name   = "data",
276                 .size   = MTDPART_SIZ_FULL,
277                 .offset = MTDPART_OFS_APPEND,
278         },
279 };
280
281 static struct gpmi_platform_data gpmi_data = {
282         .pins = &gpmi_pins,
283         .nr_parts = ARRAY_SIZE(gpmi_partitions),
284         .parts = gpmi_partitions,
285         .part_types = { "cmdline", NULL },
286 };
287
288 static struct spi_board_info spi_board_info[] __initdata = {
289 #if defined(CONFIG_ENC28J60) || defined(CONFIG_ENC28J60_MODULE)
290         {
291                 .modalias       = "enc28j60",
292                 .max_speed_hz   = 6 * 1000 * 1000,
293                 .bus_num        = 1,
294                 .chip_select    = 0,
295                 .platform_data  = NULL,
296         },
297 #endif
298 };
299
300 static void __init stmp378x_devb_init(void)
301 {
302         stmp3xxx_pinmux_init(NR_REAL_IRQS);
303
304         /* init stmp3xxx platform */
305         stmp3xxx_init();
306
307         stmp3xxx_dbguart.dev.platform_data = dbguart_pins_control;
308         stmp3xxx_appuart.dev.platform_data = appuart_pins;
309         stmp3xxx_mmc.dev.platform_data = &mmc_data;
310         stmp3xxx_gpmi.dev.platform_data = &gpmi_data;
311         stmp3xxx_spi1.dev.platform_data = &ssp1_pins;
312         stmp3xxx_spi2.dev.platform_data = &ssp2_pins;
313         stmp378x_i2c.dev.platform_data = &i2c_pins;
314
315         /* register spi devices */
316         spi_register_board_info(spi_board_info, ARRAY_SIZE(spi_board_info));
317
318         /* add board's devices */
319         platform_add_devices(devices, ARRAY_SIZE(devices));
320
321         /* add devices selected by command line ssp1= and ssp2= options */
322         stmp3xxx_ssp1_device_register();
323         stmp3xxx_ssp2_device_register();
324 }
325
326 MACHINE_START(STMP378X, "STMP378X")
327         .boot_params    = 0x40000100,
328         .map_io         = stmp378x_map_io,
329         .init_irq       = stmp378x_init_irq,
330         .timer          = &stmp3xxx_timer,
331         .init_machine   = stmp378x_devb_init,
332 MACHINE_END