Merge current mainline tree into linux-omap tree
[pandora-kernel.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
26 #include <mach/hardware.h>
27 #include <asm/mach-types.h>
28 #include <asm/mach/arch.h>
29 #include <asm/mach/map.h>
30 #include <asm/mach/flash.h>
31
32 #include <mach/gpio.h>
33 #include <mach/board.h>
34 #include <mach/common.h>
35 #include <mach/hsmmc.h>
36 #include <mach/keypad.h>
37 #include <mach/gpmc.h>
38 #include <mach/nand.h>
39
40 #define GPMC_OFF_CONFIG1_0 0x60
41
42 static struct mtd_partition omap2evm_nand_partitions[] = {
43         {
44                 .name           = "X-Loader",
45                 .offset         = 0,
46                 .size           = 1 * (64 * 2048),
47                 .mask_flags     = MTD_WRITEABLE,        /* force read-only */
48         },
49         {
50                 .name           = "U-Boot",
51                 .offset         = MTDPART_OFS_APPEND,
52                 .size           = 3 * (64 * 2048),
53                 .mask_flags     = MTD_WRITEABLE,        /* force read-only */
54         },
55         {
56                 .name           = "U-Boot Environment",
57                 .offset         = MTDPART_OFS_APPEND,
58                 .size           = 1 * (64 * 2048),
59          },
60         {
61                 .name           = "Kernel",
62                 .offset         = MTDPART_OFS_APPEND,
63                 .size           = 16 * (64 * 2048),     /* 2MB */
64         },
65         {
66                 .name           = "Ramdisk",
67                 .offset         = MTDPART_OFS_APPEND,
68                 .size           = 32 * (64 * 2048),     /* 4MB */
69         },
70         {
71                 .name           = "Filesystem",
72                 .offset         = MTDPART_OFS_APPEND,
73                 .size           = MTDPART_SIZ_FULL,
74         }
75 };
76
77 static struct omap_nand_platform_data omap2evm_nand_data = {
78         .parts          = omap2evm_nand_partitions,
79         .nr_parts       = ARRAY_SIZE(omap2evm_nand_partitions),
80         .dma_channel    = -1,   /* disable DMA in OMAP NAND driver */
81 };
82
83 static struct resource omap2evm_nand_resource = {
84         .flags          = IORESOURCE_MEM,
85 };
86
87 static struct platform_device omap2evm_nand_device = {
88         .name           = "omap2-nand",
89         .id             = -1,
90         .dev            = {
91                 .platform_data  = &omap2evm_nand_data,
92         },
93         .num_resources  = 1,
94         .resource       = &omap2evm_nand_resource,
95 };
96
97 void __init omap2evm_flash_init(void)
98 {
99         void __iomem *gpmc_base_add, *gpmc_cs_base_add;
100         unsigned char cs = 0;
101
102         gpmc_base_add = (__force void __iomem *)OMAP243X_GPMC_VIRT;
103         while (cs < GPMC_CS_NUM) {
104                 int ret = 0;
105
106                 /* Each GPMC set for a single CS is at offset 0x30 */
107                 gpmc_cs_base_add = (gpmc_base_add + GPMC_OFF_CONFIG1_0 +
108                                     (cs * 0x30));
109
110                 /* xloader/Uboot would have programmed the NAND
111                  * base address for us This is a ugly hack. The proper
112                  * way of doing this is to pass the setup of u-boot up
113                  * to kernel using kernel params - something on the
114                  * lines of machineID. Check if Nand is
115                  * configured */
116                 ret = __raw_readl(gpmc_cs_base_add + GPMC_CS_CONFIG1);
117                 if ((ret & 0xC00) == (0x800)) {
118                         /* Found it!! */
119                         printk(KERN_INFO "NAND: Found NAND on CS %d \n", cs);
120                         break;
121                 }
122                 cs++;
123         }
124         if (cs >= GPMC_CS_NUM) {
125                 printk(KERN_INFO "MTD: Unable to find MTD configuration in "
126                                  "GPMC   - not registering.\n");
127                 return;
128         }
129
130         omap2evm_nand_data.cs                   = cs;
131         omap2evm_nand_data.gpmc_cs_baseaddr     = gpmc_cs_base_add;
132         omap2evm_nand_data.gpmc_baseaddr        = gpmc_base_add;
133
134         if (platform_device_register(&omap2evm_nand_device) < 0) {
135                 printk(KERN_ERR "Unable to register NAND device\n");
136                 return;
137         }
138 }
139
140 static struct resource omap2evm_smc911x_resources[] = {
141         [0] =   {
142                 .start  = OMAP2EVM_ETHR_START,
143                 .end    = (OMAP2EVM_ETHR_START + OMAP2EVM_ETHR_SIZE - 1),
144                 .flags  = IORESOURCE_MEM,
145         },
146         [1] =   {
147                 .start  = OMAP_GPIO_IRQ(OMAP2EVM_ETHR_GPIO_IRQ),
148                 .end    = OMAP_GPIO_IRQ(OMAP2EVM_ETHR_GPIO_IRQ),
149                 .flags  = IORESOURCE_IRQ,
150         },
151 };
152
153 static struct platform_device omap2evm_smc911x_device = {
154         .name       = "smc911x",
155         .id     = -1,
156         .num_resources  = ARRAY_SIZE(omap2evm_smc911x_resources),
157         .resource   = &omap2evm_smc911x_resources [0],
158 };
159
160 static inline void __init omap2evm_init_smc911x(void)
161 {
162         int gpio = OMAP2EVM_ETHR_GPIO_IRQ;
163         int ret;
164
165         ret = gpio_request(gpio, "smc911x IRQ");
166         if (ret < 0) {
167                 printk(KERN_ERR "Failed to request GPIO %d for smc911x IRQ\n",
168                                 gpio);
169                 return;
170         }
171         gpio_direction_input(gpio);
172
173 }
174
175 static struct platform_device omap2_evm_lcd_device = {
176         .name           = "omap2evm_lcd",
177         .id             = -1,
178 };
179
180 static struct omap_lcd_config omap2_evm_lcd_config __initdata = {
181         .ctrl_name      = "internal",
182 };
183
184 static int omap2evm_keymap[] = {
185         KEY(0, 0, KEY_LEFT),
186         KEY(0, 1, KEY_RIGHT),
187         KEY(0, 2, KEY_A),
188         KEY(0, 3, KEY_B),
189         KEY(1, 0, KEY_DOWN),
190         KEY(1, 1, KEY_UP),
191         KEY(1, 2, KEY_E),
192         KEY(1, 3, KEY_F),
193         KEY(2, 0, KEY_ENTER),
194         KEY(2, 1, KEY_I),
195         KEY(2, 2, KEY_J),
196         KEY(2, 3, KEY_K),
197         KEY(3, 0, KEY_M),
198         KEY(3, 1, KEY_N),
199         KEY(3, 2, KEY_O),
200         KEY(3, 3, KEY_P)
201 };
202
203 static struct twl4030_keypad_data omap2evm_kp_data = {
204         .rows           = 4,
205         .cols           = 4,
206         .keymap         = omap2evm_keymap,
207         .keymapsize     = ARRAY_SIZE(omap2evm_keymap),
208         .rep            = 1,
209         .irq            = TWL4030_MODIRQ_KEYPAD,
210 };
211
212 static void __init omap2_evm_init_irq(void)
213 {
214         omap2_init_common_hw(NULL);
215         omap_init_irq();
216         omap_gpio_init();
217         omap2evm_init_smc911x();
218 }
219
220 static struct omap_uart_config omap2_evm_uart_config __initdata = {
221         .enabled_uarts  = ((1 << 0) | (1 << 1) | (1 << 2)),
222 };
223
224 static struct omap_board_config_kernel omap2_evm_config[] __initdata = {
225         { OMAP_TAG_UART,        &omap2_evm_uart_config },
226         { OMAP_TAG_LCD,         &omap2_evm_lcd_config },
227 };
228
229 static struct twl4030_gpio_platform_data omap2evm_gpio_data = {
230         .gpio_base      = OMAP_MAX_GPIO_LINES,
231         .irq_base       = TWL4030_GPIO_IRQ_BASE,
232         .irq_end        = TWL4030_GPIO_IRQ_END,
233 };
234
235 static struct twl4030_usb_data omap2evm_usb_data = {
236         .usb_mode       = T2_USB_MODE_ULPI,
237 };
238
239 static struct twl4030_madc_platform_data omap2evm_madc_data = {
240         .irq_line       = 1,
241 };
242
243 static struct twl4030_platform_data omap2evm_twldata = {
244         .irq_base       = TWL4030_IRQ_BASE,
245         .irq_end        = TWL4030_IRQ_END,
246
247         /* platform_data for children goes here */
248         .keypad         = &omap2evm_kp_data,
249         .madc           = &omap2evm_madc_data,
250         .usb            = &omap2evm_usb_data,
251         .gpio           = &omap2evm_gpio_data,
252 };
253
254 static struct i2c_board_info __initdata omap2evm_i2c_boardinfo[] = {
255         {
256                 I2C_BOARD_INFO("twl4030", 0x48),
257                 .flags = I2C_CLIENT_WAKE,
258                 .irq = INT_24XX_SYS_NIRQ,
259                 .platform_data = &omap2evm_twldata,
260         },
261 };
262
263 static int __init omap2_evm_i2c_init(void)
264 {
265         omap_register_i2c_bus(1, 400, NULL, 0);
266         omap_register_i2c_bus(2, 2600, omap2evm_i2c_boardinfo,
267                         ARRAY_SIZE(omap2evm_i2c_boardinfo));
268         return 0;
269 }
270
271 static struct platform_device *omap2_evm_devices[] __initdata = {
272         &omap2_evm_lcd_device,
273         &omap2evm_smc911x_device,
274 };
275
276 static void __init omap2_evm_init(void)
277 {
278         omap2_evm_i2c_init();
279
280         platform_add_devices(omap2_evm_devices, ARRAY_SIZE(omap2_evm_devices));
281         omap_board_config = omap2_evm_config;
282         omap_board_config_size = ARRAY_SIZE(omap2_evm_config);
283         omap_serial_init();
284         hsmmc_init();
285         omap2evm_flash_init();
286 }
287
288 static void __init omap2_evm_map_io(void)
289 {
290         omap2_set_globals_243x();
291         omap2_map_common_io();
292 }
293
294 MACHINE_START(OMAP2EVM, "OMAP2EVM Board")
295         /* Maintainer:  Arun KS <arunks@mistralsolutions.com> */
296         .phys_io        = 0x48000000,
297         .io_pg_offst    = ((0xd8000000) >> 18) & 0xfffc,
298         .boot_params    = 0x80000100,
299         .map_io         = omap2_evm_map_io,
300         .init_irq       = omap2_evm_init_irq,
301         .init_machine   = omap2_evm_init,
302         .timer          = &omap_timer,
303 MACHINE_END