Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input
[pandora-kernel.git] / arch / arm / mach-omap2 / board-omap3evm.c
1 /*
2  * linux/arch/arm/mach-omap2/board-omap3evm.c
3  *
4  * Copyright (C) 2008 Texas Instruments
5  *
6  * Modified from mach-omap2/board-3430sdp.c
7  *
8  * Initial code: Syed Mohammed Khasim
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License version 2 as
12  * published by the Free Software Foundation.
13  */
14
15 #include <linux/kernel.h>
16 #include <linux/init.h>
17 #include <linux/platform_device.h>
18 #include <linux/delay.h>
19 #include <linux/err.h>
20 #include <linux/clk.h>
21 #include <linux/gpio.h>
22 #include <linux/input.h>
23 #include <linux/leds.h>
24
25 #include <linux/spi/spi.h>
26 #include <linux/spi/ads7846.h>
27 #include <linux/i2c/twl4030.h>
28
29 #include <mach/hardware.h>
30 #include <asm/mach-types.h>
31 #include <asm/mach/arch.h>
32 #include <asm/mach/map.h>
33
34 #include <mach/board.h>
35 #include <mach/mux.h>
36 #include <mach/usb.h>
37 #include <mach/common.h>
38 #include <mach/mcspi.h>
39 #include <mach/keypad.h>
40
41 #include "sdram-micron-mt46h32m32lf-6.h"
42 #include "mmc-twl4030.h"
43
44 #define OMAP3_EVM_TS_GPIO       175
45
46 #define OMAP3EVM_ETHR_START     0x2c000000
47 #define OMAP3EVM_ETHR_SIZE      1024
48 #define OMAP3EVM_ETHR_GPIO_IRQ  176
49 #define OMAP3EVM_SMC911X_CS     5
50
51 static struct resource omap3evm_smc911x_resources[] = {
52         [0] =   {
53                 .start  = OMAP3EVM_ETHR_START,
54                 .end    = (OMAP3EVM_ETHR_START + OMAP3EVM_ETHR_SIZE - 1),
55                 .flags  = IORESOURCE_MEM,
56         },
57         [1] =   {
58                 .start  = OMAP_GPIO_IRQ(OMAP3EVM_ETHR_GPIO_IRQ),
59                 .end    = OMAP_GPIO_IRQ(OMAP3EVM_ETHR_GPIO_IRQ),
60                 .flags  = IORESOURCE_IRQ,
61         },
62 };
63
64 static struct platform_device omap3evm_smc911x_device = {
65         .name           = "smc911x",
66         .id             = -1,
67         .num_resources  = ARRAY_SIZE(omap3evm_smc911x_resources),
68         .resource       = &omap3evm_smc911x_resources[0],
69 };
70
71 static inline void __init omap3evm_init_smc911x(void)
72 {
73         int eth_cs;
74         struct clk *l3ck;
75         unsigned int rate;
76
77         eth_cs = OMAP3EVM_SMC911X_CS;
78
79         l3ck = clk_get(NULL, "l3_ck");
80         if (IS_ERR(l3ck))
81                 rate = 100000000;
82         else
83                 rate = clk_get_rate(l3ck);
84
85         if (gpio_request(OMAP3EVM_ETHR_GPIO_IRQ, "SMC911x irq") < 0) {
86                 printk(KERN_ERR "Failed to request GPIO%d for smc911x IRQ\n",
87                         OMAP3EVM_ETHR_GPIO_IRQ);
88                 return;
89         }
90
91         gpio_direction_input(OMAP3EVM_ETHR_GPIO_IRQ);
92 }
93
94 static struct omap_uart_config omap3_evm_uart_config __initdata = {
95         .enabled_uarts  = ((1 << 0) | (1 << 1) | (1 << 2)),
96 };
97
98 static struct twl4030_hsmmc_info mmc[] = {
99         {
100                 .mmc            = 1,
101                 .wires          = 4,
102                 .gpio_cd        = -EINVAL,
103                 .gpio_wp        = 63,
104         },
105         {}      /* Terminator */
106 };
107
108 static struct gpio_led gpio_leds[] = {
109         {
110                 .name                   = "omap3evm::ledb",
111                 /* normally not visible (board underside) */
112                 .default_trigger        = "default-on",
113                 .gpio                   = -EINVAL,      /* gets replaced */
114                 .active_low             = true,
115         },
116 };
117
118 static struct gpio_led_platform_data gpio_led_info = {
119         .leds           = gpio_leds,
120         .num_leds       = ARRAY_SIZE(gpio_leds),
121 };
122
123 static struct platform_device leds_gpio = {
124         .name   = "leds-gpio",
125         .id     = -1,
126         .dev    = {
127                 .platform_data  = &gpio_led_info,
128         },
129 };
130
131
132 static int omap3evm_twl_gpio_setup(struct device *dev,
133                 unsigned gpio, unsigned ngpio)
134 {
135         /* gpio + 0 is "mmc0_cd" (input/IRQ) */
136         omap_cfg_reg(L8_34XX_GPIO63);
137         mmc[0].gpio_cd = gpio + 0;
138         twl4030_mmc_init(mmc);
139
140         /*
141          * Most GPIOs are for USB OTG.  Some are mostly sent to
142          * the P2 connector; notably LEDA for the LCD backlight.
143          */
144
145         /* TWL4030_GPIO_MAX + 1 == ledB (out, active low LED) */
146         gpio_leds[2].gpio = gpio + TWL4030_GPIO_MAX + 1;
147
148         platform_device_register(&leds_gpio);
149
150         return 0;
151 }
152
153 static struct twl4030_gpio_platform_data omap3evm_gpio_data = {
154         .gpio_base      = OMAP_MAX_GPIO_LINES,
155         .irq_base       = TWL4030_GPIO_IRQ_BASE,
156         .irq_end        = TWL4030_GPIO_IRQ_END,
157         .use_leds       = true,
158         .setup          = omap3evm_twl_gpio_setup,
159 };
160
161 static struct twl4030_usb_data omap3evm_usb_data = {
162         .usb_mode       = T2_USB_MODE_ULPI,
163 };
164
165 static int omap3evm_keymap[] = {
166         KEY(0, 0, KEY_LEFT),
167         KEY(0, 1, KEY_RIGHT),
168         KEY(0, 2, KEY_A),
169         KEY(0, 3, KEY_B),
170         KEY(1, 0, KEY_DOWN),
171         KEY(1, 1, KEY_UP),
172         KEY(1, 2, KEY_E),
173         KEY(1, 3, KEY_F),
174         KEY(2, 0, KEY_ENTER),
175         KEY(2, 1, KEY_I),
176         KEY(2, 2, KEY_J),
177         KEY(2, 3, KEY_K),
178         KEY(3, 0, KEY_M),
179         KEY(3, 1, KEY_N),
180         KEY(3, 2, KEY_O),
181         KEY(3, 3, KEY_P)
182 };
183
184 static struct twl4030_keypad_data omap3evm_kp_data = {
185         .rows           = 4,
186         .cols           = 4,
187         .keymap         = omap3evm_keymap,
188         .keymapsize     = ARRAY_SIZE(omap3evm_keymap),
189         .rep            = 1,
190 };
191
192 static struct twl4030_madc_platform_data omap3evm_madc_data = {
193         .irq_line       = 1,
194 };
195
196 static struct twl4030_platform_data omap3evm_twldata = {
197         .irq_base       = TWL4030_IRQ_BASE,
198         .irq_end        = TWL4030_IRQ_END,
199
200         /* platform_data for children goes here */
201         .keypad         = &omap3evm_kp_data,
202         .madc           = &omap3evm_madc_data,
203         .usb            = &omap3evm_usb_data,
204         .gpio           = &omap3evm_gpio_data,
205 };
206
207 static struct i2c_board_info __initdata omap3evm_i2c_boardinfo[] = {
208         {
209                 I2C_BOARD_INFO("twl4030", 0x48),
210                 .flags = I2C_CLIENT_WAKE,
211                 .irq = INT_34XX_SYS_NIRQ,
212                 .platform_data = &omap3evm_twldata,
213         },
214 };
215
216 static int __init omap3_evm_i2c_init(void)
217 {
218         omap_register_i2c_bus(1, 2600, omap3evm_i2c_boardinfo,
219                         ARRAY_SIZE(omap3evm_i2c_boardinfo));
220         omap_register_i2c_bus(2, 400, NULL, 0);
221         omap_register_i2c_bus(3, 400, NULL, 0);
222         return 0;
223 }
224
225 static struct platform_device omap3_evm_lcd_device = {
226         .name           = "omap3evm_lcd",
227         .id             = -1,
228 };
229
230 static struct omap_lcd_config omap3_evm_lcd_config __initdata = {
231         .ctrl_name      = "internal",
232 };
233
234 static void ads7846_dev_init(void)
235 {
236         if (gpio_request(OMAP3_EVM_TS_GPIO, "ADS7846 pendown") < 0)
237                 printk(KERN_ERR "can't get ads7846 pen down GPIO\n");
238
239         gpio_direction_input(OMAP3_EVM_TS_GPIO);
240
241         omap_set_gpio_debounce(OMAP3_EVM_TS_GPIO, 1);
242         omap_set_gpio_debounce_time(OMAP3_EVM_TS_GPIO, 0xa);
243 }
244
245 static int ads7846_get_pendown_state(void)
246 {
247         return !gpio_get_value(OMAP3_EVM_TS_GPIO);
248 }
249
250 struct ads7846_platform_data ads7846_config = {
251         .x_max                  = 0x0fff,
252         .y_max                  = 0x0fff,
253         .x_plate_ohms           = 180,
254         .pressure_max           = 255,
255         .debounce_max           = 10,
256         .debounce_tol           = 3,
257         .debounce_rep           = 1,
258         .get_pendown_state      = ads7846_get_pendown_state,
259         .keep_vref_on           = 1,
260         .settle_delay_usecs     = 150,
261 };
262
263 static struct omap2_mcspi_device_config ads7846_mcspi_config = {
264         .turbo_mode     = 0,
265         .single_channel = 1,    /* 0: slave, 1: master */
266 };
267
268 struct spi_board_info omap3evm_spi_board_info[] = {
269         [0] = {
270                 .modalias               = "ads7846",
271                 .bus_num                = 1,
272                 .chip_select            = 0,
273                 .max_speed_hz           = 1500000,
274                 .controller_data        = &ads7846_mcspi_config,
275                 .irq                    = OMAP_GPIO_IRQ(OMAP3_EVM_TS_GPIO),
276                 .platform_data          = &ads7846_config,
277         },
278 };
279
280 static void __init omap3_evm_init_irq(void)
281 {
282         omap2_init_common_hw(mt46h32m32lf6_sdrc_params);
283         omap_init_irq();
284         omap_gpio_init();
285         omap3evm_init_smc911x();
286 }
287
288 static struct omap_board_config_kernel omap3_evm_config[] __initdata = {
289         { OMAP_TAG_UART,        &omap3_evm_uart_config },
290         { OMAP_TAG_LCD,         &omap3_evm_lcd_config },
291 };
292
293 static struct platform_device *omap3_evm_devices[] __initdata = {
294         &omap3_evm_lcd_device,
295         &omap3evm_smc911x_device,
296 };
297
298 static void __init omap3_evm_init(void)
299 {
300         omap3_evm_i2c_init();
301
302         platform_add_devices(omap3_evm_devices, ARRAY_SIZE(omap3_evm_devices));
303         omap_board_config = omap3_evm_config;
304         omap_board_config_size = ARRAY_SIZE(omap3_evm_config);
305
306         spi_register_board_info(omap3evm_spi_board_info,
307                                 ARRAY_SIZE(omap3evm_spi_board_info));
308
309         omap_serial_init();
310         usb_musb_init();
311         ads7846_dev_init();
312 }
313
314 static void __init omap3_evm_map_io(void)
315 {
316         omap2_set_globals_343x();
317         omap2_map_common_io();
318 }
319
320 MACHINE_START(OMAP3EVM, "OMAP3 EVM")
321         /* Maintainer: Syed Mohammed Khasim - Texas Instruments */
322         .phys_io        = 0x48000000,
323         .io_pg_offst    = ((0xd8000000) >> 18) & 0xfffc,
324         .boot_params    = 0x80000100,
325         .map_io         = omap3_evm_map_io,
326         .init_irq       = omap3_evm_init_irq,
327         .init_machine   = omap3_evm_init,
328         .timer          = &omap_timer,
329 MACHINE_END