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