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