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