]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - arch/arm/mach-omap2/board-omap2evm.c
OMAP2EVM : Add touchscreen support
[linux-2.6-omap-h63xx.git] / arch / arm / mach-omap2 / board-omap2evm.c
1 /*
2  * linux/arch/arm/mach-omap2/board-omap2evm.c
3  *
4  * Copyright (C) 2008 Mistral Solutions Pvt Ltd
5  *
6  * Modified from mach-omap2/board-generic.c
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 as
10  * published by the Free Software Foundation.
11  */
12
13 #include <linux/kernel.h>
14 #include <linux/init.h>
15 #include <linux/platform_device.h>
16 #include <linux/delay.h>
17 #include <linux/err.h>
18 #include <linux/clk.h>
19 #include <linux/io.h>
20 #include <linux/input.h>
21 #include <linux/i2c/twl4030.h>
22 #include <linux/mtd/mtd.h>
23 #include <linux/mtd/partitions.h>
24 #include <linux/mtd/nand.h>
25 #include <linux/spi/spi.h>
26 #include <linux/spi/ads7846.h>
27
28 #include <mach/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 <mach/gpio.h>
35 #include <mach/board.h>
36 #include <mach/common.h>
37 #include <mach/hsmmc.h>
38 #include <mach/keypad.h>
39 #include <mach/gpmc.h>
40 #include <mach/nand.h>
41 #include <mach/mcspi.h>
42 #include <mach/mux.h>
43
44 #define GPMC_OFF_CONFIG1_0 0x60
45
46 static struct mtd_partition omap2evm_nand_partitions[] = {
47         {
48                 .name           = "X-Loader",
49                 .offset         = 0,
50                 .size           = 1 * (64 * 2048),
51                 .mask_flags     = MTD_WRITEABLE,        /* force read-only */
52         },
53         {
54                 .name           = "U-Boot",
55                 .offset         = MTDPART_OFS_APPEND,
56                 .size           = 3 * (64 * 2048),
57                 .mask_flags     = MTD_WRITEABLE,        /* force read-only */
58         },
59         {
60                 .name           = "U-Boot Environment",
61                 .offset         = MTDPART_OFS_APPEND,
62                 .size           = 1 * (64 * 2048),
63          },
64         {
65                 .name           = "Kernel",
66                 .offset         = MTDPART_OFS_APPEND,
67                 .size           = 16 * (64 * 2048),     /* 2MB */
68         },
69         {
70                 .name           = "Ramdisk",
71                 .offset         = MTDPART_OFS_APPEND,
72                 .size           = 32 * (64 * 2048),     /* 4MB */
73         },
74         {
75                 .name           = "Filesystem",
76                 .offset         = MTDPART_OFS_APPEND,
77                 .size           = MTDPART_SIZ_FULL,
78         }
79 };
80
81 static struct omap_nand_platform_data omap2evm_nand_data = {
82         .parts          = omap2evm_nand_partitions,
83         .nr_parts       = ARRAY_SIZE(omap2evm_nand_partitions),
84         .dma_channel    = -1,   /* disable DMA in OMAP NAND driver */
85 };
86
87 static struct resource omap2evm_nand_resource = {
88         .flags          = IORESOURCE_MEM,
89 };
90
91 static struct platform_device omap2evm_nand_device = {
92         .name           = "omap2-nand",
93         .id             = -1,
94         .dev            = {
95                 .platform_data  = &omap2evm_nand_data,
96         },
97         .num_resources  = 1,
98         .resource       = &omap2evm_nand_resource,
99 };
100
101 void __init omap2evm_flash_init(void)
102 {
103         void __iomem *gpmc_base_add, *gpmc_cs_base_add;
104         unsigned char cs = 0;
105
106         gpmc_base_add = (__force void __iomem *)OMAP243X_GPMC_VIRT;
107         while (cs < GPMC_CS_NUM) {
108                 int ret = 0;
109
110                 /* Each GPMC set for a single CS is at offset 0x30 */
111                 gpmc_cs_base_add = (gpmc_base_add + GPMC_OFF_CONFIG1_0 +
112                                     (cs * 0x30));
113
114                 /* xloader/Uboot would have programmed the NAND
115                  * base address for us This is a ugly hack. The proper
116                  * way of doing this is to pass the setup of u-boot up
117                  * to kernel using kernel params - something on the
118                  * lines of machineID. Check if Nand is
119                  * configured */
120                 ret = __raw_readl(gpmc_cs_base_add + GPMC_CS_CONFIG1);
121                 if ((ret & 0xC00) == (0x800)) {
122                         /* Found it!! */
123                         printk(KERN_INFO "NAND: Found NAND on CS %d \n", cs);
124                         break;
125                 }
126                 cs++;
127         }
128         if (cs >= GPMC_CS_NUM) {
129                 printk(KERN_INFO "MTD: Unable to find MTD configuration in "
130                                  "GPMC   - not registering.\n");
131                 return;
132         }
133
134         omap2evm_nand_data.cs                   = cs;
135         omap2evm_nand_data.gpmc_cs_baseaddr     = gpmc_cs_base_add;
136         omap2evm_nand_data.gpmc_baseaddr        = gpmc_base_add;
137
138         if (platform_device_register(&omap2evm_nand_device) < 0) {
139                 printk(KERN_ERR "Unable to register NAND device\n");
140                 return;
141         }
142 }
143
144 static struct resource omap2evm_smc911x_resources[] = {
145         [0] =   {
146                 .start  = OMAP2EVM_ETHR_START,
147                 .end    = (OMAP2EVM_ETHR_START + OMAP2EVM_ETHR_SIZE - 1),
148                 .flags  = IORESOURCE_MEM,
149         },
150         [1] =   {
151                 .start  = OMAP_GPIO_IRQ(OMAP2EVM_ETHR_GPIO_IRQ),
152                 .end    = OMAP_GPIO_IRQ(OMAP2EVM_ETHR_GPIO_IRQ),
153                 .flags  = IORESOURCE_IRQ,
154         },
155 };
156
157 static struct platform_device omap2evm_smc911x_device = {
158         .name       = "smc911x",
159         .id     = -1,
160         .num_resources  = ARRAY_SIZE(omap2evm_smc911x_resources),
161         .resource   = &omap2evm_smc911x_resources [0],
162 };
163
164 static inline void __init omap2evm_init_smc911x(void)
165 {
166         int gpio = OMAP2EVM_ETHR_GPIO_IRQ;
167         int ret;
168
169         ret = gpio_request(gpio, "smc911x IRQ");
170         if (ret < 0) {
171                 printk(KERN_ERR "Failed to request GPIO %d for smc911x IRQ\n",
172                                 gpio);
173                 return;
174         }
175         gpio_direction_input(gpio);
176
177 }
178
179 static struct platform_device omap2_evm_lcd_device = {
180         .name           = "omap2evm_lcd",
181         .id             = -1,
182 };
183
184 static struct omap_lcd_config omap2_evm_lcd_config __initdata = {
185         .ctrl_name      = "internal",
186 };
187
188 static void ads7846_dev_init(void)
189 {
190         int gpio = OMAP2_EVM_TS_GPIO;
191         int ret;
192
193         ret = gpio_request(gpio, "ads7846_pen_down");
194         if (ret < 0) {
195                 printk(KERN_ERR "Failed to request GPIO %d for ads7846 pen down IRQ\n",
196                                 gpio);
197                 return;
198         }
199
200         gpio_direction_input(gpio);
201
202         /*Setting the MUX */
203         omap_cfg_reg(Y18_2430_MCSPI1_CLK);
204         omap_cfg_reg(AD15_2430_MCSPI1_SIMO);
205         omap_cfg_reg(AE17_2430_MCSPI1_SOMI);
206         omap_cfg_reg(U1_2430_MCSPI1_CS0);
207
208         omap_cfg_reg(AF19_2430_GPIO_85);
209
210 }
211
212 static int ads7846_get_pendown_state(void)
213 {
214         return !omap_get_gpio_datain(OMAP2_EVM_TS_GPIO);
215 }
216
217 struct ads7846_platform_data ads7846_config = {
218         .x_max                  = 0x0fff,
219         .y_max                  = 0x0fff,
220         .x_plate_ohms           = 180,
221         .pressure_max           = 255,
222         .debounce_max           = 10,
223         .debounce_tol           = 3,
224         .debounce_rep           = 1,
225         .get_pendown_state      = ads7846_get_pendown_state,
226         .keep_vref_on           = 1,
227         .settle_delay_usecs     = 150,
228 };
229
230 static struct omap2_mcspi_device_config ads7846_mcspi_config = {
231         .turbo_mode     = 0,
232         .single_channel = 1,  /* 0: slave, 1: master */
233 };
234
235 struct spi_board_info omap2evm_spi_board_info[] = {
236         [0] = {
237                 .modalias               = "ads7846",
238                 .bus_num                = 1,
239                 .chip_select            = 0,
240                 .max_speed_hz           = 1500000,
241                 .controller_data        = &ads7846_mcspi_config,
242                 .irq                    = OMAP_GPIO_IRQ(OMAP2_EVM_TS_GPIO),
243                 .platform_data          = &ads7846_config,
244         },
245 };
246
247
248 static int omap2evm_keymap[] = {
249         KEY(0, 0, KEY_LEFT),
250         KEY(0, 1, KEY_RIGHT),
251         KEY(0, 2, KEY_A),
252         KEY(0, 3, KEY_B),
253         KEY(1, 0, KEY_DOWN),
254         KEY(1, 1, KEY_UP),
255         KEY(1, 2, KEY_E),
256         KEY(1, 3, KEY_F),
257         KEY(2, 0, KEY_ENTER),
258         KEY(2, 1, KEY_I),
259         KEY(2, 2, KEY_J),
260         KEY(2, 3, KEY_K),
261         KEY(3, 0, KEY_M),
262         KEY(3, 1, KEY_N),
263         KEY(3, 2, KEY_O),
264         KEY(3, 3, KEY_P)
265 };
266
267 static struct twl4030_keypad_data omap2evm_kp_data = {
268         .rows           = 4,
269         .cols           = 4,
270         .keymap         = omap2evm_keymap,
271         .keymapsize     = ARRAY_SIZE(omap2evm_keymap),
272         .rep            = 1,
273         .irq            = TWL4030_MODIRQ_KEYPAD,
274 };
275
276 static void __init omap2_evm_init_irq(void)
277 {
278         omap2_init_common_hw(NULL);
279         omap_init_irq();
280         omap_gpio_init();
281         omap2evm_init_smc911x();
282 }
283
284 static struct omap_uart_config omap2_evm_uart_config __initdata = {
285         .enabled_uarts  = ((1 << 0) | (1 << 1) | (1 << 2)),
286 };
287
288 static struct omap_board_config_kernel omap2_evm_config[] __initdata = {
289         { OMAP_TAG_UART,        &omap2_evm_uart_config },
290         { OMAP_TAG_LCD,         &omap2_evm_lcd_config },
291 };
292
293 static struct twl4030_gpio_platform_data omap2evm_gpio_data = {
294         .gpio_base      = OMAP_MAX_GPIO_LINES,
295         .irq_base       = TWL4030_GPIO_IRQ_BASE,
296         .irq_end        = TWL4030_GPIO_IRQ_END,
297 };
298
299 static struct twl4030_usb_data omap2evm_usb_data = {
300         .usb_mode       = T2_USB_MODE_ULPI,
301 };
302
303 static struct twl4030_madc_platform_data omap2evm_madc_data = {
304         .irq_line       = 1,
305 };
306
307 static struct twl4030_platform_data omap2evm_twldata = {
308         .irq_base       = TWL4030_IRQ_BASE,
309         .irq_end        = TWL4030_IRQ_END,
310
311         /* platform_data for children goes here */
312         .keypad         = &omap2evm_kp_data,
313         .madc           = &omap2evm_madc_data,
314         .usb            = &omap2evm_usb_data,
315         .gpio           = &omap2evm_gpio_data,
316 };
317
318 static struct i2c_board_info __initdata omap2evm_i2c_boardinfo[] = {
319         {
320                 I2C_BOARD_INFO("twl4030", 0x48),
321                 .flags = I2C_CLIENT_WAKE,
322                 .irq = INT_24XX_SYS_NIRQ,
323                 .platform_data = &omap2evm_twldata,
324         },
325 };
326
327 static int __init omap2_evm_i2c_init(void)
328 {
329         omap_register_i2c_bus(1, 400, NULL, 0);
330         omap_register_i2c_bus(2, 2600, omap2evm_i2c_boardinfo,
331                         ARRAY_SIZE(omap2evm_i2c_boardinfo));
332         return 0;
333 }
334
335 static struct platform_device *omap2_evm_devices[] __initdata = {
336         &omap2_evm_lcd_device,
337         &omap2evm_smc911x_device,
338 };
339
340 static void __init omap2_evm_init(void)
341 {
342         omap2_evm_i2c_init();
343
344         platform_add_devices(omap2_evm_devices, ARRAY_SIZE(omap2_evm_devices));
345         omap_board_config = omap2_evm_config;
346         omap_board_config_size = ARRAY_SIZE(omap2_evm_config);
347         spi_register_board_info(omap2evm_spi_board_info,
348                                 ARRAY_SIZE(omap2evm_spi_board_info));
349         omap_serial_init();
350         hsmmc_init();
351         omap2evm_flash_init();
352         ads7846_dev_init();
353 }
354
355 static void __init omap2_evm_map_io(void)
356 {
357         omap2_set_globals_243x();
358         omap2_map_common_io();
359 }
360
361 MACHINE_START(OMAP2EVM, "OMAP2EVM Board")
362         /* Maintainer:  Arun KS <arunks@mistralsolutions.com> */
363         .phys_io        = 0x48000000,
364         .io_pg_offst    = ((0xd8000000) >> 18) & 0xfffc,
365         .boot_params    = 0x80000100,
366         .map_io         = omap2_evm_map_io,
367         .init_irq       = omap2_evm_init_irq,
368         .init_machine   = omap2_evm_init,
369         .timer          = &omap_timer,
370 MACHINE_END