Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input
[linux-2.6.git] / arch / arm / mach-omap2 / board-rx51-peripherals.c
1 /*
2  * linux/arch/arm/mach-omap2/board-rx51-peripherals.c
3  *
4  * Copyright (C) 2008-2009 Nokia
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  */
10
11 #include <linux/kernel.h>
12 #include <linux/init.h>
13 #include <linux/platform_device.h>
14 #include <linux/input.h>
15 #include <linux/spi/spi.h>
16 #include <linux/i2c.h>
17 #include <linux/i2c/twl4030.h>
18 #include <linux/clk.h>
19 #include <linux/delay.h>
20 #include <linux/regulator/machine.h>
21 #include <linux/gpio.h>
22 #include <linux/mmc/host.h>
23
24 #include <mach/mcspi.h>
25 #include <mach/mux.h>
26 #include <mach/board.h>
27 #include <mach/common.h>
28 #include <mach/dma.h>
29 #include <mach/gpmc.h>
30 #include <mach/keypad.h>
31 #include <mach/onenand.h>
32 #include <mach/gpmc-smc91x.h>
33
34 #include "mmc-twl4030.h"
35
36 #define SYSTEM_REV_B_USES_VAUX3 0x1699
37 #define SYSTEM_REV_S_USES_VAUX3 0x8
38
39 static int board_keymap[] = {
40         KEY(0, 0, KEY_Q),
41         KEY(0, 1, KEY_O),
42         KEY(0, 2, KEY_P),
43         KEY(0, 3, KEY_COMMA),
44         KEY(0, 4, KEY_BACKSPACE),
45         KEY(0, 6, KEY_A),
46         KEY(0, 7, KEY_S),
47         KEY(1, 0, KEY_W),
48         KEY(1, 1, KEY_D),
49         KEY(1, 2, KEY_F),
50         KEY(1, 3, KEY_G),
51         KEY(1, 4, KEY_H),
52         KEY(1, 5, KEY_J),
53         KEY(1, 6, KEY_K),
54         KEY(1, 7, KEY_L),
55         KEY(2, 0, KEY_E),
56         KEY(2, 1, KEY_DOT),
57         KEY(2, 2, KEY_UP),
58         KEY(2, 3, KEY_ENTER),
59         KEY(2, 5, KEY_Z),
60         KEY(2, 6, KEY_X),
61         KEY(2, 7, KEY_C),
62         KEY(3, 0, KEY_R),
63         KEY(3, 1, KEY_V),
64         KEY(3, 2, KEY_B),
65         KEY(3, 3, KEY_N),
66         KEY(3, 4, KEY_M),
67         KEY(3, 5, KEY_SPACE),
68         KEY(3, 6, KEY_SPACE),
69         KEY(3, 7, KEY_LEFT),
70         KEY(4, 0, KEY_T),
71         KEY(4, 1, KEY_DOWN),
72         KEY(4, 2, KEY_RIGHT),
73         KEY(4, 4, KEY_LEFTCTRL),
74         KEY(4, 5, KEY_RIGHTALT),
75         KEY(4, 6, KEY_LEFTSHIFT),
76         KEY(5, 0, KEY_Y),
77         KEY(6, 0, KEY_U),
78         KEY(7, 0, KEY_I),
79         KEY(7, 1, KEY_F7),
80         KEY(7, 2, KEY_F8),
81         KEY(0xff, 2, KEY_F9),
82         KEY(0xff, 4, KEY_F10),
83         KEY(0xff, 5, KEY_F11),
84 };
85
86 static struct matrix_keymap_data board_map_data = {
87         .keymap                 = board_keymap,
88         .keymap_size            = ARRAY_SIZE(board_keymap),
89 };
90
91 static struct twl4030_keypad_data rx51_kp_data = {
92         .keymap_data    = &board_map_data,
93         .rows           = 8,
94         .cols           = 8,
95         .rep            = 1,
96 };
97
98 static struct twl4030_madc_platform_data rx51_madc_data = {
99         .irq_line               = 1,
100 };
101
102 static struct twl4030_hsmmc_info mmc[] = {
103         {
104                 .name           = "external",
105                 .mmc            = 1,
106                 .wires          = 4,
107                 .cover_only     = true,
108                 .gpio_cd        = 160,
109                 .gpio_wp        = -EINVAL,
110                 .power_saving   = true,
111         },
112         {
113                 .name           = "internal",
114                 .mmc            = 2,
115                 .wires          = 8,
116                 .gpio_cd        = -EINVAL,
117                 .gpio_wp        = -EINVAL,
118                 .nonremovable   = true,
119                 .power_saving   = true,
120         },
121         {}      /* Terminator */
122 };
123
124 static struct regulator_consumer_supply rx51_vmmc1_supply = {
125         .supply                 = "vmmc",
126 };
127
128 static struct regulator_consumer_supply rx51_vmmc2_supply = {
129         .supply                 = "vmmc",
130 };
131
132 static struct regulator_consumer_supply rx51_vsim_supply = {
133         .supply                 = "vmmc_aux",
134 };
135
136 static struct regulator_init_data rx51_vaux1 = {
137         .constraints = {
138                 .name                   = "V28",
139                 .min_uV                 = 2800000,
140                 .max_uV                 = 2800000,
141                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
142                                         | REGULATOR_MODE_STANDBY,
143                 .valid_ops_mask         = REGULATOR_CHANGE_MODE
144                                         | REGULATOR_CHANGE_STATUS,
145         },
146 };
147
148 static struct regulator_init_data rx51_vaux2 = {
149         .constraints = {
150                 .name                   = "VCSI",
151                 .min_uV                 = 1800000,
152                 .max_uV                 = 1800000,
153                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
154                                         | REGULATOR_MODE_STANDBY,
155                 .valid_ops_mask         = REGULATOR_CHANGE_MODE
156                                         | REGULATOR_CHANGE_STATUS,
157         },
158 };
159
160 /* VAUX3 - adds more power to VIO_18 rail */
161 static struct regulator_init_data rx51_vaux3_cam = {
162         .constraints = {
163                 .name                   = "VCAM_DIG_18",
164                 .min_uV                 = 1800000,
165                 .max_uV                 = 1800000,
166                 .apply_uV               = true,
167                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
168                                         | REGULATOR_MODE_STANDBY,
169                 .valid_ops_mask         = REGULATOR_CHANGE_MODE
170                                         | REGULATOR_CHANGE_STATUS,
171         },
172 };
173
174 static struct regulator_init_data rx51_vaux3_mmc = {
175         .constraints = {
176                 .name                   = "VMMC2_30",
177                 .min_uV                 = 2800000,
178                 .max_uV                 = 3000000,
179                 .apply_uV               = true,
180                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
181                                         | REGULATOR_MODE_STANDBY,
182                 .valid_ops_mask         = REGULATOR_CHANGE_VOLTAGE
183                                         | REGULATOR_CHANGE_MODE
184                                         | REGULATOR_CHANGE_STATUS,
185         },
186         .num_consumer_supplies  = 1,
187         .consumer_supplies      = &rx51_vmmc2_supply,
188 };
189
190 static struct regulator_init_data rx51_vaux4 = {
191         .constraints = {
192                 .name                   = "VCAM_ANA_28",
193                 .min_uV                 = 2800000,
194                 .max_uV                 = 2800000,
195                 .apply_uV               = true,
196                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
197                                         | REGULATOR_MODE_STANDBY,
198                 .valid_ops_mask         = REGULATOR_CHANGE_MODE
199                                         | REGULATOR_CHANGE_STATUS,
200         },
201 };
202
203 static struct regulator_init_data rx51_vmmc1 = {
204         .constraints = {
205                 .min_uV                 = 1850000,
206                 .max_uV                 = 3150000,
207                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
208                                         | REGULATOR_MODE_STANDBY,
209                 .valid_ops_mask         = REGULATOR_CHANGE_VOLTAGE
210                                         | REGULATOR_CHANGE_MODE
211                                         | REGULATOR_CHANGE_STATUS,
212         },
213         .num_consumer_supplies  = 1,
214         .consumer_supplies      = &rx51_vmmc1_supply,
215 };
216
217 static struct regulator_init_data rx51_vmmc2 = {
218         .constraints = {
219                 .name                   = "VMMC2_30",
220                 .min_uV                 = 1850000,
221                 .max_uV                 = 3150000,
222                 .apply_uV               = true,
223                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
224                                         | REGULATOR_MODE_STANDBY,
225                 .valid_ops_mask         = REGULATOR_CHANGE_VOLTAGE
226                                         | REGULATOR_CHANGE_MODE
227                                         | REGULATOR_CHANGE_STATUS,
228         },
229         .num_consumer_supplies  = 1,
230         .consumer_supplies      = &rx51_vmmc2_supply,
231 };
232
233 static struct regulator_init_data rx51_vsim = {
234         .constraints = {
235                 .name                   = "VMMC2_IO_18",
236                 .min_uV                 = 1800000,
237                 .max_uV                 = 1800000,
238                 .apply_uV               = true,
239                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
240                                         | REGULATOR_MODE_STANDBY,
241                 .valid_ops_mask         = REGULATOR_CHANGE_MODE
242                                         | REGULATOR_CHANGE_STATUS,
243         },
244         .num_consumer_supplies  = 1,
245         .consumer_supplies      = &rx51_vsim_supply,
246 };
247
248 static struct regulator_init_data rx51_vdac = {
249         .constraints = {
250                 .min_uV                 = 1800000,
251                 .max_uV                 = 1800000,
252                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
253                                         | REGULATOR_MODE_STANDBY,
254                 .valid_ops_mask         = REGULATOR_CHANGE_VOLTAGE
255                                         | REGULATOR_CHANGE_MODE
256                                         | REGULATOR_CHANGE_STATUS,
257         },
258 };
259
260 static int rx51_twlgpio_setup(struct device *dev, unsigned gpio, unsigned n)
261 {
262         /* FIXME this gpio setup is just a placeholder for now */
263         gpio_request(gpio + 6, "backlight_pwm");
264         gpio_direction_output(gpio + 6, 0);
265         gpio_request(gpio + 7, "speaker_en");
266         gpio_direction_output(gpio + 7, 1);
267
268         /* set up MMC adapters, linking their regulators to them */
269         twl4030_mmc_init(mmc);
270         rx51_vmmc1_supply.dev = mmc[0].dev;
271         rx51_vmmc2_supply.dev = mmc[1].dev;
272         rx51_vsim_supply.dev = mmc[1].dev;
273
274         return 0;
275 }
276
277 static struct twl4030_gpio_platform_data rx51_gpio_data = {
278         .gpio_base              = OMAP_MAX_GPIO_LINES,
279         .irq_base               = TWL4030_GPIO_IRQ_BASE,
280         .irq_end                = TWL4030_GPIO_IRQ_END,
281         .pulldowns              = BIT(0) | BIT(1) | BIT(2) | BIT(3)
282                                 | BIT(4) | BIT(5)
283                                 | BIT(8) | BIT(9) | BIT(10) | BIT(11)
284                                 | BIT(12) | BIT(13) | BIT(14) | BIT(15)
285                                 | BIT(16) | BIT(17) ,
286         .setup                  = rx51_twlgpio_setup,
287 };
288
289 static struct twl4030_usb_data rx51_usb_data = {
290         .usb_mode               = T2_USB_MODE_ULPI,
291 };
292
293 static struct twl4030_ins sleep_on_seq[] __initdata = {
294 /*
295  * Turn off VDD1 and VDD2.
296  */
297         {MSG_SINGULAR(DEV_GRP_P1, 0xf, RES_STATE_OFF), 4},
298         {MSG_SINGULAR(DEV_GRP_P1, 0x10, RES_STATE_OFF), 2},
299 /*
300  * And also turn off the OMAP3 PLLs and the sysclk output.
301  */
302         {MSG_SINGULAR(DEV_GRP_P1, 0x7, RES_STATE_OFF), 3},
303         {MSG_SINGULAR(DEV_GRP_P1, 0x17, RES_STATE_OFF), 3},
304 };
305
306 static struct twl4030_script sleep_on_script __initdata = {
307         .script = sleep_on_seq,
308         .size   = ARRAY_SIZE(sleep_on_seq),
309         .flags  = TWL4030_SLEEP_SCRIPT,
310 };
311
312 static struct twl4030_ins wakeup_seq[] __initdata = {
313 /*
314  * Reenable the OMAP3 PLLs.
315  * Wakeup VDD1 and VDD2.
316  * Reenable sysclk output.
317  */
318         {MSG_SINGULAR(DEV_GRP_P1, 0x7, RES_STATE_ACTIVE), 0x30},
319         {MSG_SINGULAR(DEV_GRP_P1, 0xf, RES_STATE_ACTIVE), 0x30},
320         {MSG_SINGULAR(DEV_GRP_P1, 0x10, RES_STATE_ACTIVE), 0x37},
321         {MSG_SINGULAR(DEV_GRP_P1, 0x19, RES_STATE_ACTIVE), 3},
322 };
323
324 static struct twl4030_script wakeup_script __initdata = {
325         .script = wakeup_seq,
326         .size   = ARRAY_SIZE(wakeup_seq),
327         .flags  = TWL4030_WAKEUP12_SCRIPT,
328 };
329
330 static struct twl4030_ins wakeup_p3_seq[] __initdata = {
331 /*
332  * Wakeup VDD1 (dummy to be able to insert a delay)
333  * Enable CLKEN
334  */
335         {MSG_SINGULAR(DEV_GRP_P1, 0x17, RES_STATE_ACTIVE), 3},
336 };
337
338 static struct twl4030_script wakeup_p3_script __initdata = {
339         .script = wakeup_p3_seq,
340         .size   = ARRAY_SIZE(wakeup_p3_seq),
341         .flags  = TWL4030_WAKEUP3_SCRIPT,
342 };
343
344 static struct twl4030_ins wrst_seq[] __initdata = {
345 /*
346  * Reset twl4030.
347  * Reset VDD1 regulator.
348  * Reset VDD2 regulator.
349  * Reset VPLL1 regulator.
350  * Enable sysclk output.
351  * Reenable twl4030.
352  */
353         {MSG_SINGULAR(DEV_GRP_NULL, RES_RESET, RES_STATE_OFF), 2},
354         {MSG_BROADCAST(DEV_GRP_NULL, RES_GRP_ALL, 0, 1, RES_STATE_ACTIVE),
355                 0x13},
356         {MSG_BROADCAST(DEV_GRP_NULL, RES_GRP_PP, 0, 2, RES_STATE_WRST), 0x13},
357         {MSG_BROADCAST(DEV_GRP_NULL, RES_GRP_PP, 0, 3, RES_STATE_OFF), 0x13},
358         {MSG_SINGULAR(DEV_GRP_NULL, RES_VDD1, RES_STATE_WRST), 0x13},
359         {MSG_SINGULAR(DEV_GRP_NULL, RES_VDD2, RES_STATE_WRST), 0x13},
360         {MSG_SINGULAR(DEV_GRP_NULL, RES_VPLL1, RES_STATE_WRST), 0x35},
361         {MSG_SINGULAR(DEV_GRP_P1, RES_HFCLKOUT, RES_STATE_ACTIVE), 2},
362         {MSG_SINGULAR(DEV_GRP_NULL, RES_RESET, RES_STATE_ACTIVE), 2},
363 };
364
365 static struct twl4030_script wrst_script __initdata = {
366         .script = wrst_seq,
367         .size   = ARRAY_SIZE(wrst_seq),
368         .flags  = TWL4030_WRST_SCRIPT,
369 };
370
371 static struct twl4030_script *twl4030_scripts[] __initdata = {
372         /* wakeup12 script should be loaded before sleep script, otherwise a
373            board might hit retention before loading of wakeup script is
374            completed. This can cause boot failures depending on timing issues.
375         */
376         &wakeup_script,
377         &sleep_on_script,
378         &wakeup_p3_script,
379         &wrst_script,
380 };
381
382 static struct twl4030_resconfig twl4030_rconfig[] __initdata = {
383         { .resource = RES_VINTANA1, .devgroup = -1, .type = -1, .type2 = 1 },
384         { .resource = RES_VINTANA2, .devgroup = -1, .type = -1, .type2 = 1 },
385         { .resource = RES_VINTDIG, .devgroup = -1, .type = -1, .type2 = 1 },
386         { .resource = RES_VMMC1, .devgroup = -1, .type = -1, .type2 = 3},
387         { .resource = RES_VMMC2, .devgroup = DEV_GRP_NULL, .type = -1,
388           .type2 = 3},
389         { .resource = RES_VAUX1, .devgroup = -1, .type = -1, .type2 = 3},
390         { .resource = RES_VAUX2, .devgroup = -1, .type = -1, .type2 = 3},
391         { .resource = RES_VAUX3, .devgroup = -1, .type = -1, .type2 = 3},
392         { .resource = RES_VAUX4, .devgroup = -1, .type = -1, .type2 = 3},
393         { .resource = RES_VPLL2, .devgroup = -1, .type = -1, .type2 = 3},
394         { .resource = RES_VDAC, .devgroup = -1, .type = -1, .type2 = 3},
395         { .resource = RES_VSIM, .devgroup = DEV_GRP_NULL, .type = -1,
396           .type2 = 3},
397         { .resource = RES_CLKEN, .devgroup = DEV_GRP_P3, .type = -1,
398                 .type2 = 1 },
399         { 0, 0},
400 };
401
402 static struct twl4030_power_data rx51_t2scripts_data __initdata = {
403         .scripts        = twl4030_scripts,
404         .num = ARRAY_SIZE(twl4030_scripts),
405         .resource_config = twl4030_rconfig,
406 };
407
408
409
410 static struct twl4030_platform_data rx51_twldata __initdata = {
411         .irq_base               = TWL4030_IRQ_BASE,
412         .irq_end                = TWL4030_IRQ_END,
413
414         /* platform_data for children goes here */
415         .gpio                   = &rx51_gpio_data,
416         .keypad                 = &rx51_kp_data,
417         .madc                   = &rx51_madc_data,
418         .usb                    = &rx51_usb_data,
419         .power                  = &rx51_t2scripts_data,
420
421         .vaux1                  = &rx51_vaux1,
422         .vaux2                  = &rx51_vaux2,
423         .vaux4                  = &rx51_vaux4,
424         .vmmc1                  = &rx51_vmmc1,
425         .vsim                   = &rx51_vsim,
426         .vdac                   = &rx51_vdac,
427 };
428
429 static struct i2c_board_info __initdata rx51_peripherals_i2c_board_info_1[] = {
430         {
431                 I2C_BOARD_INFO("twl5030", 0x48),
432                 .flags = I2C_CLIENT_WAKE,
433                 .irq = INT_34XX_SYS_NIRQ,
434                 .platform_data = &rx51_twldata,
435         },
436 };
437
438 static int __init rx51_i2c_init(void)
439 {
440         if ((system_rev >= SYSTEM_REV_S_USES_VAUX3 && system_rev < 0x100) ||
441             system_rev >= SYSTEM_REV_B_USES_VAUX3)
442                 rx51_twldata.vaux3 = &rx51_vaux3_mmc;
443         else {
444                 rx51_twldata.vaux3 = &rx51_vaux3_cam;
445                 rx51_twldata.vmmc2 = &rx51_vmmc2;
446         }
447         omap_register_i2c_bus(1, 2600, rx51_peripherals_i2c_board_info_1,
448                         ARRAY_SIZE(rx51_peripherals_i2c_board_info_1));
449         omap_register_i2c_bus(2, 100, NULL, 0);
450         omap_register_i2c_bus(3, 400, NULL, 0);
451         return 0;
452 }
453
454 #if defined(CONFIG_MTD_ONENAND_OMAP2) || \
455         defined(CONFIG_MTD_ONENAND_OMAP2_MODULE)
456
457 static struct mtd_partition onenand_partitions[] = {
458         {
459                 .name           = "bootloader",
460                 .offset         = 0,
461                 .size           = 0x20000,
462                 .mask_flags     = MTD_WRITEABLE,        /* Force read-only */
463         },
464         {
465                 .name           = "config",
466                 .offset         = MTDPART_OFS_APPEND,
467                 .size           = 0x60000,
468         },
469         {
470                 .name           = "log",
471                 .offset         = MTDPART_OFS_APPEND,
472                 .size           = 0x40000,
473         },
474         {
475                 .name           = "kernel",
476                 .offset         = MTDPART_OFS_APPEND,
477                 .size           = 0x200000,
478         },
479         {
480                 .name           = "initfs",
481                 .offset         = MTDPART_OFS_APPEND,
482                 .size           = 0x200000,
483         },
484         {
485                 .name           = "rootfs",
486                 .offset         = MTDPART_OFS_APPEND,
487                 .size           = MTDPART_SIZ_FULL,
488         },
489 };
490
491 static struct omap_onenand_platform_data board_onenand_data = {
492         .cs             = 0,
493         .gpio_irq       = 65,
494         .parts          = onenand_partitions,
495         .nr_parts       = ARRAY_SIZE(onenand_partitions),
496         .flags          = ONENAND_SYNC_READWRITE,
497 };
498
499 static void __init board_onenand_init(void)
500 {
501         gpmc_onenand_init(&board_onenand_data);
502 }
503
504 #else
505
506 static inline void board_onenand_init(void)
507 {
508 }
509
510 #endif
511
512 #if defined(CONFIG_SMC91X) || defined(CONFIG_SMC91X_MODULE)
513
514 static struct omap_smc91x_platform_data board_smc91x_data = {
515         .cs             = 1,
516         .gpio_irq       = 54,
517         .gpio_pwrdwn    = 86,
518         .gpio_reset     = 164,
519         .flags          = GPMC_TIMINGS_SMC91C96 | IORESOURCE_IRQ_HIGHLEVEL,
520 };
521
522 static void __init board_smc91x_init(void)
523 {
524         omap_cfg_reg(U8_34XX_GPIO54_DOWN);
525         omap_cfg_reg(G25_34XX_GPIO86_OUT);
526         omap_cfg_reg(H19_34XX_GPIO164_OUT);
527
528         gpmc_smc91x_init(&board_smc91x_data);
529 }
530
531 #else
532
533 static inline void board_smc91x_init(void)
534 {
535 }
536
537 #endif
538
539 void __init rx51_peripherals_init(void)
540 {
541         rx51_i2c_init();
542         board_onenand_init();
543         board_smc91x_init();
544 }
545