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