Merge branch 'drm-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/airlied...
[pandora-kernel.git] / arch / arm / mach-omap2 / board-omap3touchbook.c
1 /*
2  * linux/arch/arm/mach-omap2/board-omap3touchbook.c
3  *
4  * Copyright (C) 2009 Always Innovating
5  *
6  * Modified from mach-omap2/board-omap3beagleboard.c
7  *
8  * Initial code: GrĂ©goire Gentil, Tim Yamin
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License version 2 as
12  * published by the Free Software Foundation.
13  */
14
15 #include <linux/kernel.h>
16 #include <linux/init.h>
17 #include <linux/platform_device.h>
18 #include <linux/delay.h>
19 #include <linux/err.h>
20 #include <linux/clk.h>
21 #include <linux/io.h>
22 #include <linux/leds.h>
23 #include <linux/gpio.h>
24 #include <linux/input.h>
25 #include <linux/gpio_keys.h>
26
27 #include <linux/mtd/mtd.h>
28 #include <linux/mtd/partitions.h>
29 #include <linux/mtd/nand.h>
30
31 #include <plat/mcspi.h>
32 #include <linux/spi/spi.h>
33
34 #include <linux/spi/ads7846.h>
35
36 #include <linux/regulator/machine.h>
37 #include <linux/i2c/twl.h>
38
39 #include <mach/hardware.h>
40 #include <asm/mach-types.h>
41 #include <asm/mach/arch.h>
42 #include <asm/mach/map.h>
43 #include <asm/mach/flash.h>
44
45 #include <plat/board.h>
46 #include <plat/common.h>
47 #include <plat/gpmc.h>
48 #include <plat/nand.h>
49 #include <plat/usb.h>
50 #include <plat/timer-gp.h>
51
52 #include "mux.h"
53 #include "hsmmc.h"
54
55 #include <asm/setup.h>
56
57 #define NAND_BLOCK_SIZE         SZ_128K
58
59 #define OMAP3_AC_GPIO           136
60 #define OMAP3_TS_GPIO           162
61 #define TB_BL_PWM_TIMER         9
62 #define TB_KILL_POWER_GPIO      168
63
64 unsigned long touchbook_revision;
65
66 static struct mtd_partition omap3touchbook_nand_partitions[] = {
67         /* All the partition sizes are listed in terms of NAND block size */
68         {
69                 .name           = "X-Loader",
70                 .offset         = 0,
71                 .size           = 4 * NAND_BLOCK_SIZE,
72                 .mask_flags     = MTD_WRITEABLE,        /* force read-only */
73         },
74         {
75                 .name           = "U-Boot",
76                 .offset         = MTDPART_OFS_APPEND,   /* Offset = 0x80000 */
77                 .size           = 15 * NAND_BLOCK_SIZE,
78                 .mask_flags     = MTD_WRITEABLE,        /* force read-only */
79         },
80         {
81                 .name           = "U-Boot Env",
82                 .offset         = MTDPART_OFS_APPEND,   /* Offset = 0x260000 */
83                 .size           = 1 * NAND_BLOCK_SIZE,
84         },
85         {
86                 .name           = "Kernel",
87                 .offset         = MTDPART_OFS_APPEND,   /* Offset = 0x280000 */
88                 .size           = 32 * NAND_BLOCK_SIZE,
89         },
90         {
91                 .name           = "File System",
92                 .offset         = MTDPART_OFS_APPEND,   /* Offset = 0x680000 */
93                 .size           = MTDPART_SIZ_FULL,
94         },
95 };
96
97 static struct omap_nand_platform_data omap3touchbook_nand_data = {
98         .options        = NAND_BUSWIDTH_16,
99         .parts          = omap3touchbook_nand_partitions,
100         .nr_parts       = ARRAY_SIZE(omap3touchbook_nand_partitions),
101         .dma_channel    = -1,           /* disable DMA in OMAP NAND driver */
102         .nand_setup     = NULL,
103         .dev_ready      = NULL,
104 };
105
106 #include "sdram-micron-mt46h32m32lf-6.h"
107
108 static struct omap2_hsmmc_info mmc[] = {
109         {
110                 .mmc            = 1,
111                 .wires          = 8,
112                 .gpio_wp        = 29,
113         },
114         {}      /* Terminator */
115 };
116
117 static struct platform_device omap3_touchbook_lcd_device = {
118         .name           = "omap3touchbook_lcd",
119         .id             = -1,
120 };
121
122 static struct omap_lcd_config omap3_touchbook_lcd_config __initdata = {
123         .ctrl_name      = "internal",
124 };
125
126 static struct regulator_consumer_supply touchbook_vmmc1_supply = {
127         .supply                 = "vmmc",
128 };
129
130 static struct regulator_consumer_supply touchbook_vsim_supply = {
131         .supply                 = "vmmc_aux",
132 };
133
134 static struct gpio_led gpio_leds[];
135
136 static int touchbook_twl_gpio_setup(struct device *dev,
137                 unsigned gpio, unsigned ngpio)
138 {
139         if (system_rev >= 0x20 && system_rev <= 0x34301000) {
140                 omap_mux_init_gpio(23, OMAP_PIN_INPUT);
141                 mmc[0].gpio_wp = 23;
142         } else {
143                 omap_mux_init_gpio(29, OMAP_PIN_INPUT);
144         }
145         /* gpio + 0 is "mmc0_cd" (input/IRQ) */
146         mmc[0].gpio_cd = gpio + 0;
147         omap2_hsmmc_init(mmc);
148
149         /* link regulators to MMC adapters */
150         touchbook_vmmc1_supply.dev = mmc[0].dev;
151         touchbook_vsim_supply.dev = mmc[0].dev;
152
153         /* REVISIT: need ehci-omap hooks for external VBUS
154          * power switch and overcurrent detect
155          */
156
157         gpio_request(gpio + 1, "EHCI_nOC");
158         gpio_direction_input(gpio + 1);
159
160         /* TWL4030_GPIO_MAX + 0 == ledA, EHCI nEN_USB_PWR (out, active low) */
161         gpio_request(gpio + TWL4030_GPIO_MAX, "nEN_USB_PWR");
162         gpio_direction_output(gpio + TWL4030_GPIO_MAX, 0);
163
164         /* TWL4030_GPIO_MAX + 1 == ledB, PMU_STAT (out, active low LED) */
165         gpio_leds[2].gpio = gpio + TWL4030_GPIO_MAX + 1;
166
167         return 0;
168 }
169
170 static struct twl4030_gpio_platform_data touchbook_gpio_data = {
171         .gpio_base      = OMAP_MAX_GPIO_LINES,
172         .irq_base       = TWL4030_GPIO_IRQ_BASE,
173         .irq_end        = TWL4030_GPIO_IRQ_END,
174         .use_leds       = true,
175         .pullups        = BIT(1),
176         .pulldowns      = BIT(2) | BIT(6) | BIT(7) | BIT(8) | BIT(13)
177                                 | BIT(15) | BIT(16) | BIT(17),
178         .setup          = touchbook_twl_gpio_setup,
179 };
180
181 static struct regulator_consumer_supply touchbook_vdac_supply = {
182         .supply         = "vdac",
183         .dev            = &omap3_touchbook_lcd_device.dev,
184 };
185
186 static struct regulator_consumer_supply touchbook_vdvi_supply = {
187         .supply         = "vdvi",
188         .dev            = &omap3_touchbook_lcd_device.dev,
189 };
190
191 /* VMMC1 for MMC1 pins CMD, CLK, DAT0..DAT3 (20 mA, plus card == max 220 mA) */
192 static struct regulator_init_data touchbook_vmmc1 = {
193         .constraints = {
194                 .min_uV                 = 1850000,
195                 .max_uV                 = 3150000,
196                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
197                                         | REGULATOR_MODE_STANDBY,
198                 .valid_ops_mask         = REGULATOR_CHANGE_VOLTAGE
199                                         | REGULATOR_CHANGE_MODE
200                                         | REGULATOR_CHANGE_STATUS,
201         },
202         .num_consumer_supplies  = 1,
203         .consumer_supplies      = &touchbook_vmmc1_supply,
204 };
205
206 /* VSIM for MMC1 pins DAT4..DAT7 (2 mA, plus card == max 50 mA) */
207 static struct regulator_init_data touchbook_vsim = {
208         .constraints = {
209                 .min_uV                 = 1800000,
210                 .max_uV                 = 3000000,
211                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
212                                         | REGULATOR_MODE_STANDBY,
213                 .valid_ops_mask         = REGULATOR_CHANGE_VOLTAGE
214                                         | REGULATOR_CHANGE_MODE
215                                         | REGULATOR_CHANGE_STATUS,
216         },
217         .num_consumer_supplies  = 1,
218         .consumer_supplies      = &touchbook_vsim_supply,
219 };
220
221 /* VDAC for DSS driving S-Video (8 mA unloaded, max 65 mA) */
222 static struct regulator_init_data touchbook_vdac = {
223         .constraints = {
224                 .min_uV                 = 1800000,
225                 .max_uV                 = 1800000,
226                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
227                                         | REGULATOR_MODE_STANDBY,
228                 .valid_ops_mask         = REGULATOR_CHANGE_MODE
229                                         | REGULATOR_CHANGE_STATUS,
230         },
231         .num_consumer_supplies  = 1,
232         .consumer_supplies      = &touchbook_vdac_supply,
233 };
234
235 /* VPLL2 for digital video outputs */
236 static struct regulator_init_data touchbook_vpll2 = {
237         .constraints = {
238                 .name                   = "VDVI",
239                 .min_uV                 = 1800000,
240                 .max_uV                 = 1800000,
241                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
242                                         | REGULATOR_MODE_STANDBY,
243                 .valid_ops_mask         = REGULATOR_CHANGE_MODE
244                                         | REGULATOR_CHANGE_STATUS,
245         },
246         .num_consumer_supplies  = 1,
247         .consumer_supplies      = &touchbook_vdvi_supply,
248 };
249
250 static struct twl4030_usb_data touchbook_usb_data = {
251         .usb_mode       = T2_USB_MODE_ULPI,
252 };
253
254 static struct twl4030_codec_audio_data touchbook_audio_data = {
255         .audio_mclk = 26000000,
256 };
257
258 static struct twl4030_codec_data touchbook_codec_data = {
259         .audio_mclk = 26000000,
260         .audio = &touchbook_audio_data,
261 };
262
263 static struct twl4030_platform_data touchbook_twldata = {
264         .irq_base       = TWL4030_IRQ_BASE,
265         .irq_end        = TWL4030_IRQ_END,
266
267         /* platform_data for children goes here */
268         .usb            = &touchbook_usb_data,
269         .gpio           = &touchbook_gpio_data,
270         .codec          = &touchbook_codec_data,
271         .vmmc1          = &touchbook_vmmc1,
272         .vsim           = &touchbook_vsim,
273         .vdac           = &touchbook_vdac,
274         .vpll2          = &touchbook_vpll2,
275 };
276
277 static struct i2c_board_info __initdata touchbook_i2c_boardinfo[] = {
278         {
279                 I2C_BOARD_INFO("twl4030", 0x48),
280                 .flags = I2C_CLIENT_WAKE,
281                 .irq = INT_34XX_SYS_NIRQ,
282                 .platform_data = &touchbook_twldata,
283         },
284 };
285
286 static struct i2c_board_info __initdata touchBook_i2c_boardinfo[] = {
287         {
288                 I2C_BOARD_INFO("bq27200", 0x55),
289         },
290 };
291
292 static int __init omap3_touchbook_i2c_init(void)
293 {
294         /* Standard TouchBook bus */
295         omap_register_i2c_bus(1, 2600, touchbook_i2c_boardinfo,
296                         ARRAY_SIZE(touchbook_i2c_boardinfo));
297
298         /* Additional TouchBook bus */
299         omap_register_i2c_bus(3, 100, touchBook_i2c_boardinfo,
300                         ARRAY_SIZE(touchBook_i2c_boardinfo));
301
302         return 0;
303 }
304
305 static void __init omap3_ads7846_init(void)
306 {
307         if (gpio_request(OMAP3_TS_GPIO, "ads7846_pen_down")) {
308                 printk(KERN_ERR "Failed to request GPIO %d for "
309                                 "ads7846 pen down IRQ\n", OMAP3_TS_GPIO);
310                 return;
311         }
312
313         gpio_direction_input(OMAP3_TS_GPIO);
314         gpio_set_debounce(OMAP3_TS_GPIO, 310);
315 }
316
317 static struct ads7846_platform_data ads7846_config = {
318         .x_min                  = 100,
319         .y_min                  = 265,
320         .x_max                  = 3950,
321         .y_max                  = 3750,
322         .x_plate_ohms           = 40,
323         .pressure_max           = 255,
324         .debounce_max           = 10,
325         .debounce_tol           = 5,
326         .debounce_rep           = 1,
327         .gpio_pendown           = OMAP3_TS_GPIO,
328         .keep_vref_on           = 1,
329 };
330
331 static struct omap2_mcspi_device_config ads7846_mcspi_config = {
332         .turbo_mode     = 0,
333         .single_channel = 1,    /* 0: slave, 1: master */
334 };
335
336 static struct spi_board_info omap3_ads7846_spi_board_info[] __initdata = {
337         {
338                 .modalias               = "ads7846",
339                 .bus_num                = 4,
340                 .chip_select            = 0,
341                 .max_speed_hz           = 1500000,
342                 .controller_data        = &ads7846_mcspi_config,
343                 .irq                    = OMAP_GPIO_IRQ(OMAP3_TS_GPIO),
344                 .platform_data          = &ads7846_config,
345         }
346 };
347
348 static struct gpio_led gpio_leds[] = {
349         {
350                 .name                   = "touchbook::usr0",
351                 .default_trigger        = "heartbeat",
352                 .gpio                   = 150,
353         },
354         {
355                 .name                   = "touchbook::usr1",
356                 .default_trigger        = "mmc0",
357                 .gpio                   = 149,
358         },
359         {
360                 .name                   = "touchbook::pmu_stat",
361                 .gpio                   = -EINVAL,      /* gets replaced */
362                 .active_low             = true,
363         },
364 };
365
366 static struct gpio_led_platform_data gpio_led_info = {
367         .leds           = gpio_leds,
368         .num_leds       = ARRAY_SIZE(gpio_leds),
369 };
370
371 static struct platform_device leds_gpio = {
372         .name   = "leds-gpio",
373         .id     = -1,
374         .dev    = {
375                 .platform_data  = &gpio_led_info,
376         },
377 };
378
379 static struct gpio_keys_button gpio_buttons[] = {
380         {
381                 .code                   = BTN_EXTRA,
382                 .gpio                   = 7,
383                 .desc                   = "user",
384                 .wakeup                 = 1,
385         },
386         {
387                 .code                   = KEY_POWER,
388                 .gpio                   = 183,
389                 .desc                   = "power",
390                 .wakeup                 = 1,
391         },
392 };
393
394 static struct gpio_keys_platform_data gpio_key_info = {
395         .buttons        = gpio_buttons,
396         .nbuttons       = ARRAY_SIZE(gpio_buttons),
397 };
398
399 static struct platform_device keys_gpio = {
400         .name   = "gpio-keys",
401         .id     = -1,
402         .dev    = {
403                 .platform_data  = &gpio_key_info,
404         },
405 };
406
407 static struct omap_board_config_kernel omap3_touchbook_config[] __initdata = {
408         { OMAP_TAG_LCD,         &omap3_touchbook_lcd_config },
409 };
410
411 #ifdef CONFIG_OMAP_MUX
412 static struct omap_board_mux board_mux[] __initdata = {
413         { .reg_offset = OMAP_MUX_TERMINATOR },
414 };
415 #else
416 #define board_mux       NULL
417 #endif
418
419 static void __init omap3_touchbook_init_irq(void)
420 {
421         omap3_mux_init(board_mux, OMAP_PACKAGE_CBB);
422         omap_board_config = omap3_touchbook_config;
423         omap_board_config_size = ARRAY_SIZE(omap3_touchbook_config);
424         omap2_init_common_hw(mt46h32m32lf6_sdrc_params,
425                              mt46h32m32lf6_sdrc_params);
426         omap_init_irq();
427 #ifdef CONFIG_OMAP_32K_TIMER
428         omap2_gp_clockevent_set_gptimer(12);
429 #endif
430         omap_gpio_init();
431 }
432
433 static struct platform_device *omap3_touchbook_devices[] __initdata = {
434         &omap3_touchbook_lcd_device,
435         &leds_gpio,
436         &keys_gpio,
437 };
438
439 static void __init omap3touchbook_flash_init(void)
440 {
441         u8 cs = 0;
442         u8 nandcs = GPMC_CS_NUM + 1;
443
444         /* find out the chip-select on which NAND exists */
445         while (cs < GPMC_CS_NUM) {
446                 u32 ret = 0;
447                 ret = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG1);
448
449                 if ((ret & 0xC00) == 0x800) {
450                         printk(KERN_INFO "Found NAND on CS%d\n", cs);
451                         if (nandcs > GPMC_CS_NUM)
452                                 nandcs = cs;
453                 }
454                 cs++;
455         }
456
457         if (nandcs > GPMC_CS_NUM) {
458                 printk(KERN_INFO "NAND: Unable to find configuration "
459                                  "in GPMC\n ");
460                 return;
461         }
462
463         if (nandcs < GPMC_CS_NUM) {
464                 omap3touchbook_nand_data.cs = nandcs;
465
466                 printk(KERN_INFO "Registering NAND on CS%d\n", nandcs);
467                 if (gpmc_nand_init(&omap3touchbook_nand_data) < 0)
468                         printk(KERN_ERR "Unable to register NAND device\n");
469         }
470 }
471
472 static const struct ehci_hcd_omap_platform_data ehci_pdata __initconst = {
473
474         .port_mode[0] = EHCI_HCD_OMAP_MODE_PHY,
475         .port_mode[1] = EHCI_HCD_OMAP_MODE_PHY,
476         .port_mode[2] = EHCI_HCD_OMAP_MODE_UNKNOWN,
477
478         .phy_reset  = true,
479         .reset_gpio_port[0]  = -EINVAL,
480         .reset_gpio_port[1]  = 147,
481         .reset_gpio_port[2]  = -EINVAL
482 };
483
484 static void omap3_touchbook_poweroff(void)
485 {
486         int r;
487
488         r = gpio_request(TB_KILL_POWER_GPIO, "DVI reset");
489         if (r < 0) {
490                 printk(KERN_ERR "Unable to get kill power GPIO\n");
491                 return;
492         }
493
494         gpio_direction_output(TB_KILL_POWER_GPIO, 0);
495 }
496
497 static int __init early_touchbook_revision(char *p)
498 {
499         if (!p)
500                 return 0;
501
502         return strict_strtoul(p, 10, &touchbook_revision);
503 }
504 early_param("tbr", early_touchbook_revision);
505
506 static struct omap_musb_board_data musb_board_data = {
507         .interface_type         = MUSB_INTERFACE_ULPI,
508         .mode                   = MUSB_OTG,
509         .power                  = 100,
510 };
511
512 static void __init omap3_touchbook_init(void)
513 {
514         pm_power_off = omap3_touchbook_poweroff;
515
516         omap3_touchbook_i2c_init();
517         platform_add_devices(omap3_touchbook_devices,
518                         ARRAY_SIZE(omap3_touchbook_devices));
519         omap_serial_init();
520
521         omap_mux_init_gpio(170, OMAP_PIN_INPUT);
522         gpio_request(176, "DVI_nPD");
523         /* REVISIT leave DVI powered down until it's needed ... */
524         gpio_direction_output(176, true);
525
526         /* Touchscreen and accelerometer */
527         spi_register_board_info(omap3_ads7846_spi_board_info,
528                                 ARRAY_SIZE(omap3_ads7846_spi_board_info));
529         omap3_ads7846_init();
530         usb_musb_init(&musb_board_data);
531         usb_ehci_init(&ehci_pdata);
532         omap3touchbook_flash_init();
533
534         /* Ensure SDRC pins are mux'd for self-refresh */
535         omap_mux_init_signal("sdrc_cke0", OMAP_PIN_OUTPUT);
536         omap_mux_init_signal("sdrc_cke1", OMAP_PIN_OUTPUT);
537 }
538
539 MACHINE_START(TOUCHBOOK, "OMAP3 touchbook Board")
540         /* Maintainer: Gregoire Gentil - http://www.alwaysinnovating.com */
541         .phys_io        = 0x48000000,
542         .io_pg_offst    = ((0xd8000000) >> 18) & 0xfffc,
543         .boot_params    = 0x80000100,
544         .map_io         = omap3_map_io,
545         .reserve        = omap_reserve,
546         .init_irq       = omap3_touchbook_init_irq,
547         .init_machine   = omap3_touchbook_init,
548         .timer          = &omap_timer,
549 MACHINE_END