GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / arch / arm / mach-stmp378x / stmp378x_devb.c
blob330fcdbf2de6744d4ba2982d572073f2d25da257
1 /*
2 * Freescale STMP378X development board support
4 * Embedded Alley Solutions, Inc <source@embeddedalley.com>
6 * Copyright 2008 Freescale Semiconductor, Inc. All Rights Reserved.
7 * Copyright 2008 Embedded Alley Solutions, Inc All Rights Reserved.
8 */
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:
15 * http://www.opensource.org/licenses/gpl-license.html
16 * http://www.gnu.org/copyleft/gpl.html
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>
27 #include <asm/setup.h>
28 #include <asm/mach-types.h>
29 #include <asm/mach/arch.h>
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>
38 #include "stmp378x.h"
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,
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 },
63 static struct pin_group i2c_pins = {
64 .pins = i2c_pins_desc,
65 .nr_pins = ARRAY_SIZE(i2c_pins_desc),
68 static struct pin_desc dbguart_pins_0[] = {
69 { PINID_PWM0, PIN_FUN3, },
70 { PINID_PWM1, PIN_FUN3, },
73 static struct pin_group dbguart_pins[] = {
74 [0] = {
75 .pins = dbguart_pins_0,
76 .nr_pins = ARRAY_SIZE(dbguart_pins_0),
80 static int dbguart_pins_control(int id, int request)
82 int r = 0;
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;
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, },
98 static struct pin_desc appuart_pins_1[] = {
101 static struct pin_desc mmc_pins_desc[] = {
102 { PINID_SSP1_DATA0, PIN_FUN1, PIN_8MA, PIN_3_3V, 1 },
103 { PINID_SSP1_DATA1, PIN_FUN1, PIN_8MA, PIN_3_3V, 1 },
104 { PINID_SSP1_DATA2, PIN_FUN1, PIN_8MA, PIN_3_3V, 1 },
105 { PINID_SSP1_DATA3, PIN_FUN1, PIN_8MA, PIN_3_3V, 1 },
106 { PINID_SSP1_CMD, PIN_FUN1, PIN_8MA, PIN_3_3V, 1 },
107 { PINID_SSP1_SCK, PIN_FUN1, PIN_8MA, PIN_3_3V, 0 },
108 { PINID_SSP1_DETECT, PIN_FUN1, PIN_8MA, PIN_3_3V, 0 },
111 static struct pin_group mmc_pins = {
112 .pins = mmc_pins_desc,
113 .nr_pins = ARRAY_SIZE(mmc_pins_desc),
116 static int stmp3xxxmmc_get_wp(void)
118 return gpio_get_value(PINID_PWM4);
121 static int stmp3xxxmmc_hw_init_ssp1(void)
123 int ret;
125 ret = stmp3xxx_request_pin_group(&mmc_pins, "mmc");
126 if (ret)
127 goto out;
129 /* Configure write protect GPIO pin */
130 ret = gpio_request(PINID_PWM4, "mmc wp");
131 if (ret)
132 goto out_wp;
134 gpio_direction_input(PINID_PWM4);
136 /* Configure POWER pin as gpio to drive power to MMC slot */
137 ret = gpio_request(PINID_PWM3, "mmc power");
138 if (ret)
139 goto out_power;
141 gpio_direction_output(PINID_PWM3, 0);
142 mdelay(100);
144 return 0;
146 out_power:
147 gpio_free(PINID_PWM4);
148 out_wp:
149 stmp3xxx_release_pin_group(&mmc_pins, "mmc");
150 out:
151 return ret;
154 static void stmp3xxxmmc_hw_release_ssp1(void)
156 gpio_free(PINID_PWM3);
157 gpio_free(PINID_PWM4);
158 stmp3xxx_release_pin_group(&mmc_pins, "mmc");
161 static void stmp3xxxmmc_cmd_pullup_ssp1(int enable)
163 stmp3xxx_pin_pullup(PINID_SSP1_CMD, enable, "mmc");
166 static unsigned long
167 stmp3xxxmmc_setclock_ssp1(void __iomem *base, unsigned long hz)
169 struct clk *ssp, *parent;
170 char *p;
171 long r;
173 ssp = clk_get(NULL, "ssp");
175 /* using SSP1, no timeout, clock rate 1 */
176 writel(BF(2, SSP_TIMING_CLOCK_DIVIDE) |
177 BF(0xFFFF, SSP_TIMING_TIMEOUT),
178 base + HW_SSP_TIMING);
180 p = (hz > 1000000) ? "io" : "osc_24M";
181 parent = clk_get(NULL, p);
182 clk_set_parent(ssp, parent);
183 r = clk_set_rate(ssp, 2 * hz / 1000);
184 clk_put(parent);
185 clk_put(ssp);
187 return hz;
190 static struct stmp3xxxmmc_platform_data mmc_data = {
191 .hw_init = stmp3xxxmmc_hw_init_ssp1,
192 .hw_release = stmp3xxxmmc_hw_release_ssp1,
193 .get_wp = stmp3xxxmmc_get_wp,
194 .cmd_pullup = stmp3xxxmmc_cmd_pullup_ssp1,
195 .setclock = stmp3xxxmmc_setclock_ssp1,
199 static struct pin_group appuart_pins[] = {
200 [0] = {
201 .pins = appuart_pins_0,
202 .nr_pins = ARRAY_SIZE(appuart_pins_0),
204 [1] = {
205 .pins = appuart_pins_1,
206 .nr_pins = ARRAY_SIZE(appuart_pins_1),
210 static struct pin_desc ssp1_pins_desc[] = {
211 { PINID_SSP1_SCK, PIN_FUN1, PIN_8MA, PIN_3_3V, 0, },
212 { PINID_SSP1_CMD, PIN_FUN1, PIN_4MA, PIN_3_3V, 0, },
213 { PINID_SSP1_DATA0, PIN_FUN1, PIN_4MA, PIN_3_3V, 0, },
214 { PINID_SSP1_DATA3, PIN_FUN1, PIN_4MA, PIN_3_3V, 0, },
217 static struct pin_desc ssp2_pins_desc[] = {
218 { PINID_GPMI_WRN, PIN_FUN3, PIN_8MA, PIN_3_3V, 0, },
219 { PINID_GPMI_RDY1, PIN_FUN3, PIN_4MA, PIN_3_3V, 0, },
220 { PINID_GPMI_D00, PIN_FUN3, PIN_4MA, PIN_3_3V, 0, },
221 { PINID_GPMI_D03, PIN_FUN3, PIN_4MA, PIN_3_3V, 0, },
224 static struct pin_group ssp1_pins = {
225 .pins = ssp1_pins_desc,
226 .nr_pins = ARRAY_SIZE(ssp1_pins_desc),
229 static struct pin_group ssp2_pins = {
230 .pins = ssp1_pins_desc,
231 .nr_pins = ARRAY_SIZE(ssp2_pins_desc),
234 static struct pin_desc gpmi_pins_desc[] = {
235 { PINID_GPMI_CE0N, PIN_FUN1, PIN_4MA, PIN_3_3V, 0 },
236 { PINID_GPMI_CE1N, PIN_FUN1, PIN_4MA, PIN_3_3V, 0 },
237 { PINID_GMPI_CE2N, PIN_FUN1, PIN_4MA, PIN_3_3V, 0 },
238 { PINID_GPMI_CLE, PIN_FUN1, PIN_4MA, PIN_3_3V, 0 },
239 { PINID_GPMI_ALE, PIN_FUN1, PIN_4MA, PIN_3_3V, 0 },
240 { PINID_GPMI_WPN, PIN_FUN1, PIN_12MA, PIN_3_3V, 0 },
241 { PINID_GPMI_RDY1, PIN_FUN1, PIN_4MA, PIN_3_3V, 0 },
242 { PINID_GPMI_D00, PIN_FUN1, PIN_4MA, PIN_3_3V, 0 },
243 { PINID_GPMI_D01, PIN_FUN1, PIN_4MA, PIN_3_3V, 0 },
244 { PINID_GPMI_D02, PIN_FUN1, PIN_4MA, PIN_3_3V, 0 },
245 { PINID_GPMI_D03, PIN_FUN1, PIN_4MA, PIN_3_3V, 0 },
246 { PINID_GPMI_D04, PIN_FUN1, PIN_4MA, PIN_3_3V, 0 },
247 { PINID_GPMI_D05, PIN_FUN1, PIN_4MA, PIN_3_3V, 0 },
248 { PINID_GPMI_D06, PIN_FUN1, PIN_4MA, PIN_3_3V, 0 },
249 { PINID_GPMI_D07, PIN_FUN1, PIN_4MA, PIN_3_3V, 0 },
250 { PINID_GPMI_RDY0, PIN_FUN1, PIN_4MA, PIN_3_3V, 0 },
251 { PINID_GPMI_RDY2, PIN_FUN1, PIN_4MA, PIN_3_3V, 0 },
252 { PINID_GPMI_RDY3, PIN_FUN1, PIN_4MA, PIN_3_3V, 0 },
253 { PINID_GPMI_WRN, PIN_FUN1, PIN_12MA, PIN_3_3V, 0 },
254 { PINID_GPMI_RDN, PIN_FUN1, PIN_12MA, PIN_3_3V, 0 },
257 static struct pin_group gpmi_pins = {
258 .pins = gpmi_pins_desc,
259 .nr_pins = ARRAY_SIZE(gpmi_pins_desc),
262 static struct mtd_partition gpmi_partitions[] = {
263 [0] = {
264 .name = "boot",
265 .size = 10 * SZ_1M,
266 .offset = 0,
268 [1] = {
269 .name = "data",
270 .size = MTDPART_SIZ_FULL,
271 .offset = MTDPART_OFS_APPEND,
275 static struct gpmi_platform_data gpmi_data = {
276 .pins = &gpmi_pins,
277 .nr_parts = ARRAY_SIZE(gpmi_partitions),
278 .parts = gpmi_partitions,
279 .part_types = { "cmdline", NULL },
282 static struct spi_board_info spi_board_info[] __initdata = {
283 #if defined(CONFIG_ENC28J60) || defined(CONFIG_ENC28J60_MODULE)
285 .modalias = "enc28j60",
286 .max_speed_hz = 6 * 1000 * 1000,
287 .bus_num = 1,
288 .chip_select = 0,
289 .platform_data = NULL,
291 #endif
294 static void __init stmp378x_devb_init(void)
296 stmp3xxx_pinmux_init(NR_REAL_IRQS);
298 /* init stmp3xxx platform */
299 stmp3xxx_init();
301 stmp3xxx_dbguart.dev.platform_data = dbguart_pins_control;
302 stmp3xxx_appuart.dev.platform_data = appuart_pins;
303 stmp3xxx_mmc.dev.platform_data = &mmc_data;
304 stmp3xxx_gpmi.dev.platform_data = &gpmi_data;
305 stmp3xxx_spi1.dev.platform_data = &ssp1_pins;
306 stmp3xxx_spi2.dev.platform_data = &ssp2_pins;
307 stmp378x_i2c.dev.platform_data = &i2c_pins;
309 /* register spi devices */
310 spi_register_board_info(spi_board_info, ARRAY_SIZE(spi_board_info));
312 /* add board's devices */
313 platform_add_devices(devices, ARRAY_SIZE(devices));
315 /* add devices selected by command line ssp1= and ssp2= options */
316 stmp3xxx_ssp1_device_register();
317 stmp3xxx_ssp2_device_register();
320 MACHINE_START(STMP378X, "STMP378X")
321 .phys_io = 0x80000000,
322 .io_pg_offst = ((0xf0000000) >> 18) & 0xfffc,
323 .boot_params = 0x40000100,
324 .map_io = stmp378x_map_io,
325 .init_irq = stmp378x_init_irq,
326 .timer = &stmp3xxx_timer,
327 .init_machine = stmp378x_devb_init,
328 MACHINE_END