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