]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - arch/arm/mach-omap2/board-2430sdp.c
899e6e3402dd2051484d4f6aef7afaf57b7a80ad
[linux-2.6-omap-h63xx.git] / arch / arm / mach-omap2 / board-2430sdp.c
1 /*
2  * linux/arch/arm/mach-omap2/board-2430sdp.c
3  *
4  * Copyright (C) 2006 Texas Instruments
5  *
6  * Modified from mach-omap2/board-generic.c
7  *
8  * Initial Code : Based on a patch from Komal Shah and Richard Woodruff
9  * Updated the Code for 2430 SDP : Syed Mohammed Khasim
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License version 2 as
13  * published by the Free Software Foundation.
14  */
15
16 #include <linux/kernel.h>
17 #include <linux/init.h>
18 #include <linux/platform_device.h>
19 #include <linux/mtd/mtd.h>
20 #include <linux/mtd/partitions.h>
21 #include <linux/delay.h>
22 #include <linux/input.h>
23 #include <linux/i2c/twl4030.h>
24 #include <linux/err.h>
25 #include <linux/clk.h>
26 #include <linux/io.h>
27 #include <linux/spi/spi.h>
28 #include <linux/spi/ads7846.h>
29
30 #include <mach/hardware.h>
31 #include <asm/mach-types.h>
32 #include <asm/mach/arch.h>
33 #include <asm/mach/map.h>
34 #include <asm/mach/flash.h>
35
36 #include <mach/gpio.h>
37 #include <mach/mux.h>
38 #include <mach/board.h>
39 #include <mach/usb.h>
40 #include <mach/common.h>
41 #include <mach/gpmc.h>
42 #include <mach/mcspi.h>
43
44
45 #include "mmc-twl4030.h"
46
47 #define SDP2430_CS0_BASE        0x04000000
48 #define SDP2430_FLASH_CS        0
49 #define SDP2430_SMC91X_CS       5
50 #define SDP2430_ETHR_GPIO_IRQ           149
51
52 /* GPIO used for TSC2046 (touchscreen)
53  *
54  * Also note that the tsc2046 is the same silicon as the ads7846, so
55  * that driver is used for the touchscreen. */
56 #define TS_GPIO                 24
57
58 #define TWL4030_MSECURE_GPIO    118
59 #define SECONDARY_LCD_GPIO      147
60
61 extern void sdp2430_flash_init(void);
62
63 static struct mtd_partition sdp2430_partitions[] = {
64         /* bootloader (U-Boot, etc) in first sector */
65         {
66                 .name           = "bootloader",
67                 .offset         = 0,
68                 .size           = SZ_256K,
69                 .mask_flags     = MTD_WRITEABLE,        /* force read-only */
70          },
71         /* bootloader params in the next sector */
72         {
73                 .name           = "params",
74                 .offset         = MTDPART_OFS_APPEND,
75                 .size           = SZ_128K,
76                 .mask_flags     = 0,
77          },
78         /* kernel */
79         {
80                 .name           = "kernel",
81                 .offset         = MTDPART_OFS_APPEND,
82                 .size           = SZ_2M,
83                 .mask_flags     = 0
84         },
85         /* file system */
86         {
87                 .name           = "filesystem",
88                 .offset         = MTDPART_OFS_APPEND,
89                 .size           = MTDPART_SIZ_FULL,
90                 .mask_flags     = 0
91         }
92 };
93
94 static struct flash_platform_data sdp2430_flash_data = {
95         .map_name       = "cfi_probe",
96         .width          = 2,
97         .parts          = sdp2430_partitions,
98         .nr_parts       = ARRAY_SIZE(sdp2430_partitions),
99 };
100
101 static struct resource sdp2430_flash_resource = {
102         .start          = SDP2430_CS0_BASE,
103         .end            = SDP2430_CS0_BASE + SZ_64M - 1,
104         .flags          = IORESOURCE_MEM,
105 };
106
107 static struct platform_device sdp2430_flash_device = {
108         .name           = "omapflash",
109         .id             = 0,
110         .dev = {
111                 .platform_data  = &sdp2430_flash_data,
112         },
113         .num_resources  = 1,
114         .resource       = &sdp2430_flash_resource,
115 };
116
117 static struct resource sdp2430_smc91x_resources[] = {
118         [0] = {
119                 .start  = SDP2430_CS0_BASE,
120                 .end    = SDP2430_CS0_BASE + SZ_64M - 1,
121                 .flags  = IORESOURCE_MEM,
122         },
123         [1] = {
124                 .start  = OMAP_GPIO_IRQ(SDP2430_ETHR_GPIO_IRQ),
125                 .end    = OMAP_GPIO_IRQ(SDP2430_ETHR_GPIO_IRQ),
126                 .flags  = IORESOURCE_IRQ | IORESOURCE_IRQ_LOWLEVEL,
127         },
128 };
129
130 static struct platform_device sdp2430_lcd_device = {
131         .name           = "sdp2430_lcd",
132         .id             = -1,
133 };
134
135 static struct platform_device sdp2430_smc91x_device = {
136         .name           = "smc91x",
137         .id             = -1,
138         .num_resources  = ARRAY_SIZE(sdp2430_smc91x_resources),
139         .resource       = sdp2430_smc91x_resources,
140 };
141
142 /*
143  * Key mapping for 2430 SDP board
144  */
145
146 static int sdp2430_keymap[] = {
147         KEY(0, 0, KEY_LEFT),
148         KEY(0, 1, KEY_RIGHT),
149         KEY(0, 2, KEY_A),
150         KEY(0, 3, KEY_B),
151         KEY(0, 4, KEY_C),
152         KEY(1, 0, KEY_DOWN),
153         KEY(1, 1, KEY_UP),
154         KEY(1, 2, KEY_E),
155         KEY(1, 3, KEY_F),
156         KEY(1, 4, KEY_G),
157         KEY(2, 0, KEY_ENTER),
158         KEY(2, 1, KEY_I),
159         KEY(2, 2, KEY_J),
160         KEY(2, 3, KEY_K),
161         KEY(2, 4, KEY_3),
162         KEY(3, 0, KEY_M),
163         KEY(3, 1, KEY_N),
164         KEY(3, 2, KEY_O),
165         KEY(3, 3, KEY_P),
166         KEY(3, 4, KEY_Q),
167         KEY(4, 0, KEY_R),
168         KEY(4, 1, KEY_4),
169         KEY(4, 2, KEY_T),
170         KEY(4, 3, KEY_U),
171         KEY(4, 4, KEY_D),
172         KEY(5, 0, KEY_V),
173         KEY(5, 1, KEY_W),
174         KEY(5, 2, KEY_L),
175         KEY(5, 3, KEY_S),
176         KEY(5, 4, KEY_H),
177         0
178 };
179
180 static struct twl4030_keypad_data sdp2430_kp_data = {
181         .rows           = 5,
182         .cols           = 6,
183         .keymap         = sdp2430_keymap,
184         .keymapsize     = ARRAY_SIZE(sdp2430_keymap),
185         .rep            = 1,
186 };
187
188 static int __init msecure_init(void)
189 {
190         int ret = 0;
191
192 #ifdef CONFIG_RTC_DRV_TWL4030
193         ret = gpio_request(TWL4030_MSECURE_GPIO, "msecure");
194         if (ret < 0) {
195                 printk(KERN_ERR "msecure_init: can't reserve GPIO:%d !\n",
196                         TWL4030_MSECURE_GPIO);
197                 goto out;
198         }
199         /*
200          * TWL4030 will be in secure mode if msecure line from OMAP is low.
201          * Make msecure line high in order to change the TWL4030 RTC time
202          * and calender registers.
203          */
204         gpio_direction_output(TWL4030_MSECURE_GPIO, 1);
205 out:
206 #endif
207
208         return ret;
209 }
210
211 static struct platform_device *sdp2430_devices[] __initdata = {
212         &sdp2430_smc91x_device,
213         &sdp2430_flash_device,
214         &sdp2430_lcd_device,
215 };
216
217 static void ads7846_dev_init(void)
218 {
219         if (gpio_request(TS_GPIO, "ads7846 irq") < 0)
220                 printk(KERN_ERR "can't get ads746 pen down GPIO\n");
221
222         gpio_direction_input(TS_GPIO);
223
224         omap_set_gpio_debounce(TS_GPIO, 1);
225         omap_set_gpio_debounce_time(TS_GPIO, 0xa);
226 }
227
228 static int ads7846_get_pendown_state(void)
229 {
230         return !gpio_get_value(TS_GPIO);
231 }
232
233 static struct ads7846_platform_data tsc2046_config __initdata = {
234         .get_pendown_state = ads7846_get_pendown_state,
235         .keep_vref_on      = 1,
236 };
237
238 static struct omap2_mcspi_device_config tsc2046_mcspi_config = {
239         .turbo_mode     = 0,
240         .single_channel = 0,  /* 0: slave, 1: master */
241 };
242
243 static struct omap_lcd_config sdp2430_lcd_config __initdata = {
244         .ctrl_name      = "internal",
245 };
246
247 static struct spi_board_info sdp2430_spi_board_info[] __initdata = {
248         [0] = {
249                 /*
250                  * TSC2046 operates at a max freqency of 2MHz, so
251                  * operate slightly below at 1.5MHz
252                  */
253                 .modalias        = "ads7846",
254                 .bus_num         = 1,
255                 .chip_select     = 0,
256                 .max_speed_hz    = 1500000,
257                 .controller_data = &tsc2046_mcspi_config,
258                 .irq             = OMAP_GPIO_IRQ(TS_GPIO),
259                 .platform_data   = &tsc2046_config,
260         },
261 };
262
263 static inline void __init sdp2430_init_smc91x(void)
264 {
265         int eth_cs;
266         unsigned long cs_mem_base;
267         unsigned int rate;
268         struct clk *gpmc_fck;
269
270         eth_cs = SDP2430_SMC91X_CS;
271
272         gpmc_fck = clk_get(NULL, "gpmc_fck");   /* Always on ENABLE_ON_INIT */
273         if (IS_ERR(gpmc_fck)) {
274                 WARN_ON(1);
275                 return;
276         }
277
278         clk_enable(gpmc_fck);
279         rate = clk_get_rate(gpmc_fck);
280
281         /* Make sure CS1 timings are correct, for 2430 always muxed */
282         gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG1, 0x00011200);
283
284         if (rate >= 160000000) {
285                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG2, 0x001f1f01);
286                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG3, 0x00080803);
287                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG4, 0x1c0b1c0a);
288                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG5, 0x041f1F1F);
289                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG6, 0x000004C4);
290         } else if (rate >= 130000000) {
291                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG2, 0x001f1f00);
292                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG3, 0x00080802);
293                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG4, 0x1C091C09);
294                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG5, 0x041f1F1F);
295                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG6, 0x000004C4);
296         } else { /* rate = 100000000 */
297                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG2, 0x001f1f00);
298                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG3, 0x00080802);
299                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG4, 0x1C091C09);
300                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG5, 0x031A1F1F);
301                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG6, 0x000003C2);
302         }
303
304         if (gpmc_cs_request(eth_cs, SZ_16M, &cs_mem_base) < 0) {
305                 printk(KERN_ERR "Failed to request GPMC mem for smc91x\n");
306                 goto out;
307         }
308
309         sdp2430_smc91x_resources[0].start = cs_mem_base + 0x300;
310         sdp2430_smc91x_resources[0].end = cs_mem_base + 0x30f;
311         udelay(100);
312
313         if (gpio_request(SDP2430_ETHR_GPIO_IRQ, "SMC91x irq") < 0) {
314                 printk(KERN_ERR "Failed to request GPIO%d for smc91x IRQ\n",
315                         SDP2430_ETHR_GPIO_IRQ);
316                 gpmc_cs_free(eth_cs);
317                 goto out;
318         }
319         gpio_direction_input(SDP2430_ETHR_GPIO_IRQ);
320
321 out:
322         clk_disable(gpmc_fck);
323         clk_put(gpmc_fck);
324 }
325
326 static void __init omap_2430sdp_init_irq(void)
327 {
328         omap2_init_common_hw(NULL);
329         omap_init_irq();
330         omap_gpio_init();
331         sdp2430_init_smc91x();
332 }
333
334 static struct omap_uart_config sdp2430_uart_config __initdata = {
335         .enabled_uarts = ((1 << 0) | (1 << 1) | (1 << 2)),
336 };
337
338 static
339 struct omap_serial_console_config sdp2430_serial_console_config __initdata = {
340         .console_uart = 1,
341         .console_speed = 115200,
342 };
343
344 static struct omap_board_config_kernel sdp2430_config[] __initdata = {
345         {OMAP_TAG_UART, &sdp2430_uart_config},
346         {OMAP_TAG_LCD, &sdp2430_lcd_config},
347         {OMAP_TAG_SERIAL_CONSOLE, &sdp2430_serial_console_config},
348 };
349
350
351 static struct twl4030_gpio_platform_data sdp2430_gpio_data = {
352         .gpio_base      = OMAP_MAX_GPIO_LINES,
353         .irq_base       = TWL4030_GPIO_IRQ_BASE,
354         .irq_end        = TWL4030_GPIO_IRQ_END,
355 };
356
357 static struct twl4030_usb_data sdp2430_usb_data = {
358         .usb_mode       = T2_USB_MODE_ULPI,
359 };
360
361 static struct twl4030_madc_platform_data sdp2430_madc_data = {
362         .irq_line       = 1,
363 };
364
365 static struct twl4030_platform_data sdp2430_twldata = {
366         .irq_base       = TWL4030_IRQ_BASE,
367         .irq_end        = TWL4030_IRQ_END,
368
369         /* platform_data for children goes here */
370         .gpio           = &sdp2430_gpio_data,
371         .madc           = &sdp2430_madc_data,
372         .keypad         = &sdp2430_kp_data,
373         .usb            = &sdp2430_usb_data,
374 };
375
376 static struct i2c_board_info __initdata sdp2430_i2c_boardinfo[] = {
377         {
378                 I2C_BOARD_INFO("twl4030", 0x48),
379                 .flags = I2C_CLIENT_WAKE,
380                 .irq = INT_24XX_SYS_NIRQ,
381                 .platform_data = &sdp2430_twldata,
382         },
383 };
384
385 static int __init omap2430_i2c_init(void)
386 {
387         omap_register_i2c_bus(1, 400, NULL, 0);
388         omap_register_i2c_bus(2, 2600, sdp2430_i2c_boardinfo,
389                         ARRAY_SIZE(sdp2430_i2c_boardinfo));
390         return 0;
391 }
392
393 static struct twl4030_hsmmc_info mmc[] __initdata = {
394         {
395                 .mmc            = 1,
396                 .wires          = 4,
397                 .gpio_cd        = -EINVAL,
398                 .gpio_wp        = -EINVAL,
399                 .ext_clock      = 1,
400         },
401         {}      /* Terminator */
402 };
403
404 static void __init omap_2430sdp_init(void)
405 {
406         omap2430_i2c_init();
407
408         platform_add_devices(sdp2430_devices, ARRAY_SIZE(sdp2430_devices));
409         omap_board_config = sdp2430_config;
410         omap_board_config_size = ARRAY_SIZE(sdp2430_config);
411         omap_serial_init();
412
413         msecure_init();
414
415         sdp2430_flash_init();
416         usb_musb_init();
417
418         spi_register_board_info(sdp2430_spi_board_info,
419                                 ARRAY_SIZE(sdp2430_spi_board_info));
420         ads7846_dev_init();
421         twl4030_mmc_init(mmc);
422
423         /* turn off secondary LCD backlight */
424         gpio_direction_output(SECONDARY_LCD_GPIO, 0);
425 }
426
427 static void __init omap_2430sdp_map_io(void)
428 {
429         omap2_set_globals_243x();
430         omap2_map_common_io();
431 }
432
433 MACHINE_START(OMAP_2430SDP, "OMAP2430 sdp2430 board")
434         /* Maintainer: Syed Khasim - Texas Instruments Inc */
435         .phys_io        = 0x48000000,
436         .io_pg_offst    = ((0xd8000000) >> 18) & 0xfffc,
437         .boot_params    = 0x80000100,
438         .map_io         = omap_2430sdp_map_io,
439         .init_irq       = omap_2430sdp_init_irq,
440         .init_machine   = omap_2430sdp_init,
441         .timer          = &omap_timer,
442 MACHINE_END