omap: rx51: Add support for USB chargers
[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/input/matrix_keypad.h>
16 #include <linux/spi/spi.h>
17 #include <linux/spi/wl12xx.h>
18 #include <linux/i2c.h>
19 #include <linux/i2c/twl.h>
20 #include <linux/clk.h>
21 #include <linux/delay.h>
22 #include <linux/regulator/machine.h>
23 #include <linux/gpio.h>
24 #include <linux/gpio_keys.h>
25 #include <linux/mmc/host.h>
26
27 #include <plat/mcspi.h>
28 #include <plat/board.h>
29 #include <plat/common.h>
30 #include <plat/dma.h>
31 #include <plat/gpmc.h>
32 #include <plat/onenand.h>
33 #include <plat/gpmc-smc91x.h>
34
35 #include <sound/tlv320aic3x.h>
36 #include <sound/tpa6130a2-plat.h>
37
38 #include <../drivers/staging/iio/light/tsl2563.h>
39
40 #include "mux.h"
41 #include "hsmmc.h"
42
43 #define SYSTEM_REV_B_USES_VAUX3 0x1699
44 #define SYSTEM_REV_S_USES_VAUX3 0x8
45
46 #define RX51_WL1251_POWER_GPIO          87
47 #define RX51_WL1251_IRQ_GPIO            42
48
49 /* list all spi devices here */
50 enum {
51         RX51_SPI_WL1251,
52         RX51_SPI_MIPID,         /* LCD panel */
53         RX51_SPI_TSC2005,       /* Touch Controller */
54 };
55
56 static struct wl12xx_platform_data wl1251_pdata;
57
58 #if defined(CONFIG_SENSORS_TSL2563) || defined(CONFIG_SENSORS_TSL2563_MODULE)
59 static struct tsl2563_platform_data rx51_tsl2563_platform_data = {
60         .cover_comp_gain = 16,
61 };
62 #endif
63
64 static struct omap2_mcspi_device_config wl1251_mcspi_config = {
65         .turbo_mode     = 0,
66         .single_channel = 1,
67 };
68
69 static struct omap2_mcspi_device_config mipid_mcspi_config = {
70         .turbo_mode     = 0,
71         .single_channel = 1,
72 };
73
74 static struct omap2_mcspi_device_config tsc2005_mcspi_config = {
75         .turbo_mode     = 0,
76         .single_channel = 1,
77 };
78
79 static struct spi_board_info rx51_peripherals_spi_board_info[] __initdata = {
80         [RX51_SPI_WL1251] = {
81                 .modalias               = "wl1251",
82                 .bus_num                = 4,
83                 .chip_select            = 0,
84                 .max_speed_hz           = 48000000,
85                 .mode                   = SPI_MODE_3,
86                 .controller_data        = &wl1251_mcspi_config,
87                 .platform_data          = &wl1251_pdata,
88         },
89         [RX51_SPI_MIPID] = {
90                 .modalias               = "acx565akm",
91                 .bus_num                = 1,
92                 .chip_select            = 2,
93                 .max_speed_hz           = 6000000,
94                 .controller_data        = &mipid_mcspi_config,
95         },
96         [RX51_SPI_TSC2005] = {
97                 .modalias               = "tsc2005",
98                 .bus_num                = 1,
99                 .chip_select            = 0,
100                 /* .irq = OMAP_GPIO_IRQ(RX51_TSC2005_IRQ_GPIO),*/
101                 .max_speed_hz           = 6000000,
102                 .controller_data        = &tsc2005_mcspi_config,
103                 /* .platform_data = &tsc2005_config,*/
104         },
105 };
106
107 static struct platform_device rx51_charger_device = {
108         .name = "isp1704_charger",
109 };
110
111 #if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
112
113 #define RX51_GPIO_CAMERA_LENS_COVER     110
114 #define RX51_GPIO_CAMERA_FOCUS          68
115 #define RX51_GPIO_CAMERA_CAPTURE        69
116 #define RX51_GPIO_KEYPAD_SLIDE          71
117 #define RX51_GPIO_LOCK_BUTTON           113
118 #define RX51_GPIO_PROXIMITY             89
119
120 #define RX51_GPIO_DEBOUNCE_TIMEOUT      10
121
122 static struct gpio_keys_button rx51_gpio_keys[] = {
123         {
124                 .desc                   = "Camera Lens Cover",
125                 .type                   = EV_SW,
126                 .code                   = SW_CAMERA_LENS_COVER,
127                 .gpio                   = RX51_GPIO_CAMERA_LENS_COVER,
128                 .active_low             = 1,
129                 .debounce_interval      = RX51_GPIO_DEBOUNCE_TIMEOUT,
130         }, {
131                 .desc                   = "Camera Focus",
132                 .type                   = EV_KEY,
133                 .code                   = KEY_CAMERA_FOCUS,
134                 .gpio                   = RX51_GPIO_CAMERA_FOCUS,
135                 .active_low             = 1,
136                 .debounce_interval      = RX51_GPIO_DEBOUNCE_TIMEOUT,
137         }, {
138                 .desc                   = "Camera Capture",
139                 .type                   = EV_KEY,
140                 .code                   = KEY_CAMERA,
141                 .gpio                   = RX51_GPIO_CAMERA_CAPTURE,
142                 .active_low             = 1,
143                 .debounce_interval      = RX51_GPIO_DEBOUNCE_TIMEOUT,
144         }, {
145                 .desc                   = "Lock Button",
146                 .type                   = EV_KEY,
147                 .code                   = KEY_SCREENLOCK,
148                 .gpio                   = RX51_GPIO_LOCK_BUTTON,
149                 .active_low             = 1,
150                 .debounce_interval      = RX51_GPIO_DEBOUNCE_TIMEOUT,
151         }, {
152                 .desc                   = "Keypad Slide",
153                 .type                   = EV_SW,
154                 .code                   = SW_KEYPAD_SLIDE,
155                 .gpio                   = RX51_GPIO_KEYPAD_SLIDE,
156                 .active_low             = 1,
157                 .debounce_interval      = RX51_GPIO_DEBOUNCE_TIMEOUT,
158         }, {
159                 .desc                   = "Proximity Sensor",
160                 .type                   = EV_SW,
161                 .code                   = SW_FRONT_PROXIMITY,
162                 .gpio                   = RX51_GPIO_PROXIMITY,
163                 .active_low             = 0,
164                 .debounce_interval      = RX51_GPIO_DEBOUNCE_TIMEOUT,
165         }
166 };
167
168 static struct gpio_keys_platform_data rx51_gpio_keys_data = {
169         .buttons        = rx51_gpio_keys,
170         .nbuttons       = ARRAY_SIZE(rx51_gpio_keys),
171 };
172
173 static struct platform_device rx51_gpio_keys_device = {
174         .name   = "gpio-keys",
175         .id     = -1,
176         .dev    = {
177                 .platform_data  = &rx51_gpio_keys_data,
178         },
179 };
180
181 static void __init rx51_add_gpio_keys(void)
182 {
183         platform_device_register(&rx51_gpio_keys_device);
184 }
185 #else
186 static void __init rx51_add_gpio_keys(void)
187 {
188 }
189 #endif /* CONFIG_KEYBOARD_GPIO || CONFIG_KEYBOARD_GPIO_MODULE */
190
191 static int board_keymap[] = {
192         /*
193          * Note that KEY(x, 8, KEY_XXX) entries represent "entrire row
194          * connected to the ground" matrix state.
195          */
196         KEY(0, 0, KEY_Q),
197         KEY(0, 1, KEY_O),
198         KEY(0, 2, KEY_P),
199         KEY(0, 3, KEY_COMMA),
200         KEY(0, 4, KEY_BACKSPACE),
201         KEY(0, 6, KEY_A),
202         KEY(0, 7, KEY_S),
203
204         KEY(1, 0, KEY_W),
205         KEY(1, 1, KEY_D),
206         KEY(1, 2, KEY_F),
207         KEY(1, 3, KEY_G),
208         KEY(1, 4, KEY_H),
209         KEY(1, 5, KEY_J),
210         KEY(1, 6, KEY_K),
211         KEY(1, 7, KEY_L),
212
213         KEY(2, 0, KEY_E),
214         KEY(2, 1, KEY_DOT),
215         KEY(2, 2, KEY_UP),
216         KEY(2, 3, KEY_ENTER),
217         KEY(2, 5, KEY_Z),
218         KEY(2, 6, KEY_X),
219         KEY(2, 7, KEY_C),
220         KEY(2, 8, KEY_F9),
221
222         KEY(3, 0, KEY_R),
223         KEY(3, 1, KEY_V),
224         KEY(3, 2, KEY_B),
225         KEY(3, 3, KEY_N),
226         KEY(3, 4, KEY_M),
227         KEY(3, 5, KEY_SPACE),
228         KEY(3, 6, KEY_SPACE),
229         KEY(3, 7, KEY_LEFT),
230
231         KEY(4, 0, KEY_T),
232         KEY(4, 1, KEY_DOWN),
233         KEY(4, 2, KEY_RIGHT),
234         KEY(4, 4, KEY_LEFTCTRL),
235         KEY(4, 5, KEY_RIGHTALT),
236         KEY(4, 6, KEY_LEFTSHIFT),
237         KEY(4, 8, KEY_F10),
238
239         KEY(5, 0, KEY_Y),
240         KEY(5, 8, KEY_F11),
241
242         KEY(6, 0, KEY_U),
243
244         KEY(7, 0, KEY_I),
245         KEY(7, 1, KEY_F7),
246         KEY(7, 2, KEY_F8),
247 };
248
249 static struct matrix_keymap_data board_map_data = {
250         .keymap                 = board_keymap,
251         .keymap_size            = ARRAY_SIZE(board_keymap),
252 };
253
254 static struct twl4030_keypad_data rx51_kp_data = {
255         .keymap_data    = &board_map_data,
256         .rows           = 8,
257         .cols           = 8,
258         .rep            = 1,
259 };
260
261 static struct twl4030_madc_platform_data rx51_madc_data = {
262         .irq_line               = 1,
263 };
264
265 /* Enable input logic and pull all lines up when eMMC is on. */
266 static struct omap_board_mux rx51_mmc2_on_mux[] = {
267         OMAP3_MUX(SDMMC2_CMD, OMAP_PIN_INPUT_PULLUP | OMAP_MUX_MODE0),
268         OMAP3_MUX(SDMMC2_DAT0, OMAP_PIN_INPUT_PULLUP | OMAP_MUX_MODE0),
269         OMAP3_MUX(SDMMC2_DAT1, OMAP_PIN_INPUT_PULLUP | OMAP_MUX_MODE0),
270         OMAP3_MUX(SDMMC2_DAT2, OMAP_PIN_INPUT_PULLUP | OMAP_MUX_MODE0),
271         OMAP3_MUX(SDMMC2_DAT3, OMAP_PIN_INPUT_PULLUP | OMAP_MUX_MODE0),
272         OMAP3_MUX(SDMMC2_DAT4, OMAP_PIN_INPUT_PULLUP | OMAP_MUX_MODE0),
273         OMAP3_MUX(SDMMC2_DAT5, OMAP_PIN_INPUT_PULLUP | OMAP_MUX_MODE0),
274         OMAP3_MUX(SDMMC2_DAT6, OMAP_PIN_INPUT_PULLUP | OMAP_MUX_MODE0),
275         OMAP3_MUX(SDMMC2_DAT7, OMAP_PIN_INPUT_PULLUP | OMAP_MUX_MODE0),
276         { .reg_offset = OMAP_MUX_TERMINATOR },
277 };
278
279 /* Disable input logic and pull all lines down when eMMC is off. */
280 static struct omap_board_mux rx51_mmc2_off_mux[] = {
281         OMAP3_MUX(SDMMC2_CMD, OMAP_PULL_ENA | OMAP_MUX_MODE0),
282         OMAP3_MUX(SDMMC2_DAT0, OMAP_PULL_ENA | OMAP_MUX_MODE0),
283         OMAP3_MUX(SDMMC2_DAT1, OMAP_PULL_ENA | OMAP_MUX_MODE0),
284         OMAP3_MUX(SDMMC2_DAT2, OMAP_PULL_ENA | OMAP_MUX_MODE0),
285         OMAP3_MUX(SDMMC2_DAT3, OMAP_PULL_ENA | OMAP_MUX_MODE0),
286         OMAP3_MUX(SDMMC2_DAT4, OMAP_PULL_ENA | OMAP_MUX_MODE0),
287         OMAP3_MUX(SDMMC2_DAT5, OMAP_PULL_ENA | OMAP_MUX_MODE0),
288         OMAP3_MUX(SDMMC2_DAT6, OMAP_PULL_ENA | OMAP_MUX_MODE0),
289         OMAP3_MUX(SDMMC2_DAT7, OMAP_PULL_ENA | OMAP_MUX_MODE0),
290         { .reg_offset = OMAP_MUX_TERMINATOR },
291 };
292
293 /*
294  * Current flows to eMMC when eMMC is off and the data lines are pulled up,
295  * so pull them down. N.B. we pull 8 lines because we are using 8 lines.
296  */
297 static void rx51_mmc2_remux(struct device *dev, int slot, int power_on)
298 {
299         if (power_on)
300                 omap_mux_write_array(rx51_mmc2_on_mux);
301         else
302                 omap_mux_write_array(rx51_mmc2_off_mux);
303 }
304
305 static struct omap2_hsmmc_info mmc[] __initdata = {
306         {
307                 .name           = "external",
308                 .mmc            = 1,
309                 .wires          = 4,
310                 .cover_only     = true,
311                 .gpio_cd        = 160,
312                 .gpio_wp        = -EINVAL,
313                 .power_saving   = true,
314         },
315         {
316                 .name           = "internal",
317                 .mmc            = 2,
318                 .wires          = 8, /* See also rx51_mmc2_remux */
319                 .gpio_cd        = -EINVAL,
320                 .gpio_wp        = -EINVAL,
321                 .nonremovable   = true,
322                 .power_saving   = true,
323                 .remux          = rx51_mmc2_remux,
324         },
325         {}      /* Terminator */
326 };
327
328 static struct regulator_consumer_supply rx51_vmmc1_supply =
329         REGULATOR_SUPPLY("vmmc", "mmci-omap-hs.0");
330
331 static struct regulator_consumer_supply rx51_vaux3_supply =
332         REGULATOR_SUPPLY("vmmc", "mmci-omap-hs.1");
333
334 static struct regulator_consumer_supply rx51_vsim_supply =
335         REGULATOR_SUPPLY("vmmc_aux", "mmci-omap-hs.1");
336
337 static struct regulator_consumer_supply rx51_vmmc2_supplies[] = {
338         /* tlv320aic3x analog supplies */
339         REGULATOR_SUPPLY("AVDD", "2-0018"),
340         REGULATOR_SUPPLY("DRVDD", "2-0018"),
341         /* tpa6130a2 */
342         REGULATOR_SUPPLY("Vdd", "2-0060"),
343         /* Keep vmmc as last item. It is not iterated for newer boards */
344         REGULATOR_SUPPLY("vmmc", "mmci-omap-hs.1"),
345 };
346
347 static struct regulator_consumer_supply rx51_vio_supplies[] = {
348         /* tlv320aic3x digital supplies */
349         REGULATOR_SUPPLY("IOVDD", "2-0018"),
350         REGULATOR_SUPPLY("DVDD", "2-0018"),
351 };
352
353 #if defined(CONFIG_FB_OMAP2) || defined(CONFIG_FB_OMAP2_MODULE)
354 extern struct platform_device rx51_display_device;
355 #endif
356
357 static struct regulator_consumer_supply rx51_vaux1_consumers[] = {
358 #if defined(CONFIG_FB_OMAP2) || defined(CONFIG_FB_OMAP2_MODULE)
359         {
360                 .supply = "vdds_sdi",
361                 .dev    = &rx51_display_device.dev,
362         },
363 #endif
364 };
365
366 static struct regulator_init_data rx51_vaux1 = {
367         .constraints = {
368                 .name                   = "V28",
369                 .min_uV                 = 2800000,
370                 .max_uV                 = 2800000,
371                 .always_on              = true, /* due battery cover sensor */
372                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
373                                         | REGULATOR_MODE_STANDBY,
374                 .valid_ops_mask         = REGULATOR_CHANGE_MODE
375                                         | REGULATOR_CHANGE_STATUS,
376         },
377         .num_consumer_supplies  = ARRAY_SIZE(rx51_vaux1_consumers),
378         .consumer_supplies      = rx51_vaux1_consumers,
379 };
380
381 static struct regulator_init_data rx51_vaux2 = {
382         .constraints = {
383                 .name                   = "VCSI",
384                 .min_uV                 = 1800000,
385                 .max_uV                 = 1800000,
386                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
387                                         | REGULATOR_MODE_STANDBY,
388                 .valid_ops_mask         = REGULATOR_CHANGE_MODE
389                                         | REGULATOR_CHANGE_STATUS,
390         },
391 };
392
393 /* VAUX3 - adds more power to VIO_18 rail */
394 static struct regulator_init_data rx51_vaux3_cam = {
395         .constraints = {
396                 .name                   = "VCAM_DIG_18",
397                 .min_uV                 = 1800000,
398                 .max_uV                 = 1800000,
399                 .apply_uV               = true,
400                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
401                                         | REGULATOR_MODE_STANDBY,
402                 .valid_ops_mask         = REGULATOR_CHANGE_MODE
403                                         | REGULATOR_CHANGE_STATUS,
404         },
405 };
406
407 static struct regulator_init_data rx51_vaux3_mmc = {
408         .constraints = {
409                 .name                   = "VMMC2_30",
410                 .min_uV                 = 2800000,
411                 .max_uV                 = 3000000,
412                 .apply_uV               = true,
413                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
414                                         | REGULATOR_MODE_STANDBY,
415                 .valid_ops_mask         = REGULATOR_CHANGE_VOLTAGE
416                                         | REGULATOR_CHANGE_MODE
417                                         | REGULATOR_CHANGE_STATUS,
418         },
419         .num_consumer_supplies  = 1,
420         .consumer_supplies      = &rx51_vaux3_supply,
421 };
422
423 static struct regulator_init_data rx51_vaux4 = {
424         .constraints = {
425                 .name                   = "VCAM_ANA_28",
426                 .min_uV                 = 2800000,
427                 .max_uV                 = 2800000,
428                 .apply_uV               = true,
429                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
430                                         | REGULATOR_MODE_STANDBY,
431                 .valid_ops_mask         = REGULATOR_CHANGE_MODE
432                                         | REGULATOR_CHANGE_STATUS,
433         },
434 };
435
436 static struct regulator_init_data rx51_vmmc1 = {
437         .constraints = {
438                 .min_uV                 = 1850000,
439                 .max_uV                 = 3150000,
440                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
441                                         | REGULATOR_MODE_STANDBY,
442                 .valid_ops_mask         = REGULATOR_CHANGE_VOLTAGE
443                                         | REGULATOR_CHANGE_MODE
444                                         | REGULATOR_CHANGE_STATUS,
445         },
446         .num_consumer_supplies  = 1,
447         .consumer_supplies      = &rx51_vmmc1_supply,
448 };
449
450 static struct regulator_init_data rx51_vmmc2 = {
451         .constraints = {
452                 .name                   = "V28_A",
453                 .min_uV                 = 2800000,
454                 .max_uV                 = 3000000,
455                 .apply_uV               = true,
456                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
457                                         | REGULATOR_MODE_STANDBY,
458                 .valid_ops_mask         = REGULATOR_CHANGE_VOLTAGE
459                                         | REGULATOR_CHANGE_MODE
460                                         | REGULATOR_CHANGE_STATUS,
461         },
462         .num_consumer_supplies  = ARRAY_SIZE(rx51_vmmc2_supplies),
463         .consumer_supplies      = rx51_vmmc2_supplies,
464 };
465
466 static struct regulator_init_data rx51_vsim = {
467         .constraints = {
468                 .name                   = "VMMC2_IO_18",
469                 .min_uV                 = 1800000,
470                 .max_uV                 = 1800000,
471                 .apply_uV               = true,
472                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
473                                         | REGULATOR_MODE_STANDBY,
474                 .valid_ops_mask         = REGULATOR_CHANGE_MODE
475                                         | REGULATOR_CHANGE_STATUS,
476         },
477         .num_consumer_supplies  = 1,
478         .consumer_supplies      = &rx51_vsim_supply,
479 };
480
481 static struct regulator_init_data rx51_vdac = {
482         .constraints = {
483                 .min_uV                 = 1800000,
484                 .max_uV                 = 1800000,
485                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
486                                         | REGULATOR_MODE_STANDBY,
487                 .valid_ops_mask         = REGULATOR_CHANGE_VOLTAGE
488                                         | REGULATOR_CHANGE_MODE
489                                         | REGULATOR_CHANGE_STATUS,
490         },
491 };
492
493 static struct regulator_init_data rx51_vio = {
494         .constraints = {
495                 .min_uV                 = 1800000,
496                 .max_uV                 = 1800000,
497                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
498                                         | REGULATOR_MODE_STANDBY,
499                 .valid_ops_mask         = REGULATOR_CHANGE_VOLTAGE
500                                         | REGULATOR_CHANGE_MODE
501                                         | REGULATOR_CHANGE_STATUS,
502         },
503         .num_consumer_supplies  = ARRAY_SIZE(rx51_vio_supplies),
504         .consumer_supplies      = rx51_vio_supplies,
505 };
506
507 static int rx51_twlgpio_setup(struct device *dev, unsigned gpio, unsigned n)
508 {
509         /* FIXME this gpio setup is just a placeholder for now */
510         gpio_request(gpio + 6, "backlight_pwm");
511         gpio_direction_output(gpio + 6, 0);
512         gpio_request(gpio + 7, "speaker_en");
513         gpio_direction_output(gpio + 7, 1);
514
515         return 0;
516 }
517
518 static struct twl4030_gpio_platform_data rx51_gpio_data = {
519         .gpio_base              = OMAP_MAX_GPIO_LINES,
520         .irq_base               = TWL4030_GPIO_IRQ_BASE,
521         .irq_end                = TWL4030_GPIO_IRQ_END,
522         .pulldowns              = BIT(0) | BIT(1) | BIT(2) | BIT(3)
523                                 | BIT(4) | BIT(5)
524                                 | BIT(8) | BIT(9) | BIT(10) | BIT(11)
525                                 | BIT(12) | BIT(13) | BIT(14) | BIT(15)
526                                 | BIT(16) | BIT(17) ,
527         .setup                  = rx51_twlgpio_setup,
528 };
529
530 static struct twl4030_usb_data rx51_usb_data = {
531         .usb_mode               = T2_USB_MODE_ULPI,
532 };
533
534 static struct twl4030_ins sleep_on_seq[] __initdata = {
535 /*
536  * Turn off everything
537  */
538         {MSG_BROADCAST(DEV_GRP_NULL, RES_GRP_ALL, 1, 0, RES_STATE_SLEEP), 2},
539 };
540
541 static struct twl4030_script sleep_on_script __initdata = {
542         .script = sleep_on_seq,
543         .size   = ARRAY_SIZE(sleep_on_seq),
544         .flags  = TWL4030_SLEEP_SCRIPT,
545 };
546
547 static struct twl4030_ins wakeup_seq[] __initdata = {
548 /*
549  * Reenable everything
550  */
551         {MSG_BROADCAST(DEV_GRP_NULL, RES_GRP_ALL, 1, 0, RES_STATE_ACTIVE), 2},
552 };
553
554 static struct twl4030_script wakeup_script __initdata = {
555         .script = wakeup_seq,
556         .size   = ARRAY_SIZE(wakeup_seq),
557         .flags  = TWL4030_WAKEUP12_SCRIPT,
558 };
559
560 static struct twl4030_ins wakeup_p3_seq[] __initdata = {
561 /*
562  * Reenable everything
563  */
564         {MSG_BROADCAST(DEV_GRP_NULL, RES_GRP_ALL, 1, 0, RES_STATE_ACTIVE), 2},
565 };
566
567 static struct twl4030_script wakeup_p3_script __initdata = {
568         .script = wakeup_p3_seq,
569         .size   = ARRAY_SIZE(wakeup_p3_seq),
570         .flags  = TWL4030_WAKEUP3_SCRIPT,
571 };
572
573 static struct twl4030_ins wrst_seq[] __initdata = {
574 /*
575  * Reset twl4030.
576  * Reset VDD1 regulator.
577  * Reset VDD2 regulator.
578  * Reset VPLL1 regulator.
579  * Enable sysclk output.
580  * Reenable twl4030.
581  */
582         {MSG_SINGULAR(DEV_GRP_NULL, RES_RESET, RES_STATE_OFF), 2},
583         {MSG_BROADCAST(DEV_GRP_NULL, RES_GRP_ALL, 0, 1, RES_STATE_ACTIVE),
584                 0x13},
585         {MSG_BROADCAST(DEV_GRP_NULL, RES_GRP_PP, 0, 3, RES_STATE_OFF), 0x13},
586         {MSG_SINGULAR(DEV_GRP_NULL, RES_VDD1, RES_STATE_WRST), 0x13},
587         {MSG_SINGULAR(DEV_GRP_NULL, RES_VDD2, RES_STATE_WRST), 0x13},
588         {MSG_SINGULAR(DEV_GRP_NULL, RES_VPLL1, RES_STATE_WRST), 0x35},
589         {MSG_SINGULAR(DEV_GRP_P3, RES_HFCLKOUT, RES_STATE_ACTIVE), 2},
590         {MSG_SINGULAR(DEV_GRP_NULL, RES_RESET, RES_STATE_ACTIVE), 2},
591 };
592
593 static struct twl4030_script wrst_script __initdata = {
594         .script = wrst_seq,
595         .size   = ARRAY_SIZE(wrst_seq),
596         .flags  = TWL4030_WRST_SCRIPT,
597 };
598
599 static struct twl4030_script *twl4030_scripts[] __initdata = {
600         /* wakeup12 script should be loaded before sleep script, otherwise a
601            board might hit retention before loading of wakeup script is
602            completed. This can cause boot failures depending on timing issues.
603         */
604         &wakeup_script,
605         &sleep_on_script,
606         &wakeup_p3_script,
607         &wrst_script,
608 };
609
610 static struct twl4030_resconfig twl4030_rconfig[] __initdata = {
611         { .resource = RES_VDD1, .devgroup = -1,
612           .type = 1, .type2 = -1, .remap_off = RES_STATE_OFF,
613           .remap_sleep = RES_STATE_OFF
614         },
615         { .resource = RES_VDD2, .devgroup = -1,
616           .type = 1, .type2 = -1, .remap_off = RES_STATE_OFF,
617           .remap_sleep = RES_STATE_OFF
618         },
619         { .resource = RES_VPLL1, .devgroup = -1,
620           .type = 1, .type2 = -1, .remap_off = RES_STATE_OFF,
621           .remap_sleep = RES_STATE_OFF
622         },
623         { .resource = RES_VPLL2, .devgroup = -1,
624           .type = -1, .type2 = 3, .remap_off = -1, .remap_sleep = -1
625         },
626         { .resource = RES_VAUX1, .devgroup = -1,
627           .type = -1, .type2 = 3, .remap_off = -1, .remap_sleep = -1
628         },
629         { .resource = RES_VAUX2, .devgroup = -1,
630           .type = -1, .type2 = 3, .remap_off = -1, .remap_sleep = -1
631         },
632         { .resource = RES_VAUX3, .devgroup = -1,
633           .type = -1, .type2 = 3, .remap_off = -1, .remap_sleep = -1
634         },
635         { .resource = RES_VAUX4, .devgroup = -1,
636           .type = -1, .type2 = 3, .remap_off = -1, .remap_sleep = -1
637         },
638         { .resource = RES_VMMC1, .devgroup = -1,
639           .type = -1, .type2 = 3, .remap_off = -1, .remap_sleep = -1
640         },
641         { .resource = RES_VMMC2, .devgroup = -1,
642           .type = -1, .type2 = 3, .remap_off = -1, .remap_sleep = -1
643         },
644         { .resource = RES_VDAC, .devgroup = -1,
645           .type = -1, .type2 = 3, .remap_off = -1, .remap_sleep = -1
646         },
647         { .resource = RES_VSIM, .devgroup = -1,
648           .type = -1, .type2 = 3, .remap_off = -1, .remap_sleep = -1
649         },
650         { .resource = RES_VINTANA1, .devgroup = DEV_GRP_P1 | DEV_GRP_P3,
651           .type = -1, .type2 = -1, .remap_off = -1, .remap_sleep = -1
652         },
653         { .resource = RES_VINTANA2, .devgroup = DEV_GRP_P1 | DEV_GRP_P3,
654           .type = 1, .type2 = -1, .remap_off = -1, .remap_sleep = -1
655         },
656         { .resource = RES_VINTDIG, .devgroup = DEV_GRP_P1 | DEV_GRP_P3,
657           .type = -1, .type2 = -1, .remap_off = -1, .remap_sleep = -1
658         },
659         { .resource = RES_VIO, .devgroup = DEV_GRP_P3,
660           .type = 1, .type2 = -1, .remap_off = -1, .remap_sleep = -1
661         },
662         { .resource = RES_CLKEN, .devgroup = DEV_GRP_P1 | DEV_GRP_P3,
663           .type = 1, .type2 = -1 , .remap_off = -1, .remap_sleep = -1
664         },
665         { .resource = RES_REGEN, .devgroup = DEV_GRP_P1 | DEV_GRP_P3,
666           .type = 1, .type2 = -1, .remap_off = -1, .remap_sleep = -1
667         },
668         { .resource = RES_NRES_PWRON, .devgroup = DEV_GRP_P1 | DEV_GRP_P3,
669           .type = 1, .type2 = -1, .remap_off = -1, .remap_sleep = -1
670         },
671         { .resource = RES_SYSEN, .devgroup = DEV_GRP_P1 | DEV_GRP_P3,
672           .type = 1, .type2 = -1, .remap_off = -1, .remap_sleep = -1
673         },
674         { .resource = RES_HFCLKOUT, .devgroup = DEV_GRP_P3,
675           .type = 1, .type2 = -1, .remap_off = -1, .remap_sleep = -1
676         },
677         { .resource = RES_32KCLKOUT, .devgroup = -1,
678           .type = 1, .type2 = -1, .remap_off = -1, .remap_sleep = -1
679         },
680         { .resource = RES_RESET, .devgroup = -1,
681           .type = 1, .type2 = -1, .remap_off = -1, .remap_sleep = -1
682         },
683         { .resource = RES_Main_Ref, .devgroup = -1,
684           .type = 1, .type2 = -1, .remap_off = -1, .remap_sleep = -1
685         },
686         { 0, 0},
687 };
688
689 static struct twl4030_power_data rx51_t2scripts_data __initdata = {
690         .scripts        = twl4030_scripts,
691         .num = ARRAY_SIZE(twl4030_scripts),
692         .resource_config = twl4030_rconfig,
693 };
694
695
696
697 static struct twl4030_platform_data rx51_twldata __initdata = {
698         .irq_base               = TWL4030_IRQ_BASE,
699         .irq_end                = TWL4030_IRQ_END,
700
701         /* platform_data for children goes here */
702         .gpio                   = &rx51_gpio_data,
703         .keypad                 = &rx51_kp_data,
704         .madc                   = &rx51_madc_data,
705         .usb                    = &rx51_usb_data,
706         .power                  = &rx51_t2scripts_data,
707
708         .vaux1                  = &rx51_vaux1,
709         .vaux2                  = &rx51_vaux2,
710         .vaux4                  = &rx51_vaux4,
711         .vmmc1                  = &rx51_vmmc1,
712         .vsim                   = &rx51_vsim,
713         .vdac                   = &rx51_vdac,
714         .vio                    = &rx51_vio,
715 };
716
717 static struct aic3x_pdata rx51_aic3x_data __initdata = {
718         .gpio_reset             = 60,
719 };
720
721 static struct tpa6130a2_platform_data rx51_tpa6130a2_data __initdata = {
722         .id                     = TPA6130A2,
723         .power_gpio             = 98,
724 };
725
726 static struct i2c_board_info __initdata rx51_peripherals_i2c_board_info_1[] = {
727         {
728                 I2C_BOARD_INFO("twl5030", 0x48),
729                 .flags = I2C_CLIENT_WAKE,
730                 .irq = INT_34XX_SYS_NIRQ,
731                 .platform_data = &rx51_twldata,
732         },
733 };
734
735 static struct i2c_board_info __initdata rx51_peripherals_i2c_board_info_2[] = {
736         {
737                 I2C_BOARD_INFO("tlv320aic3x", 0x18),
738                 .platform_data = &rx51_aic3x_data,
739         },
740 #if defined(CONFIG_SENSORS_TSL2563) || defined(CONFIG_SENSORS_TSL2563_MODULE)
741         {
742                 I2C_BOARD_INFO("tsl2563", 0x29),
743                 .platform_data = &rx51_tsl2563_platform_data,
744         },
745 #endif
746         {
747                 I2C_BOARD_INFO("tpa6130a2", 0x60),
748                 .platform_data = &rx51_tpa6130a2_data,
749         }
750 };
751
752 static int __init rx51_i2c_init(void)
753 {
754         if ((system_rev >= SYSTEM_REV_S_USES_VAUX3 && system_rev < 0x100) ||
755             system_rev >= SYSTEM_REV_B_USES_VAUX3) {
756                 rx51_twldata.vaux3 = &rx51_vaux3_mmc;
757                 /* Only older boards use VMMC2 for internal MMC */
758                 rx51_vmmc2.num_consumer_supplies--;
759         } else {
760                 rx51_twldata.vaux3 = &rx51_vaux3_cam;
761         }
762         rx51_twldata.vmmc2 = &rx51_vmmc2;
763         omap_register_i2c_bus(1, 2200, rx51_peripherals_i2c_board_info_1,
764                               ARRAY_SIZE(rx51_peripherals_i2c_board_info_1));
765         omap_register_i2c_bus(2, 100, rx51_peripherals_i2c_board_info_2,
766                               ARRAY_SIZE(rx51_peripherals_i2c_board_info_2));
767         omap_register_i2c_bus(3, 400, NULL, 0);
768         return 0;
769 }
770
771 #if defined(CONFIG_MTD_ONENAND_OMAP2) || \
772         defined(CONFIG_MTD_ONENAND_OMAP2_MODULE)
773
774 static struct mtd_partition onenand_partitions[] = {
775         {
776                 .name           = "bootloader",
777                 .offset         = 0,
778                 .size           = 0x20000,
779                 .mask_flags     = MTD_WRITEABLE,        /* Force read-only */
780         },
781         {
782                 .name           = "config",
783                 .offset         = MTDPART_OFS_APPEND,
784                 .size           = 0x60000,
785         },
786         {
787                 .name           = "log",
788                 .offset         = MTDPART_OFS_APPEND,
789                 .size           = 0x40000,
790         },
791         {
792                 .name           = "kernel",
793                 .offset         = MTDPART_OFS_APPEND,
794                 .size           = 0x200000,
795         },
796         {
797                 .name           = "initfs",
798                 .offset         = MTDPART_OFS_APPEND,
799                 .size           = 0x200000,
800         },
801         {
802                 .name           = "rootfs",
803                 .offset         = MTDPART_OFS_APPEND,
804                 .size           = MTDPART_SIZ_FULL,
805         },
806 };
807
808 static struct omap_onenand_platform_data board_onenand_data = {
809         .cs             = 0,
810         .gpio_irq       = 65,
811         .parts          = onenand_partitions,
812         .nr_parts       = ARRAY_SIZE(onenand_partitions),
813         .flags          = ONENAND_SYNC_READWRITE,
814 };
815
816 static void __init board_onenand_init(void)
817 {
818         gpmc_onenand_init(&board_onenand_data);
819 }
820
821 #else
822
823 static inline void board_onenand_init(void)
824 {
825 }
826
827 #endif
828
829 #if defined(CONFIG_SMC91X) || defined(CONFIG_SMC91X_MODULE)
830
831 static struct omap_smc91x_platform_data board_smc91x_data = {
832         .cs             = 1,
833         .gpio_irq       = 54,
834         .gpio_pwrdwn    = 86,
835         .gpio_reset     = 164,
836         .flags          = GPMC_TIMINGS_SMC91C96 | IORESOURCE_IRQ_HIGHLEVEL,
837 };
838
839 static void __init board_smc91x_init(void)
840 {
841         omap_mux_init_gpio(54, OMAP_PIN_INPUT_PULLDOWN);
842         omap_mux_init_gpio(86, OMAP_PIN_OUTPUT);
843         omap_mux_init_gpio(164, OMAP_PIN_OUTPUT);
844
845         gpmc_smc91x_init(&board_smc91x_data);
846 }
847
848 #else
849
850 static inline void board_smc91x_init(void)
851 {
852 }
853
854 #endif
855
856 static void rx51_wl1251_set_power(bool enable)
857 {
858         gpio_set_value(RX51_WL1251_POWER_GPIO, enable);
859 }
860
861 static void __init rx51_init_wl1251(void)
862 {
863         int irq, ret;
864
865         ret = gpio_request(RX51_WL1251_POWER_GPIO, "wl1251 power");
866         if (ret < 0)
867                 goto error;
868
869         ret = gpio_direction_output(RX51_WL1251_POWER_GPIO, 0);
870         if (ret < 0)
871                 goto err_power;
872
873         ret = gpio_request(RX51_WL1251_IRQ_GPIO, "wl1251 irq");
874         if (ret < 0)
875                 goto err_power;
876
877         ret = gpio_direction_input(RX51_WL1251_IRQ_GPIO);
878         if (ret < 0)
879                 goto err_irq;
880
881         irq = gpio_to_irq(RX51_WL1251_IRQ_GPIO);
882         if (irq < 0)
883                 goto err_irq;
884
885         wl1251_pdata.set_power = rx51_wl1251_set_power;
886         rx51_peripherals_spi_board_info[RX51_SPI_WL1251].irq = irq;
887
888         return;
889
890 err_irq:
891         gpio_free(RX51_WL1251_IRQ_GPIO);
892
893 err_power:
894         gpio_free(RX51_WL1251_POWER_GPIO);
895
896 error:
897         printk(KERN_ERR "wl1251 board initialisation failed\n");
898         wl1251_pdata.set_power = NULL;
899
900         /*
901          * Now rx51_peripherals_spi_board_info[1].irq is zero and
902          * set_power is null, and wl1251_probe() will fail.
903          */
904 }
905
906 void __init rx51_peripherals_init(void)
907 {
908         rx51_i2c_init();
909         board_onenand_init();
910         board_smc91x_init();
911         rx51_add_gpio_keys();
912         rx51_init_wl1251();
913         spi_register_board_info(rx51_peripherals_spi_board_info,
914                                 ARRAY_SIZE(rx51_peripherals_spi_board_info));
915         omap2_hsmmc_init(mmc);
916         platform_device_register(&rx51_charger_device);
917 }
918