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