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