Merge branch 'perf-fixes-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[pandora-kernel.git] / arch / arm / mach-omap2 / board-4430sdp.c
1 /*
2  * Board support file for OMAP4430 SDP.
3  *
4  * Copyright (C) 2009 Texas Instruments
5  *
6  * Author: Santosh Shilimkar <santosh.shilimkar@ti.com>
7  *
8  * Based on mach-omap2/board-3430sdp.c
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/io.h>
19 #include <linux/gpio.h>
20 #include <linux/usb/otg.h>
21 #include <linux/spi/spi.h>
22 #include <linux/i2c/twl.h>
23 #include <linux/gpio_keys.h>
24 #include <linux/regulator/machine.h>
25 #include <linux/leds.h>
26 #include <linux/leds_pwm.h>
27
28 #include <mach/hardware.h>
29 #include <mach/omap4-common.h>
30 #include <asm/mach-types.h>
31 #include <asm/mach/arch.h>
32 #include <asm/mach/map.h>
33
34 #include <plat/board.h>
35 #include <plat/common.h>
36 #include <plat/usb.h>
37 #include <plat/mmc.h>
38
39 #include "mux.h"
40 #include "hsmmc.h"
41 #include "timer-gp.h"
42 #include "control.h"
43
44 #define ETH_KS8851_IRQ                  34
45 #define ETH_KS8851_POWER_ON             48
46 #define ETH_KS8851_QUART                138
47 #define OMAP4SDP_MDM_PWR_EN_GPIO        157
48 #define OMAP4_SFH7741_SENSOR_OUTPUT_GPIO        184
49 #define OMAP4_SFH7741_ENABLE_GPIO               188
50
51 static struct gpio_led sdp4430_gpio_leds[] = {
52         {
53                 .name   = "omap4:green:debug0",
54                 .gpio   = 61,
55         },
56         {
57                 .name   = "omap4:green:debug1",
58                 .gpio   = 30,
59         },
60         {
61                 .name   = "omap4:green:debug2",
62                 .gpio   = 7,
63         },
64         {
65                 .name   = "omap4:green:debug3",
66                 .gpio   = 8,
67         },
68         {
69                 .name   = "omap4:green:debug4",
70                 .gpio   = 50,
71         },
72         {
73                 .name   = "omap4:blue:user",
74                 .gpio   = 169,
75         },
76         {
77                 .name   = "omap4:red:user",
78                 .gpio   = 170,
79         },
80         {
81                 .name   = "omap4:green:user",
82                 .gpio   = 139,
83         },
84
85 };
86
87 static struct gpio_keys_button sdp4430_gpio_keys[] = {
88         {
89                 .desc                   = "Proximity Sensor",
90                 .type                   = EV_SW,
91                 .code                   = SW_FRONT_PROXIMITY,
92                 .gpio                   = OMAP4_SFH7741_SENSOR_OUTPUT_GPIO,
93                 .active_low             = 0,
94         }
95 };
96
97 static struct gpio_led_platform_data sdp4430_led_data = {
98         .leds   = sdp4430_gpio_leds,
99         .num_leds       = ARRAY_SIZE(sdp4430_gpio_leds),
100 };
101
102 static struct led_pwm sdp4430_pwm_leds[] = {
103         {
104                 .name           = "omap4:green:chrg",
105                 .pwm_id         = 1,
106                 .max_brightness = 255,
107                 .pwm_period_ns  = 7812500,
108         },
109 };
110
111 static struct led_pwm_platform_data sdp4430_pwm_data = {
112         .num_leds       = ARRAY_SIZE(sdp4430_pwm_leds),
113         .leds           = sdp4430_pwm_leds,
114 };
115
116 static struct platform_device sdp4430_leds_pwm = {
117         .name   = "leds_pwm",
118         .id     = -1,
119         .dev    = {
120                 .platform_data = &sdp4430_pwm_data,
121         },
122 };
123
124 static int omap_prox_activate(struct device *dev)
125 {
126         gpio_set_value(OMAP4_SFH7741_ENABLE_GPIO , 1);
127         return 0;
128 }
129
130 static void omap_prox_deactivate(struct device *dev)
131 {
132         gpio_set_value(OMAP4_SFH7741_ENABLE_GPIO , 0);
133 }
134
135 static struct gpio_keys_platform_data sdp4430_gpio_keys_data = {
136         .buttons        = sdp4430_gpio_keys,
137         .nbuttons       = ARRAY_SIZE(sdp4430_gpio_keys),
138         .enable         = omap_prox_activate,
139         .disable        = omap_prox_deactivate,
140 };
141
142 static struct platform_device sdp4430_gpio_keys_device = {
143         .name   = "gpio-keys",
144         .id     = -1,
145         .dev    = {
146                 .platform_data  = &sdp4430_gpio_keys_data,
147         },
148 };
149
150 static struct platform_device sdp4430_leds_gpio = {
151         .name   = "leds-gpio",
152         .id     = -1,
153         .dev    = {
154                 .platform_data = &sdp4430_led_data,
155         },
156 };
157 static struct spi_board_info sdp4430_spi_board_info[] __initdata = {
158         {
159                 .modalias               = "ks8851",
160                 .bus_num                = 1,
161                 .chip_select            = 0,
162                 .max_speed_hz           = 24000000,
163                 .irq                    = ETH_KS8851_IRQ,
164         },
165 };
166
167 static int omap_ethernet_init(void)
168 {
169         int status;
170
171         /* Request of GPIO lines */
172
173         status = gpio_request(ETH_KS8851_POWER_ON, "eth_power");
174         if (status) {
175                 pr_err("Cannot request GPIO %d\n", ETH_KS8851_POWER_ON);
176                 return status;
177         }
178
179         status = gpio_request(ETH_KS8851_QUART, "quart");
180         if (status) {
181                 pr_err("Cannot request GPIO %d\n", ETH_KS8851_QUART);
182                 goto error1;
183         }
184
185         status = gpio_request(ETH_KS8851_IRQ, "eth_irq");
186         if (status) {
187                 pr_err("Cannot request GPIO %d\n", ETH_KS8851_IRQ);
188                 goto error2;
189         }
190
191         /* Configuration of requested GPIO lines */
192
193         status = gpio_direction_output(ETH_KS8851_POWER_ON, 1);
194         if (status) {
195                 pr_err("Cannot set output GPIO %d\n", ETH_KS8851_IRQ);
196                 goto error3;
197         }
198
199         status = gpio_direction_output(ETH_KS8851_QUART, 1);
200         if (status) {
201                 pr_err("Cannot set output GPIO %d\n", ETH_KS8851_QUART);
202                 goto error3;
203         }
204
205         status = gpio_direction_input(ETH_KS8851_IRQ);
206         if (status) {
207                 pr_err("Cannot set input GPIO %d\n", ETH_KS8851_IRQ);
208                 goto error3;
209         }
210
211         return 0;
212
213 error3:
214         gpio_free(ETH_KS8851_IRQ);
215 error2:
216         gpio_free(ETH_KS8851_QUART);
217 error1:
218         gpio_free(ETH_KS8851_POWER_ON);
219         return status;
220 }
221
222 static struct platform_device sdp4430_lcd_device = {
223         .name           = "sdp4430_lcd",
224         .id             = -1,
225 };
226
227 static struct platform_device *sdp4430_devices[] __initdata = {
228         &sdp4430_lcd_device,
229         &sdp4430_gpio_keys_device,
230         &sdp4430_leds_gpio,
231         &sdp4430_leds_pwm,
232 };
233
234 static struct omap_lcd_config sdp4430_lcd_config __initdata = {
235         .ctrl_name      = "internal",
236 };
237
238 static struct omap_board_config_kernel sdp4430_config[] __initdata = {
239         { OMAP_TAG_LCD,         &sdp4430_lcd_config },
240 };
241
242 static void __init omap_4430sdp_init_irq(void)
243 {
244         omap_board_config = sdp4430_config;
245         omap_board_config_size = ARRAY_SIZE(sdp4430_config);
246         omap2_init_common_infrastructure();
247         omap2_init_common_devices(NULL, NULL);
248 #ifdef CONFIG_OMAP_32K_TIMER
249         omap2_gp_clockevent_set_gptimer(1);
250 #endif
251         gic_init_irq();
252 }
253
254 static const struct ehci_hcd_omap_platform_data ehci_pdata __initconst = {
255         .port_mode[0]   = EHCI_HCD_OMAP_MODE_PHY,
256         .port_mode[1]   = EHCI_HCD_OMAP_MODE_UNKNOWN,
257         .port_mode[2]   = EHCI_HCD_OMAP_MODE_UNKNOWN,
258         .phy_reset      = false,
259         .reset_gpio_port[0]  = -EINVAL,
260         .reset_gpio_port[1]  = -EINVAL,
261         .reset_gpio_port[2]  = -EINVAL,
262 };
263
264 static struct omap_musb_board_data musb_board_data = {
265         .interface_type         = MUSB_INTERFACE_UTMI,
266         .mode                   = MUSB_OTG,
267         .power                  = 100,
268 };
269
270 static struct twl4030_usb_data omap4_usbphy_data = {
271         .phy_init       = omap4430_phy_init,
272         .phy_exit       = omap4430_phy_exit,
273         .phy_power      = omap4430_phy_power,
274         .phy_set_clock  = omap4430_phy_set_clk,
275 };
276
277 static struct omap2_hsmmc_info mmc[] = {
278         {
279                 .mmc            = 1,
280                 .caps           = MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA,
281                 .gpio_wp        = -EINVAL,
282         },
283         {
284                 .mmc            = 2,
285                 .caps           =  MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA,
286                 .gpio_cd        = -EINVAL,
287                 .gpio_wp        = -EINVAL,
288                 .nonremovable   = true,
289                 .ocr_mask       = MMC_VDD_29_30,
290         },
291         {}      /* Terminator */
292 };
293
294 static struct regulator_consumer_supply sdp4430_vaux_supply[] = {
295         {
296                 .supply = "vmmc",
297                 .dev_name = "mmci-omap-hs.1",
298         },
299 };
300 static struct regulator_consumer_supply sdp4430_vmmc_supply[] = {
301         {
302                 .supply = "vmmc",
303                 .dev_name = "mmci-omap-hs.0",
304         },
305 };
306
307 static int omap4_twl6030_hsmmc_late_init(struct device *dev)
308 {
309         int ret = 0;
310         struct platform_device *pdev = container_of(dev,
311                                 struct platform_device, dev);
312         struct omap_mmc_platform_data *pdata = dev->platform_data;
313
314         /* Setting MMC1 Card detect Irq */
315         if (pdev->id == 0) {
316                 ret = twl6030_mmc_card_detect_config();
317                 if (ret)
318                         pr_err("Failed configuring MMC1 card detect\n");
319                 pdata->slots[0].card_detect_irq = TWL6030_IRQ_BASE +
320                                                 MMCDETECT_INTR_OFFSET;
321                 pdata->slots[0].card_detect = twl6030_mmc_card_detect;
322         }
323         return ret;
324 }
325
326 static __init void omap4_twl6030_hsmmc_set_late_init(struct device *dev)
327 {
328         struct omap_mmc_platform_data *pdata;
329
330         /* dev can be null if CONFIG_MMC_OMAP_HS is not set */
331         if (!dev) {
332                 pr_err("Failed %s\n", __func__);
333                 return;
334         }
335         pdata = dev->platform_data;
336         pdata->init =   omap4_twl6030_hsmmc_late_init;
337 }
338
339 static int __init omap4_twl6030_hsmmc_init(struct omap2_hsmmc_info *controllers)
340 {
341         struct omap2_hsmmc_info *c;
342
343         omap2_hsmmc_init(controllers);
344         for (c = controllers; c->mmc; c++)
345                 omap4_twl6030_hsmmc_set_late_init(c->dev);
346
347         return 0;
348 }
349
350 static struct regulator_init_data sdp4430_vaux1 = {
351         .constraints = {
352                 .min_uV                 = 1000000,
353                 .max_uV                 = 3000000,
354                 .apply_uV               = true,
355                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
356                                         | REGULATOR_MODE_STANDBY,
357                 .valid_ops_mask  = REGULATOR_CHANGE_VOLTAGE
358                                         | REGULATOR_CHANGE_MODE
359                                         | REGULATOR_CHANGE_STATUS,
360         },
361         .num_consumer_supplies  = 1,
362         .consumer_supplies      = sdp4430_vaux_supply,
363 };
364
365 static struct regulator_init_data sdp4430_vaux2 = {
366         .constraints = {
367                 .min_uV                 = 1200000,
368                 .max_uV                 = 2800000,
369                 .apply_uV               = true,
370                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
371                                         | REGULATOR_MODE_STANDBY,
372                 .valid_ops_mask  = REGULATOR_CHANGE_VOLTAGE
373                                         | REGULATOR_CHANGE_MODE
374                                         | REGULATOR_CHANGE_STATUS,
375         },
376 };
377
378 static struct regulator_init_data sdp4430_vaux3 = {
379         .constraints = {
380                 .min_uV                 = 1000000,
381                 .max_uV                 = 3000000,
382                 .apply_uV               = true,
383                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
384                                         | REGULATOR_MODE_STANDBY,
385                 .valid_ops_mask  = REGULATOR_CHANGE_VOLTAGE
386                                         | REGULATOR_CHANGE_MODE
387                                         | REGULATOR_CHANGE_STATUS,
388         },
389 };
390
391 /* VMMC1 for MMC1 card */
392 static struct regulator_init_data sdp4430_vmmc = {
393         .constraints = {
394                 .min_uV                 = 1200000,
395                 .max_uV                 = 3000000,
396                 .apply_uV               = true,
397                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
398                                         | REGULATOR_MODE_STANDBY,
399                 .valid_ops_mask  = REGULATOR_CHANGE_VOLTAGE
400                                         | REGULATOR_CHANGE_MODE
401                                         | REGULATOR_CHANGE_STATUS,
402         },
403         .num_consumer_supplies  = 1,
404         .consumer_supplies      = sdp4430_vmmc_supply,
405 };
406
407 static struct regulator_init_data sdp4430_vpp = {
408         .constraints = {
409                 .min_uV                 = 1800000,
410                 .max_uV                 = 2500000,
411                 .apply_uV               = true,
412                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
413                                         | REGULATOR_MODE_STANDBY,
414                 .valid_ops_mask  = REGULATOR_CHANGE_VOLTAGE
415                                         | REGULATOR_CHANGE_MODE
416                                         | REGULATOR_CHANGE_STATUS,
417         },
418 };
419
420 static struct regulator_init_data sdp4430_vusim = {
421         .constraints = {
422                 .min_uV                 = 1200000,
423                 .max_uV                 = 2900000,
424                 .apply_uV               = true,
425                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
426                                         | REGULATOR_MODE_STANDBY,
427                 .valid_ops_mask  = REGULATOR_CHANGE_VOLTAGE
428                                         | REGULATOR_CHANGE_MODE
429                                         | REGULATOR_CHANGE_STATUS,
430         },
431 };
432
433 static struct regulator_init_data sdp4430_vana = {
434         .constraints = {
435                 .min_uV                 = 2100000,
436                 .max_uV                 = 2100000,
437                 .apply_uV               = true,
438                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
439                                         | REGULATOR_MODE_STANDBY,
440                 .valid_ops_mask  = REGULATOR_CHANGE_MODE
441                                         | REGULATOR_CHANGE_STATUS,
442         },
443 };
444
445 static struct regulator_init_data sdp4430_vcxio = {
446         .constraints = {
447                 .min_uV                 = 1800000,
448                 .max_uV                 = 1800000,
449                 .apply_uV               = true,
450                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
451                                         | REGULATOR_MODE_STANDBY,
452                 .valid_ops_mask  = REGULATOR_CHANGE_MODE
453                                         | REGULATOR_CHANGE_STATUS,
454         },
455 };
456
457 static struct regulator_init_data sdp4430_vdac = {
458         .constraints = {
459                 .min_uV                 = 1800000,
460                 .max_uV                 = 1800000,
461                 .apply_uV               = true,
462                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
463                                         | REGULATOR_MODE_STANDBY,
464                 .valid_ops_mask  = REGULATOR_CHANGE_MODE
465                                         | REGULATOR_CHANGE_STATUS,
466         },
467 };
468
469 static struct regulator_init_data sdp4430_vusb = {
470         .constraints = {
471                 .min_uV                 = 3300000,
472                 .max_uV                 = 3300000,
473                 .apply_uV               = true,
474                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
475                                         | REGULATOR_MODE_STANDBY,
476                 .valid_ops_mask  =      REGULATOR_CHANGE_MODE
477                                         | REGULATOR_CHANGE_STATUS,
478         },
479 };
480
481 static struct twl4030_platform_data sdp4430_twldata = {
482         .irq_base       = TWL6030_IRQ_BASE,
483         .irq_end        = TWL6030_IRQ_END,
484
485         /* Regulators */
486         .vmmc           = &sdp4430_vmmc,
487         .vpp            = &sdp4430_vpp,
488         .vusim          = &sdp4430_vusim,
489         .vana           = &sdp4430_vana,
490         .vcxio          = &sdp4430_vcxio,
491         .vdac           = &sdp4430_vdac,
492         .vusb           = &sdp4430_vusb,
493         .vaux1          = &sdp4430_vaux1,
494         .vaux2          = &sdp4430_vaux2,
495         .vaux3          = &sdp4430_vaux3,
496         .usb            = &omap4_usbphy_data
497 };
498
499 static struct i2c_board_info __initdata sdp4430_i2c_boardinfo[] = {
500         {
501                 I2C_BOARD_INFO("twl6030", 0x48),
502                 .flags = I2C_CLIENT_WAKE,
503                 .irq = OMAP44XX_IRQ_SYS_1N,
504                 .platform_data = &sdp4430_twldata,
505         },
506 };
507 static struct i2c_board_info __initdata sdp4430_i2c_3_boardinfo[] = {
508         {
509                 I2C_BOARD_INFO("tmp105", 0x48),
510         },
511         {
512                 I2C_BOARD_INFO("bh1780", 0x29),
513         },
514 };
515 static struct i2c_board_info __initdata sdp4430_i2c_4_boardinfo[] = {
516         {
517                 I2C_BOARD_INFO("hmc5843", 0x1e),
518         },
519 };
520 static int __init omap4_i2c_init(void)
521 {
522         /*
523          * Phoenix Audio IC needs I2C1 to
524          * start with 400 KHz or less
525          */
526         omap_register_i2c_bus(1, 400, sdp4430_i2c_boardinfo,
527                         ARRAY_SIZE(sdp4430_i2c_boardinfo));
528         omap_register_i2c_bus(2, 400, NULL, 0);
529         omap_register_i2c_bus(3, 400, sdp4430_i2c_3_boardinfo,
530                                 ARRAY_SIZE(sdp4430_i2c_3_boardinfo));
531         omap_register_i2c_bus(4, 400, sdp4430_i2c_4_boardinfo,
532                                 ARRAY_SIZE(sdp4430_i2c_4_boardinfo));
533         return 0;
534 }
535
536 static void __init omap_sfh7741prox_init(void)
537 {
538         int  error;
539
540         error = gpio_request(OMAP4_SFH7741_ENABLE_GPIO, "sfh7741");
541         if (error < 0) {
542                 pr_err("%s:failed to request GPIO %d, error %d\n",
543                         __func__, OMAP4_SFH7741_ENABLE_GPIO, error);
544                 return;
545         }
546
547         error = gpio_direction_output(OMAP4_SFH7741_ENABLE_GPIO , 0);
548         if (error < 0) {
549                 pr_err("%s: GPIO configuration failed: GPIO %d,error %d\n",
550                          __func__, OMAP4_SFH7741_ENABLE_GPIO, error);
551                 gpio_free(OMAP4_SFH7741_ENABLE_GPIO);
552         }
553 }
554
555 #ifdef CONFIG_OMAP_MUX
556 static struct omap_board_mux board_mux[] __initdata = {
557         OMAP4_MUX(USBB2_ULPITLL_CLK, OMAP_MUX_MODE4 | OMAP_PIN_OUTPUT),
558         { .reg_offset = OMAP_MUX_TERMINATOR },
559 };
560 #else
561 #define board_mux       NULL
562 #endif
563
564 static void __init omap_4430sdp_init(void)
565 {
566         int status;
567         int package = OMAP_PACKAGE_CBS;
568
569         if (omap_rev() == OMAP4430_REV_ES1_0)
570                 package = OMAP_PACKAGE_CBL;
571         omap4_mux_init(board_mux, package);
572
573         omap4_i2c_init();
574         omap_sfh7741prox_init();
575         platform_add_devices(sdp4430_devices, ARRAY_SIZE(sdp4430_devices));
576         omap_serial_init();
577         omap4_twl6030_hsmmc_init(mmc);
578
579         /* Power on the ULPI PHY */
580         status = gpio_request(OMAP4SDP_MDM_PWR_EN_GPIO, "USBB1 PHY VMDM_3V3");
581         if (status)
582                 pr_err("%s: Could not get USBB1 PHY GPIO\n", __func__);
583         else
584                 gpio_direction_output(OMAP4SDP_MDM_PWR_EN_GPIO, 1);
585
586         usb_ehci_init(&ehci_pdata);
587         usb_musb_init(&musb_board_data);
588
589         status = omap_ethernet_init();
590         if (status) {
591                 pr_err("Ethernet initialization failed: %d\n", status);
592         } else {
593                 sdp4430_spi_board_info[0].irq = gpio_to_irq(ETH_KS8851_IRQ);
594                 spi_register_board_info(sdp4430_spi_board_info,
595                                 ARRAY_SIZE(sdp4430_spi_board_info));
596         }
597 }
598
599 static void __init omap_4430sdp_map_io(void)
600 {
601         omap2_set_globals_443x();
602         omap44xx_map_common_io();
603 }
604
605 MACHINE_START(OMAP_4430SDP, "OMAP4430 4430SDP board")
606         /* Maintainer: Santosh Shilimkar - Texas Instruments Inc */
607         .boot_params    = 0x80000100,
608         .map_io         = omap_4430sdp_map_io,
609         .reserve        = omap_reserve,
610         .init_irq       = omap_4430sdp_init_irq,
611         .init_machine   = omap_4430sdp_init,
612         .timer          = &omap_timer,
613 MACHINE_END