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