Merge git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6
[pandora-kernel.git] / arch / arm / mach-omap2 / board-3430sdp.c
1 /*
2  * linux/arch/arm/mach-omap2/board-3430sdp.c
3  *
4  * Copyright (C) 2007 Texas Instruments
5  *
6  * Modified from mach-omap2/board-generic.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/input.h>
20 #include <linux/spi/spi.h>
21 #include <linux/spi/ads7846.h>
22 #include <linux/i2c/twl4030.h>
23 #include <linux/regulator/machine.h>
24 #include <linux/io.h>
25 #include <linux/gpio.h>
26
27 #include <mach/hardware.h>
28 #include <asm/mach-types.h>
29 #include <asm/mach/arch.h>
30 #include <asm/mach/map.h>
31
32 #include <mach/mcspi.h>
33 #include <mach/mux.h>
34 #include <mach/board.h>
35 #include <mach/usb.h>
36 #include <mach/common.h>
37 #include <mach/dma.h>
38 #include <mach/gpmc.h>
39
40 #include <mach/control.h>
41 #include <mach/keypad.h>
42
43 #include "mmc-twl4030.h"
44
45 #define CONFIG_DISABLE_HFCLK 1
46
47 #define SDP3430_ETHR_GPIO_IRQ_SDPV1     29
48 #define SDP3430_ETHR_GPIO_IRQ_SDPV2     6
49 #define SDP3430_SMC91X_CS               3
50
51 #define SDP3430_TS_GPIO_IRQ_SDPV1       3
52 #define SDP3430_TS_GPIO_IRQ_SDPV2       2
53
54 #define ENABLE_VAUX3_DEDICATED  0x03
55 #define ENABLE_VAUX3_DEV_GRP    0x20
56
57 #define TWL4030_MSECURE_GPIO 22
58
59 static struct resource sdp3430_smc91x_resources[] = {
60         [0] = {
61                 .flags  = IORESOURCE_MEM,
62         },
63         [1] = {
64                 .start  = 0,
65                 .end    = 0,
66                 .flags  = IORESOURCE_IRQ | IORESOURCE_IRQ_LOWLEVEL,
67         },
68 };
69
70 static struct platform_device sdp3430_smc91x_device = {
71         .name           = "smc91x",
72         .id             = -1,
73         .num_resources  = ARRAY_SIZE(sdp3430_smc91x_resources),
74         .resource       = sdp3430_smc91x_resources,
75 };
76
77 static int sdp3430_keymap[] = {
78         KEY(0, 0, KEY_LEFT),
79         KEY(0, 1, KEY_RIGHT),
80         KEY(0, 2, KEY_A),
81         KEY(0, 3, KEY_B),
82         KEY(0, 4, KEY_C),
83         KEY(1, 0, KEY_DOWN),
84         KEY(1, 1, KEY_UP),
85         KEY(1, 2, KEY_E),
86         KEY(1, 3, KEY_F),
87         KEY(1, 4, KEY_G),
88         KEY(2, 0, KEY_ENTER),
89         KEY(2, 1, KEY_I),
90         KEY(2, 2, KEY_J),
91         KEY(2, 3, KEY_K),
92         KEY(2, 4, KEY_3),
93         KEY(3, 0, KEY_M),
94         KEY(3, 1, KEY_N),
95         KEY(3, 2, KEY_O),
96         KEY(3, 3, KEY_P),
97         KEY(3, 4, KEY_Q),
98         KEY(4, 0, KEY_R),
99         KEY(4, 1, KEY_4),
100         KEY(4, 2, KEY_T),
101         KEY(4, 3, KEY_U),
102         KEY(4, 4, KEY_D),
103         KEY(5, 0, KEY_V),
104         KEY(5, 1, KEY_W),
105         KEY(5, 2, KEY_L),
106         KEY(5, 3, KEY_S),
107         KEY(5, 4, KEY_H),
108         0
109 };
110
111 static struct twl4030_keypad_data sdp3430_kp_data = {
112         .rows           = 5,
113         .cols           = 6,
114         .keymap         = sdp3430_keymap,
115         .keymapsize     = ARRAY_SIZE(sdp3430_keymap),
116         .rep            = 1,
117 };
118
119 static int ts_gpio;     /* Needed for ads7846_get_pendown_state */
120
121 /**
122  * @brief ads7846_dev_init : Requests & sets GPIO line for pen-irq
123  *
124  * @return - void. If request gpio fails then Flag KERN_ERR.
125  */
126 static void ads7846_dev_init(void)
127 {
128         if (gpio_request(ts_gpio, "ADS7846 pendown") < 0) {
129                 printk(KERN_ERR "can't get ads746 pen down GPIO\n");
130                 return;
131         }
132
133         gpio_direction_input(ts_gpio);
134
135         omap_set_gpio_debounce(ts_gpio, 1);
136         omap_set_gpio_debounce_time(ts_gpio, 0xa);
137 }
138
139 static int ads7846_get_pendown_state(void)
140 {
141         return !gpio_get_value(ts_gpio);
142 }
143
144 static struct ads7846_platform_data tsc2046_config __initdata = {
145         .get_pendown_state      = ads7846_get_pendown_state,
146         .keep_vref_on           = 1,
147 };
148
149
150 static struct omap2_mcspi_device_config tsc2046_mcspi_config = {
151         .turbo_mode     = 0,
152         .single_channel = 1,    /* 0: slave, 1: master */
153 };
154
155 static struct spi_board_info sdp3430_spi_board_info[] __initdata = {
156         [0] = {
157                 /*
158                  * TSC2046 operates at a max freqency of 2MHz, so
159                  * operate slightly below at 1.5MHz
160                  */
161                 .modalias               = "ads7846",
162                 .bus_num                = 1,
163                 .chip_select            = 0,
164                 .max_speed_hz           = 1500000,
165                 .controller_data        = &tsc2046_mcspi_config,
166                 .irq                    = 0,
167                 .platform_data          = &tsc2046_config,
168         },
169 };
170
171 static struct platform_device sdp3430_lcd_device = {
172         .name           = "sdp2430_lcd",
173         .id             = -1,
174 };
175
176 static struct regulator_consumer_supply sdp3430_vdac_supply = {
177         .supply         = "vdac",
178         .dev            = &sdp3430_lcd_device.dev,
179 };
180
181 static struct regulator_consumer_supply sdp3430_vdvi_supply = {
182         .supply         = "vdvi",
183         .dev            = &sdp3430_lcd_device.dev,
184 };
185
186 static struct platform_device *sdp3430_devices[] __initdata = {
187         &sdp3430_smc91x_device,
188         &sdp3430_lcd_device,
189 };
190
191 static inline void __init sdp3430_init_smc91x(void)
192 {
193         int eth_cs;
194         unsigned long cs_mem_base;
195         int eth_gpio = 0;
196
197         eth_cs = SDP3430_SMC91X_CS;
198
199         if (gpmc_cs_request(eth_cs, SZ_16M, &cs_mem_base) < 0) {
200                 printk(KERN_ERR "Failed to request GPMC mem for smc91x\n");
201                 return;
202         }
203
204         sdp3430_smc91x_resources[0].start = cs_mem_base + 0x300;
205         sdp3430_smc91x_resources[0].end = cs_mem_base + 0x30f;
206         udelay(100);
207
208         if (omap_rev() > OMAP3430_REV_ES1_0)
209                 eth_gpio = SDP3430_ETHR_GPIO_IRQ_SDPV2;
210         else
211                 eth_gpio = SDP3430_ETHR_GPIO_IRQ_SDPV1;
212
213         sdp3430_smc91x_resources[1].start = gpio_to_irq(eth_gpio);
214
215         if (gpio_request(eth_gpio, "SMC91x irq") < 0) {
216                 printk(KERN_ERR "Failed to request GPIO%d for smc91x IRQ\n",
217                         eth_gpio);
218                 return;
219         }
220         gpio_direction_input(eth_gpio);
221 }
222
223 static void __init omap_3430sdp_init_irq(void)
224 {
225         omap2_init_common_hw(NULL);
226         omap_init_irq();
227         omap_gpio_init();
228         sdp3430_init_smc91x();
229 }
230
231 static struct omap_uart_config sdp3430_uart_config __initdata = {
232         .enabled_uarts  = ((1 << 0) | (1 << 1) | (1 << 2)),
233 };
234
235 static struct omap_lcd_config sdp3430_lcd_config __initdata = {
236         .ctrl_name      = "internal",
237 };
238
239 static struct omap_board_config_kernel sdp3430_config[] __initdata = {
240         { OMAP_TAG_UART,        &sdp3430_uart_config },
241         { OMAP_TAG_LCD,         &sdp3430_lcd_config },
242 };
243
244 static int sdp3430_batt_table[] = {
245 /* 0 C*/
246 30800, 29500, 28300, 27100,
247 26000, 24900, 23900, 22900, 22000, 21100, 20300, 19400, 18700, 17900,
248 17200, 16500, 15900, 15300, 14700, 14100, 13600, 13100, 12600, 12100,
249 11600, 11200, 10800, 10400, 10000, 9630,   9280,   8950,   8620,   8310,
250 8020,   7730,   7460,   7200,   6950,   6710,   6470,   6250,   6040,   5830,
251 5640,   5450,   5260,   5090,   4920,   4760,   4600,   4450,   4310,   4170,
252 4040,   3910,   3790,   3670,   3550
253 };
254
255 static struct twl4030_bci_platform_data sdp3430_bci_data = {
256         .battery_tmp_tbl        = sdp3430_batt_table,
257         .tblsize                = ARRAY_SIZE(sdp3430_batt_table),
258 };
259
260 static struct twl4030_hsmmc_info mmc[] = {
261         {
262                 .mmc            = 1,
263                 /* 8 bits (default) requires S6.3 == ON,
264                  * so the SIM card isn't used; else 4 bits.
265                  */
266                 .wires          = 8,
267                 .gpio_wp        = 4,
268         },
269         {
270                 .mmc            = 2,
271                 .wires          = 8,
272                 .gpio_wp        = 7,
273         },
274         {}      /* Terminator */
275 };
276
277 static struct regulator_consumer_supply sdp3430_vmmc1_supply = {
278         .supply                 = "vmmc",
279 };
280
281 static struct regulator_consumer_supply sdp3430_vsim_supply = {
282         .supply                 = "vmmc_aux",
283 };
284
285 static struct regulator_consumer_supply sdp3430_vmmc2_supply = {
286         .supply                 = "vmmc",
287 };
288
289 static int sdp3430_twl_gpio_setup(struct device *dev,
290                 unsigned gpio, unsigned ngpio)
291 {
292         /* gpio + 0 is "mmc0_cd" (input/IRQ),
293          * gpio + 1 is "mmc1_cd" (input/IRQ)
294          */
295         mmc[0].gpio_cd = gpio + 0;
296         mmc[1].gpio_cd = gpio + 1;
297         twl4030_mmc_init(mmc);
298
299         /* link regulators to MMC adapters ... we "know" the
300          * regulators will be set up only *after* we return.
301          */
302         sdp3430_vmmc1_supply.dev = mmc[0].dev;
303         sdp3430_vsim_supply.dev = mmc[0].dev;
304         sdp3430_vmmc2_supply.dev = mmc[1].dev;
305
306         /* gpio + 7 is "sub_lcd_en_bkl" (output/PWM1) */
307         gpio_request(gpio + 7, "sub_lcd_en_bkl");
308         gpio_direction_output(gpio + 7, 0);
309
310         /* gpio + 15 is "sub_lcd_nRST" (output) */
311         gpio_request(gpio + 15, "sub_lcd_nRST");
312         gpio_direction_output(gpio + 15, 0);
313
314         return 0;
315 }
316
317 static struct twl4030_gpio_platform_data sdp3430_gpio_data = {
318         .gpio_base      = OMAP_MAX_GPIO_LINES,
319         .irq_base       = TWL4030_GPIO_IRQ_BASE,
320         .irq_end        = TWL4030_GPIO_IRQ_END,
321         .pulldowns      = BIT(2) | BIT(6) | BIT(8) | BIT(13)
322                                 | BIT(16) | BIT(17),
323         .setup          = sdp3430_twl_gpio_setup,
324 };
325
326 static struct twl4030_usb_data sdp3430_usb_data = {
327         .usb_mode       = T2_USB_MODE_ULPI,
328 };
329
330 static struct twl4030_madc_platform_data sdp3430_madc_data = {
331         .irq_line       = 1,
332 };
333
334 /*
335  * Apply all the fixed voltages since most versions of U-Boot
336  * don't bother with that initialization.
337  */
338
339 /* VAUX1 for mainboard (irda and sub-lcd) */
340 static struct regulator_init_data sdp3430_vaux1 = {
341         .constraints = {
342                 .min_uV                 = 2800000,
343                 .max_uV                 = 2800000,
344                 .apply_uV               = true,
345                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
346                                         | REGULATOR_MODE_STANDBY,
347                 .valid_ops_mask         = REGULATOR_CHANGE_MODE
348                                         | REGULATOR_CHANGE_STATUS,
349         },
350 };
351
352 /* VAUX2 for camera module */
353 static struct regulator_init_data sdp3430_vaux2 = {
354         .constraints = {
355                 .min_uV                 = 2800000,
356                 .max_uV                 = 2800000,
357                 .apply_uV               = true,
358                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
359                                         | REGULATOR_MODE_STANDBY,
360                 .valid_ops_mask         = REGULATOR_CHANGE_MODE
361                                         | REGULATOR_CHANGE_STATUS,
362         },
363 };
364
365 /* VAUX3 for LCD board */
366 static struct regulator_init_data sdp3430_vaux3 = {
367         .constraints = {
368                 .min_uV                 = 2800000,
369                 .max_uV                 = 2800000,
370                 .apply_uV               = true,
371                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
372                                         | REGULATOR_MODE_STANDBY,
373                 .valid_ops_mask         = REGULATOR_CHANGE_MODE
374                                         | REGULATOR_CHANGE_STATUS,
375         },
376 };
377
378 /* VAUX4 for OMAP VDD_CSI2 (camera) */
379 static struct regulator_init_data sdp3430_vaux4 = {
380         .constraints = {
381                 .min_uV                 = 1800000,
382                 .max_uV                 = 1800000,
383                 .apply_uV               = true,
384                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
385                                         | REGULATOR_MODE_STANDBY,
386                 .valid_ops_mask         = REGULATOR_CHANGE_MODE
387                                         | REGULATOR_CHANGE_STATUS,
388         },
389 };
390
391 /* VMMC1 for OMAP VDD_MMC1 (i/o) and MMC1 card */
392 static struct regulator_init_data sdp3430_vmmc1 = {
393         .constraints = {
394                 .min_uV                 = 1850000,
395                 .max_uV                 = 3150000,
396                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
397                                         | REGULATOR_MODE_STANDBY,
398                 .valid_ops_mask         = REGULATOR_CHANGE_VOLTAGE
399                                         | REGULATOR_CHANGE_MODE
400                                         | REGULATOR_CHANGE_STATUS,
401         },
402         .num_consumer_supplies  = 1,
403         .consumer_supplies      = &sdp3430_vmmc1_supply,
404 };
405
406 /* VMMC2 for MMC2 card */
407 static struct regulator_init_data sdp3430_vmmc2 = {
408         .constraints = {
409                 .min_uV                 = 1850000,
410                 .max_uV                 = 1850000,
411                 .apply_uV               = true,
412                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
413                                         | REGULATOR_MODE_STANDBY,
414                 .valid_ops_mask         = REGULATOR_CHANGE_MODE
415                                         | REGULATOR_CHANGE_STATUS,
416         },
417         .num_consumer_supplies  = 1,
418         .consumer_supplies      = &sdp3430_vmmc2_supply,
419 };
420
421 /* VSIM for OMAP VDD_MMC1A (i/o for DAT4..DAT7) */
422 static struct regulator_init_data sdp3430_vsim = {
423         .constraints = {
424                 .min_uV                 = 1800000,
425                 .max_uV                 = 3000000,
426                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
427                                         | REGULATOR_MODE_STANDBY,
428                 .valid_ops_mask         = REGULATOR_CHANGE_VOLTAGE
429                                         | REGULATOR_CHANGE_MODE
430                                         | REGULATOR_CHANGE_STATUS,
431         },
432         .num_consumer_supplies  = 1,
433         .consumer_supplies      = &sdp3430_vsim_supply,
434 };
435
436 /* VDAC for DSS driving S-Video */
437 static struct regulator_init_data sdp3430_vdac = {
438         .constraints = {
439                 .min_uV                 = 1800000,
440                 .max_uV                 = 1800000,
441                 .apply_uV               = true,
442                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
443                                         | REGULATOR_MODE_STANDBY,
444                 .valid_ops_mask         = REGULATOR_CHANGE_MODE
445                                         | REGULATOR_CHANGE_STATUS,
446         },
447         .num_consumer_supplies  = 1,
448         .consumer_supplies      = &sdp3430_vdac_supply,
449 };
450
451 /* VPLL2 for digital video outputs */
452 static struct regulator_init_data sdp3430_vpll2 = {
453         .constraints = {
454                 .name                   = "VDVI",
455                 .min_uV                 = 1800000,
456                 .max_uV                 = 1800000,
457                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
458                                         | REGULATOR_MODE_STANDBY,
459                 .valid_ops_mask         = REGULATOR_CHANGE_MODE
460                                         | REGULATOR_CHANGE_STATUS,
461         },
462         .num_consumer_supplies  = 1,
463         .consumer_supplies      = &sdp3430_vdvi_supply,
464 };
465
466 static struct twl4030_platform_data sdp3430_twldata = {
467         .irq_base       = TWL4030_IRQ_BASE,
468         .irq_end        = TWL4030_IRQ_END,
469
470         /* platform_data for children goes here */
471         .bci            = &sdp3430_bci_data,
472         .gpio           = &sdp3430_gpio_data,
473         .madc           = &sdp3430_madc_data,
474         .keypad         = &sdp3430_kp_data,
475         .usb            = &sdp3430_usb_data,
476
477         .vaux1          = &sdp3430_vaux1,
478         .vaux2          = &sdp3430_vaux2,
479         .vaux3          = &sdp3430_vaux3,
480         .vaux4          = &sdp3430_vaux4,
481         .vmmc1          = &sdp3430_vmmc1,
482         .vmmc2          = &sdp3430_vmmc2,
483         .vsim           = &sdp3430_vsim,
484         .vdac           = &sdp3430_vdac,
485         .vpll2          = &sdp3430_vpll2,
486 };
487
488 static struct i2c_board_info __initdata sdp3430_i2c_boardinfo[] = {
489         {
490                 I2C_BOARD_INFO("twl4030", 0x48),
491                 .flags = I2C_CLIENT_WAKE,
492                 .irq = INT_34XX_SYS_NIRQ,
493                 .platform_data = &sdp3430_twldata,
494         },
495 };
496
497 static int __init omap3430_i2c_init(void)
498 {
499         /* i2c1 for PMIC only */
500         omap_register_i2c_bus(1, 2600, sdp3430_i2c_boardinfo,
501                         ARRAY_SIZE(sdp3430_i2c_boardinfo));
502         /* i2c2 on camera connector (for sensor control) and optional isp1301 */
503         omap_register_i2c_bus(2, 400, NULL, 0);
504         /* i2c3 on display connector (for DVI, tfp410) */
505         omap_register_i2c_bus(3, 400, NULL, 0);
506         return 0;
507 }
508
509 static void __init omap_3430sdp_init(void)
510 {
511         omap3430_i2c_init();
512         platform_add_devices(sdp3430_devices, ARRAY_SIZE(sdp3430_devices));
513         omap_board_config = sdp3430_config;
514         omap_board_config_size = ARRAY_SIZE(sdp3430_config);
515         if (omap_rev() > OMAP3430_REV_ES1_0)
516                 ts_gpio = SDP3430_TS_GPIO_IRQ_SDPV2;
517         else
518                 ts_gpio = SDP3430_TS_GPIO_IRQ_SDPV1;
519         sdp3430_spi_board_info[0].irq = gpio_to_irq(ts_gpio);
520         spi_register_board_info(sdp3430_spi_board_info,
521                                 ARRAY_SIZE(sdp3430_spi_board_info));
522         ads7846_dev_init();
523         omap_serial_init();
524         usb_musb_init();
525 }
526
527 static void __init omap_3430sdp_map_io(void)
528 {
529         omap2_set_globals_343x();
530         omap2_map_common_io();
531 }
532
533 MACHINE_START(OMAP_3430SDP, "OMAP3430 3430SDP board")
534         /* Maintainer: Syed Khasim - Texas Instruments Inc */
535         .phys_io        = 0x48000000,
536         .io_pg_offst    = ((0xd8000000) >> 18) & 0xfffc,
537         .boot_params    = 0x80000100,
538         .map_io         = omap_3430sdp_map_io,
539         .init_irq       = omap_3430sdp_init_irq,
540         .init_machine   = omap_3430sdp_init,
541         .timer          = &omap_timer,
542 MACHINE_END