summaryrefslogtreecommitdiff
path: root/recipes/linux/linux-omap-psp-2.6.32/omap3-touchbook/board-omap3touchbook.c (plain)
blob: b7210ae79715434432581e3fe3574215e28be6a6
1/*
2 * linux/arch/arm/mach-omap2/board-omap3touchbook.c
3 * This file supports the Touch Book v1 (board rev
4 * A1/B1/C1), as well as Touch Book v2 or Smart Book
5 * (board rev rev D5).
6 *
7 * linux/arch/arm/mach-omap2/board-omap3touchbook.c
8 *
9 * Copyright (C) 2009-2010 Always Innovating
10 *
11 * Modified from mach-omap2/board-omap3beagleboard.c
12 *
13 * Code: Grégoire Gentil, Tim Yamin
14 *
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License version 2 as
17 * published by the Free Software Foundation.
18 */
19
20#include <linux/kernel.h>
21#include <linux/init.h>
22#include <linux/platform_device.h>
23#include <linux/delay.h>
24#include <linux/err.h>
25#include <linux/clk.h>
26#include <linux/io.h>
27#include <linux/leds.h>
28#include <linux/gpio.h>
29#include <linux/irq.h>
30#include <linux/input.h>
31#include <linux/gpio_keys.h>
32#include <linux/mtd/mtd.h>
33#include <linux/mtd/partitions.h>
34#include <linux/mtd/nand.h>
35#include <plat/mcspi.h>
36#include <linux/spi/spi.h>
37#include <linux/spi/ads7846.h>
38#include <linux/mma7455l.h>
39#include <linux/regulator/machine.h>
40#include <linux/i2c/twl.h>
41#include <linux/i2c/chacha.h>
42#include <linux/i2c/bq27x00.h>
43#include <linux/i2c-gpio.h>
44#include <mach/hardware.h>
45#include <asm/mach-types.h>
46#include <asm/mach/arch.h>
47#include <asm/mach/map.h>
48#include <asm/mach/flash.h>
49#include <plat/board.h>
50#include <plat/common.h>
51#include <plat/display.h>
52#include <plat/gpmc.h>
53#include <plat/nand.h>
54#include <plat/usb.h>
55#include <plat/timer-gp.h>
56#include <plat/clock.h>
57#include <plat/omap-pm.h>
58#include "mux.h"
59#include "mmc-twl4030.h"
60#include "pm.h"
61#include "omap3-opp.h"
62#include <asm/setup.h>
63#include <plat/dmtimer.h>
64#include <linux/backlight.h>
65#include "sdram-micron-mt46h32m32lf-6.h"
66
67#ifdef CONFIG_PANEL_SIL9022
68#include <mach/sil9022.h>
69#endif
70
71#ifdef CONFIG_PM
72static struct omap_opp * _omap35x_mpu_rate_table = omap35x_mpu_rate_table;
73static struct omap_opp * _omap37x_mpu_rate_table = omap37x_mpu_rate_table;
74static struct omap_opp * _omap35x_dsp_rate_table = omap35x_dsp_rate_table;
75static struct omap_opp * _omap37x_dsp_rate_table = omap37x_dsp_rate_table;
76static struct omap_opp * _omap35x_l3_rate_table = omap35x_l3_rate_table;
77static struct omap_opp * _omap37x_l3_rate_table = omap37x_l3_rate_table;
78#else /* CONFIG_PM */
79static struct omap_opp * _omap35x_mpu_rate_table = NULL;
80static struct omap_opp * _omap37x_mpu_rate_table = NULL;
81static struct omap_opp * _omap35x_dsp_rate_table = NULL;
82static struct omap_opp * _omap37x_dsp_rate_table = NULL;
83static struct omap_opp * _omap35x_l3_rate_table = NULL;
84static struct omap_opp * _omap37x_l3_rate_table = NULL;
85#endif /* CONFIG_PM */
86
87unsigned long touchbook_revision = 2;
88
89static int __init revision_instance(char *str)
90{
91 if (!str)
92 return -EINVAL;
93
94 touchbook_revision = simple_strtoul(str, NULL, 10);
95
96 return 0;
97}
98
99static ssize_t show_revision(struct device *dev, struct device_attribute *devattr, char *buf)
100{
101 return sprintf(buf, "%lu\n", touchbook_revision);
102}
103static DEVICE_ATTR(revision, S_IRUGO, show_revision, NULL);
104
105early_param("tbr", revision_instance);
106
107/*
108###############################################################################
109###############################################################################
110###############################################################################
111###############################################################################
112###############################################################################
113*/
114
115static struct mtd_partition touchbook_nand_partitions[] = {
116 /* All the partition sizes are listed in terms of NAND block size */
117 {
118 .name = "X-Loader",
119 .offset = 0,
120 .size = 4 * SZ_128K,
121 .mask_flags = MTD_WRITEABLE, /* force read-only */
122 },
123 {
124 .name = "U-Boot",
125 .offset = MTDPART_OFS_APPEND, /* Offset = 0x80000 */
126 .size = 15 * SZ_128K,
127 },
128 {
129 .name = "U-Boot Env",
130 .offset = MTDPART_OFS_APPEND, /* Offset = 0x260000 */
131 .size = 1 * SZ_128K,
132 },
133 {
134 .name = "Kernel",
135 .offset = MTDPART_OFS_APPEND, /* Offset = 0x280000 */
136 .size = 32 * SZ_128K,
137 },
138 {
139 .name = "File System",
140 .offset = MTDPART_OFS_APPEND, /* Offset = 0x680000 */
141 .size = MTDPART_SIZ_FULL,
142 },
143};
144
145static struct omap_nand_platform_data touchbook_nand_data = {
146 .options = NAND_BUSWIDTH_16,
147 .parts = touchbook_nand_partitions,
148 .nr_parts = ARRAY_SIZE(touchbook_nand_partitions),
149 .dma_channel = -1, /* disable DMA in OMAP NAND driver */
150 .nand_setup = NULL,
151 .dev_ready = NULL,
152};
153
154static struct resource touchbook_nand_resource = {
155 .flags = IORESOURCE_MEM,
156};
157
158static struct platform_device touchbook_nand_device = {
159 .name = "omap2-nand",
160 .id = -1,
161 .dev = {
162 .platform_data = &touchbook_nand_data,
163 },
164 .num_resources = 1,
165 .resource = &touchbook_nand_resource,
166};
167
168static int touchbook_enable_dvi(struct omap_dss_device *dssdev)
169{
170 if (dssdev->reset_gpio != -1)
171 gpio_set_value(dssdev->reset_gpio, 1);
172
173 return 0;
174}
175
176static void touchbook_disable_dvi(struct omap_dss_device *dssdev)
177{
178 if (dssdev->reset_gpio != -1)
179 gpio_set_value(dssdev->reset_gpio, 0);
180}
181
182static struct omap_dss_device touchbook_dvi_device = {
183 .type = OMAP_DISPLAY_TYPE_DPI,
184 .name = "dvi",
185 .driver_name = "generic_panel",
186 .phy.dpi.data_lines = 24,
187 .reset_gpio = 176,
188 .platform_enable = touchbook_enable_dvi,
189 .platform_disable = touchbook_disable_dvi,
190};
191
192static struct omap_dss_device *touchbook_dss_devices[] = {
193 &touchbook_dvi_device,
194};
195
196static struct omap_dss_board_info touchbook_dss_data = {
197 .num_devices = ARRAY_SIZE(touchbook_dss_devices),
198 .devices = touchbook_dss_devices,
199 .default_device = &touchbook_dvi_device,
200};
201
202static struct platform_device touchbook_dss_device = {
203 .name = "omapdss",
204 .id = -1,
205 .dev = {
206 .platform_data = &touchbook_dss_data,
207 },
208};
209
210static struct regulator_consumer_supply touchbook_vdac_supply = {
211 .supply = "vdda_dac",
212 .dev = &touchbook_dss_device.dev,
213};
214
215static struct regulator_consumer_supply touchbook_vdvi_supply = {
216 .supply = "vdds_dsi",
217 .dev = &touchbook_dss_device.dev,
218};
219
220static void __init touchbook_display_init(void)
221{
222 int r;
223
224 r = gpio_request(touchbook_dvi_device.reset_gpio, "DVI reset");
225 if (r < 0) {
226 printk(KERN_ERR "Unable to get DVI reset GPIO\n");
227 return;
228 }
229
230 gpio_direction_output(touchbook_dvi_device.reset_gpio, 0);
231}
232
233static struct twl4030_hsmmc_info touchbook_mmc[] = {
234 {
235 .mmc = 1,
236 .wires = 8,
237 },
238 {} /* Terminator */
239};
240
241static struct regulator_consumer_supply touchbook_vmmc1_supply = {
242 .supply = "vmmc",
243};
244
245static struct regulator_consumer_supply touchbook_vsim_supply = {
246 .supply = "vmmc_aux",
247};
248
249static struct gpio_led gpio_leds[];
250
251static int touchbook_twl_gpio_setup(struct device *dev,
252 unsigned gpio, unsigned ngpio)
253{
254 /* gpio + 0 is "mmc0_cd" (input/IRQ) */
255 touchbook_mmc[0].gpio_cd = gpio + 0;
256 twl4030_mmc_init(touchbook_mmc);
257
258 /* link regulators to MMC adapters */
259 touchbook_vmmc1_supply.dev = touchbook_mmc[0].dev;
260 touchbook_vsim_supply.dev = touchbook_mmc[0].dev;
261
262 return 0;
263}
264
265static struct twl4030_gpio_platform_data touchbook_gpio_data = {
266 .gpio_base = OMAP_MAX_GPIO_LINES,
267 .irq_base = TWL4030_GPIO_IRQ_BASE,
268 .irq_end = TWL4030_GPIO_IRQ_END,
269 .use_leds = true,
270 .pullups = BIT(1),
271 .pulldowns = BIT(2) | BIT(6) | BIT(7) | BIT(8) | BIT(13)
272 | BIT(15) | BIT(16) | BIT(17),
273 .setup = touchbook_twl_gpio_setup,
274};
275
276/* VMMC1 for MMC1 pins CMD, CLK, DAT0..DAT3 (20 mA, plus card == max 220 mA) */
277static struct regulator_init_data touchbook_vmmc1 = {
278 .constraints = {
279 .min_uV = 1850000,
280 .max_uV = 3150000,
281 .valid_modes_mask = REGULATOR_MODE_NORMAL | REGULATOR_MODE_STANDBY,
282 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_MODE | REGULATOR_CHANGE_STATUS,
283 },
284 .num_consumer_supplies = 1,
285 .consumer_supplies = &touchbook_vmmc1_supply,
286};
287
288/* VSIM for MMC1 pins DAT4..DAT7 (2 mA, plus card == max 50 mA) */
289static struct regulator_init_data touchbook_vsim = {
290 .constraints = {
291 .min_uV = 1800000,
292 .max_uV = 3000000,
293 .valid_modes_mask = REGULATOR_MODE_NORMAL | REGULATOR_MODE_STANDBY,
294 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_MODE | REGULATOR_CHANGE_STATUS,
295 },
296 .num_consumer_supplies = 1,
297 .consumer_supplies = &touchbook_vsim_supply,
298};
299
300/* VDAC for DSS driving S-Video (8 mA unloaded, max 65 mA) */
301static struct regulator_init_data touchbook_vdac = {
302 .constraints = {
303 .min_uV = 1800000,
304 .max_uV = 1800000,
305 .valid_modes_mask = REGULATOR_MODE_NORMAL | REGULATOR_MODE_STANDBY,
306 .valid_ops_mask = REGULATOR_CHANGE_MODE | REGULATOR_CHANGE_STATUS,
307 },
308 .num_consumer_supplies = 1,
309 .consumer_supplies = &touchbook_vdac_supply,
310};
311
312/* VPLL2 for digital video outputs */
313static struct regulator_init_data touchbook_vpll2 = {
314 .constraints = {
315 .name = "VDVI",
316 .min_uV = 1800000,
317 .max_uV = 1800000,
318 .valid_modes_mask = REGULATOR_MODE_NORMAL | REGULATOR_MODE_STANDBY,
319 .valid_ops_mask = REGULATOR_CHANGE_MODE | REGULATOR_CHANGE_STATUS,
320 },
321 .num_consumer_supplies = 1,
322 .consumer_supplies = &touchbook_vdvi_supply,
323};
324
325static struct twl4030_usb_data touchbook_usb_data = {
326 .usb_mode = T2_USB_MODE_ULPI,
327};
328
329static struct twl4030_codec_audio_data touchbook_audio_data = {
330 .audio_mclk = 26000000,
331};
332
333static struct twl4030_codec_data touchbook_codec_data = {
334 .audio_mclk = 26000000,
335 .audio = &touchbook_audio_data,
336};
337
338static struct twl4030_madc_platform_data touchbook_madc_data = {
339 .irq_line = 1,
340};
341
342static struct twl4030_bci_platform_data touchbook_bci_data = {
343 .tblsize = 0,
344 .no_backup_battery = 1,
345 .manufacturer = "Always Innovating",
346 .model_name = "Tablet 6000mAh v1.0",
347 .technology = POWER_SUPPLY_TECHNOLOGY_LIPO,
348 .energy_full_design = 6000,
349};
350
351static struct twl4030_platform_data touchbook_twldata = {
352 .irq_base = TWL4030_IRQ_BASE,
353 .irq_end = TWL4030_IRQ_END,
354
355 /* platform_data for children goes here */
356 .usb = &touchbook_usb_data,
357 .gpio = &touchbook_gpio_data,
358 .codec = &touchbook_codec_data,
359 .madc = &touchbook_madc_data,
360 .vmmc1 = &touchbook_vmmc1,
361 .vsim = &touchbook_vsim,
362 .vdac = &touchbook_vdac,
363 .vpll2 = &touchbook_vpll2,
364 .bci = &touchbook_bci_data,
365};
366
367static struct i2c_board_info __initdata touchbook_i2c_boardinfo_1[] = {
368 {
369 I2C_BOARD_INFO("twl4030", 0x48),
370 .flags = I2C_CLIENT_WAKE,
371 .irq = INT_34XX_SYS_NIRQ,
372 .platform_data = &touchbook_twldata,
373 },
374};
375
376static struct bq27x00_platform_data touchbook_bq27200_data = {
377 .manufacturer = "Always Innovating",
378 .model_name = "Keyboard 12000mAh v1.0",
379 .technology = POWER_SUPPLY_TECHNOLOGY_LIPO,
380 .energy_full_design = 12000,
381};
382
383static struct chacha_platform_data touchbook_chacha_t_data = {
384 .gpio = 155,
385 .version = 3,
386 .name = "Touchscreen Chacha Tablet",
387 .minX = 128,
388 .maxX = 17230,
389 .minY = 55555,
390 .maxY = 65300,
391};
392
393static struct i2c_board_info __initdata touchbook_i2c_boardinfo_3[] = {
394 {
395 I2C_BOARD_INFO("bq27200", 0x55),
396 .platform_data = &touchbook_bq27200_data,
397 },
398 {
399 I2C_BOARD_INFO("chacha", 0x40),
400 .irq = OMAP_GPIO_IRQ(155),
401 .platform_data = &touchbook_chacha_t_data,
402 },
403 {
404 I2C_BOARD_INFO("ds1307", 0x68),
405 },
406};
407
408static int __init touchbook_i2c_init(void)
409{
410 int ret;
411
412 /* Standard TouchBook bus */
413 omap_register_i2c_bus(1, 2600, touchbook_i2c_boardinfo_1, ARRAY_SIZE(touchbook_i2c_boardinfo_1));
414
415 /* Additional TouchBook bus */
416 omap_register_i2c_bus(3, 100, touchbook_i2c_boardinfo_3, ARRAY_SIZE(touchbook_i2c_boardinfo_3));
417
418 ret = gpio_request(touchbook_chacha_t_data.gpio, "chacha_t");
419 if (ret < 0) {
420 printk(KERN_ERR "Failed to request GPIO %d for chacha_t IRQ\n", touchbook_chacha_t_data.gpio);
421 return 0;
422 }
423 gpio_direction_input(touchbook_chacha_t_data.gpio);
424
425 return 0;
426}
427
428static struct gpio_led touchbook_gpio_leds[] = {
429 {
430 .name = "touchbook::usr0",
431 .default_trigger = "heartbeat",
432 .gpio = 150,
433 },
434 {
435 .name = "touchbook::usr1",
436 .default_trigger = "mmc0",
437 .gpio = 149,
438 },
439};
440
441static struct gpio_led_platform_data touchbook_gpio_led_info = {
442 .leds = touchbook_gpio_leds,
443 .num_leds = ARRAY_SIZE(touchbook_gpio_leds),
444};
445
446static struct platform_device touchbook_leds_gpio = {
447 .name = "leds-gpio",
448 .id = -1,
449 .dev = {
450 .platform_data = &touchbook_gpio_led_info,
451 },
452};
453
454static struct gpio_keys_button touchbook_gpio_buttons[] = {
455 {
456 .code = KEY_BACK,
457 .gpio = 7,
458 .desc = "user",
459 .wakeup = 1,
460 },
461 {
462 .code = KEY_POWER,
463 .gpio = 183,
464 .desc = "power",
465 .wakeup = 1,
466 .active_low = 1,
467 },
468};
469
470static struct gpio_keys_platform_data touchbook_gpio_key_info = {
471 .buttons = touchbook_gpio_buttons,
472 .nbuttons = ARRAY_SIZE(touchbook_gpio_buttons),
473};
474
475static struct platform_device touchbook_keys_gpio = {
476 .name = "gpio-keys",
477 .id = -1,
478 .dev = {
479 .platform_data = &touchbook_gpio_key_info,
480 },
481};
482
483static struct platform_device __initdata *touchbook_devices[] = {
484 &touchbook_leds_gpio,
485 &touchbook_keys_gpio,
486 &touchbook_dss_device,
487};
488
489static void __init touchbook_flash_init(void)
490{
491 u8 cs = 0;
492 u8 nandcs = GPMC_CS_NUM + 1;
493
494 u32 gpmc_base_add = OMAP34XX_GPMC_VIRT;
495
496 /* find out the chip-select on which NAND exists */
497 while (cs < GPMC_CS_NUM) {
498 u32 ret = 0;
499 ret = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG1);
500
501 if ((ret & 0xC00) == 0x800) {
502 printk(KERN_INFO "Found NAND on CS%d\n", cs);
503 if (nandcs > GPMC_CS_NUM)
504 nandcs = cs;
505 }
506 cs++;
507 }
508
509 if (nandcs > GPMC_CS_NUM) {
510 printk(KERN_INFO "NAND: Unable to find configuration "
511 "in GPMC\n ");
512 return;
513 }
514
515 if (nandcs < GPMC_CS_NUM) {
516 touchbook_nand_data.cs = nandcs;
517 touchbook_nand_data.gpmc_cs_baseaddr = (void *)
518 (gpmc_base_add + 0x60 + nandcs * 0x30);
519 touchbook_nand_data.gpmc_baseaddr =
520 (void *) (gpmc_base_add);
521
522 printk(KERN_INFO "Registering NAND on CS%d\n", nandcs);
523 if (platform_device_register(&touchbook_nand_device) < 0)
524 printk(KERN_ERR "Unable to register NAND device\n");
525 }
526}
527
528static struct ehci_hcd_omap_platform_data __initdata touchbook_ehci_pdata = {
529
530 .port_mode[0] = EHCI_HCD_OMAP_MODE_UNKNOWN,
531 .port_mode[1] = EHCI_HCD_OMAP_MODE_PHY,
532 .port_mode[2] = EHCI_HCD_OMAP_MODE_UNKNOWN,
533
534 .phy_reset = true,
535 .reset_gpio_port[0] = -EINVAL,
536 .reset_gpio_port[1] = 147,
537 .reset_gpio_port[2] = -EINVAL
538};
539
540#ifdef CONFIG_OMAP_MUX
541static struct omap_board_mux touchbook_board_mux[] = {
542 { .reg_offset = OMAP_MUX_TERMINATOR },
543};
544#else
545#define touchbook_board_mux NULL
546#endif
547
548static struct ads7846_platform_data touchbook_ads7846_config = {
549 .x_min = 100,
550 .y_min = 265,
551 .x_max = 3950,
552 .y_max = 3750,
553 .x_plate_ohms = 40,
554 .pressure_max = 255,
555 .debounce_max = 10,
556 .debounce_tol = 5,
557 .debounce_rep = 1,
558 .gpio_pendown = 162,
559 .keep_vref_on = 1,
560};
561
562static struct omap2_mcspi_device_config touchbook_ads7846_mcspi_config = {
563 .turbo_mode = 0,
564 .single_channel = 1, /* 0: slave, 1: master */
565};
566
567static struct spi_board_info __initdata touchbook_spi_board_info_4[] = {
568 {
569 .modalias = "ads7846",
570 .bus_num = 4,
571 .chip_select = 0,
572 .max_speed_hz = 1500000,
573 .controller_data = &touchbook_ads7846_mcspi_config,
574 .irq = OMAP_GPIO_IRQ(162),
575 .platform_data = &touchbook_ads7846_config,
576 }
577};
578
579static void __init touchbook_ads7846_init(void)
580{
581 if (gpio_request(touchbook_ads7846_config.gpio_pendown, "ads7846_pen_down")) {
582 printk(KERN_ERR "Failed to request GPIO %d for ads7846 pen down IRQ\n", touchbook_ads7846_config.gpio_pendown);
583 return;
584 }
585
586 gpio_direction_input(touchbook_ads7846_config.gpio_pendown);
587 omap_set_gpio_debounce(touchbook_ads7846_config.gpio_pendown, 1);
588 omap_set_gpio_debounce_time(touchbook_ads7846_config.gpio_pendown, 0xa);
589}
590
591static struct mma7455l_platform_data touchbook_mma7455l_config = {
592 .calibration_x = -4,
593 .calibration_y = 28,
594 .calibration_z = -28,
595 .axis_x = ABS_X,
596 .sign_x = 1,
597 .axis_y = ABS_Y,
598 .sign_y = 1,
599 .axis_z = ABS_Z,
600 .sign_z = 1,
601};
602
603static struct omap2_mcspi_device_config touchbook_mma7455l_mcspi_config = {
604 .turbo_mode = 0,
605 .single_channel = 1, /* 0: slave, 1: master */
606};
607
608static struct spi_board_info __initdata touchbook_spi_board_info_3[] = {
609 {
610 .modalias = "mma7455l",
611 .bus_num = 3,
612 .chip_select = 0,
613 .max_speed_hz = 200000,
614 .irq = OMAP_GPIO_IRQ(136),
615 .controller_data = &touchbook_mma7455l_mcspi_config,
616 .platform_data = &touchbook_mma7455l_config,
617 }
618};
619
620static void __init touchbook_mma7455l_init(void)
621{
622 int ret;
623 int touchbook_mma7455l_gpio = 136;
624
625 ret = gpio_request(touchbook_mma7455l_gpio, "mma7455l");
626 if (ret < 0) {
627 printk(KERN_ERR "Failed to request GPIO %d for mma7455l IRQ\n", touchbook_mma7455l_gpio);
628 return;
629 }
630
631 gpio_direction_input(touchbook_mma7455l_gpio);
632}
633
634static int touchbook_backlight_brightness = 50;
635static struct omap_dm_timer *touchbook_backlight_pwm;
636
637static int touchbook_backlight_read(struct backlight_device *bd)
638{
639 return touchbook_backlight_brightness;
640}
641
642static int touchbook_backlight_update(struct backlight_device *bd)
643{
644 int value = bd->props.brightness;
645 touchbook_backlight_brightness = value;
646
647 /* Frequency calculation:
648 - For 200Hz PWM, you want to load -164 (=> -32768Hz / 200Hz).
649 - Minimum duty cycle for the backlight is 15%.
650 - You have (164*0.85) => ~140 levels of brightness.
651 */
652
653 /* Halve input brightness */
654 if (!bd->props.boost)
655 value /= 2;
656
657 /* For maximum brightness, just stop the timer... */
658 if(value != bd->props.max_brightness)
659 {
660 /* Load the appropriate value for 200Hz PWM */
661 u32 period = clk_get_rate(omap_dm_timer_get_fclk(touchbook_backlight_pwm)) / bd->props.pwm_fq;
662
663 /* Minimum duty cycle is 15% */
664 u32 minimum = (period * bd->props.min_duty) / 100;
665 u32 maximum = (period * 17) / 20;
666
667 /* Work out match value */
668 u32 match = (maximum * value) / 100;
669
670 /* Start... */
671 omap_dm_timer_set_load(touchbook_backlight_pwm, 1, 0xFFFFFFFF - period - 1);
672 omap_dm_timer_set_match(touchbook_backlight_pwm, 1, 0xFFFFFFFF - minimum - match);
673 omap_dm_timer_write_counter(touchbook_backlight_pwm, -1);
674 omap_dm_timer_start(touchbook_backlight_pwm);
675 }
676 else
677 omap_dm_timer_stop(touchbook_backlight_pwm);
678
679
680 return 0;
681}
682
683static struct backlight_ops touchbook_backlight_properties = {
684 .get_brightness = touchbook_backlight_read,
685 .update_status = touchbook_backlight_update,
686};
687
688static void __init touchbook_backlight_init(void)
689{
690 static struct backlight_device *bd;
691 int touchbook_bl_pwm_timer = 9;
692 bd = backlight_device_register("touchbook", NULL, NULL, &touchbook_backlight_properties);
693
694 if(bd)
695 {
696 touchbook_backlight_pwm = omap_dm_timer_request_specific(touchbook_bl_pwm_timer);
697 omap_dm_timer_enable(touchbook_backlight_pwm);
698 omap_dm_timer_set_source(touchbook_backlight_pwm, OMAP_TIMER_SRC_SYS_CLK);
699 omap_dm_timer_set_pwm(touchbook_backlight_pwm, 1, 1, OMAP_TIMER_TRIGGER_OVERFLOW_AND_COMPARE);
700
701 bd->props.max_brightness = 100;
702 bd->props.brightness = touchbook_backlight_brightness;
703 bd->props.boost = 0;
704 bd->props.min_duty = 15;
705 bd->props.pwm_fq = 200;
706 }
707
708 touchbook_backlight_update(bd);
709}
710
711static void touchbook_poweroff(void)
712{
713 int r;
714 int touchbook_kill_power_gpio = 168;
715
716 r = gpio_request(touchbook_kill_power_gpio, "power reset");
717 if (r < 0) {
718 printk(KERN_ERR "Unable to get kill power GPIO\n");
719 return;
720 }
721
722 gpio_direction_output(touchbook_kill_power_gpio, 0);
723}
724
725static void __init touchbook_init(void)
726{
727 int r;
728 struct platform_device *pdev;
729
730 printk(KERN_ERR "Touch Book rev. A*/B*/C*\n");
731
732 pm_power_off = touchbook_poweroff;
733
734 omap3_mux_init(touchbook_board_mux, OMAP_PACKAGE_CBB);
735 touchbook_i2c_init();
736 platform_add_devices(touchbook_devices, ARRAY_SIZE(touchbook_devices));
737 omap_serial_init();
738
739 usb_musb_init();
740 usb_ehci_init(&touchbook_ehci_pdata);
741 touchbook_flash_init();
742
743 /* Ensure SDRC pins are mux'd for self-refresh */
744 omap_mux_init_signal("sdrc_cke0", OMAP_PIN_OUTPUT);
745 omap_mux_init_signal("sdrc_cke1", OMAP_PIN_OUTPUT);
746
747 touchbook_display_init();
748 touchbook_backlight_init();
749
750 /* Touchscreen and accelerometer */
751 spi_register_board_info(touchbook_spi_board_info_4, ARRAY_SIZE(touchbook_spi_board_info_4));
752 spi_register_board_info(touchbook_spi_board_info_3, ARRAY_SIZE(touchbook_spi_board_info_3));
753 touchbook_ads7846_init();
754 touchbook_mma7455l_init();
755
756 /* Export AI board revision */
757 pdev = platform_device_alloc("touchbook", 0);
758 platform_device_add(pdev);
759 r = device_create_file(&pdev->dev, &dev_attr_revision);
760}
761
762/*
763###############################################################################
764###############################################################################
765###############################################################################
766###############################################################################
767###############################################################################
768*/
769
770static struct mtd_partition touchbook_rev4_nand_partitions[] = {
771 /* All the partition sizes are listed in terms of NAND block size */
772 {
773 .name = "X-Loader",
774 .offset = 0,
775 .size = 4 * SZ_128K,
776 .mask_flags = MTD_WRITEABLE, /* force read-only */
777 },
778 {
779 .name = "U-Boot",
780 .offset = MTDPART_OFS_APPEND, /* Offset = 0x80000 */
781 .size = 15 * SZ_128K,
782 },
783 {
784 .name = "U-Boot Env",
785 .offset = MTDPART_OFS_APPEND, /* Offset = 0x260000 */
786 .size = 1 * SZ_128K,
787 },
788 {
789 .name = "Kernel",
790 .offset = MTDPART_OFS_APPEND, /* Offset = 0x280000 */
791 .size = 32 * SZ_128K,
792 },
793 {
794 .name = "File System",
795 .offset = MTDPART_OFS_APPEND, /* Offset = 0x680000 */
796 .size = MTDPART_SIZ_FULL,
797 },
798};
799
800static struct omap_nand_platform_data touchbook_rev4_nand_data = {
801 .options = NAND_BUSWIDTH_16,
802 .parts = touchbook_rev4_nand_partitions,
803 .nr_parts = ARRAY_SIZE(touchbook_rev4_nand_partitions),
804 .dma_channel = -1, /* disable DMA in OMAP NAND driver */
805 .nand_setup = NULL,
806 .dev_ready = NULL,
807};
808
809static struct resource touchbook_rev4_nand_resource = {
810 .flags = IORESOURCE_MEM,
811};
812
813static struct platform_device touchbook_rev4_nand_device = {
814 .name = "omap2-nand",
815 .id = -1,
816 .dev = {
817 .platform_data = &touchbook_rev4_nand_data,
818 },
819 .num_resources = 1,
820 .resource = &touchbook_rev4_nand_resource,
821};
822
823static int touchbook_rev4_dvi_enable(struct omap_dss_device *dssdev)
824{
825 if (dssdev->reset_gpio != -1)
826 gpio_set_value(dssdev->reset_gpio, 1);
827
828 return 0;
829}
830
831static void touchbook_rev4_dvi_disable(struct omap_dss_device *dssdev)
832{
833 if (dssdev->reset_gpio != -1)
834 gpio_set_value(dssdev->reset_gpio, 0);
835}
836
837static struct omap_dss_device touchbook_rev4_dvi_device = {
838 .type = OMAP_DISPLAY_TYPE_DPI,
839 .name = "dvi",
840 .driver_name = "generic_panel",
841 .phy.dpi.data_lines = 24,
842 .reset_gpio = 146,
843 .platform_enable = touchbook_rev4_dvi_enable,
844 .platform_disable = touchbook_rev4_dvi_disable,
845};
846
847static int touchbook_rev4_screen_m_enable(struct omap_dss_device *dssdev)
848{
849 if (dssdev->reset_gpio != -1)
850 gpio_set_value(dssdev->reset_gpio, 1);
851
852 return 0;
853}
854
855static void touchbook_rev4_screen_m_disable(struct omap_dss_device *dssdev)
856{
857 if (dssdev->reset_gpio != -1)
858 gpio_set_value(dssdev->reset_gpio, 0);
859}
860
861#ifdef CONFIG_PANEL_LH350H01
862static struct omap_dss_device touchbook_rev4_mid_device = {
863 .type = OMAP_DISPLAY_TYPE_DSI,
864 .name = "mid",
865 .driver_name = "lh350h01_panel",
866 .phy.dsi.clk_lane = 2,
867 .phy.dsi.clk_pol = 1,
868 .phy.dsi.data1_lane = 1,
869 .phy.dsi.data1_pol = 1,
870 .phy.dsi.data2_lane = 3,
871 .phy.dsi.data2_pol = 1,
872 .phy.dsi.ddr_clk_hz = 25000000,
873 .phy.dsi.lp_clk_hz = 1000000,
874 .reset_gpio = 12,
875 .platform_enable = touchbook_rev4_screen_m_enable,
876 .platform_disable = touchbook_rev4_screen_m_disable,
877 .phy.dsi.xfer_mode = OMAP_DSI_XFER_VIDEO_MODE,
878 .phy.dsi.vm_timing.hsa = 16,
879 .phy.dsi.vm_timing.hfp = 12,
880 .phy.dsi.vm_timing.hbp = 12,
881 .phy.dsi.vm_timing.vsa = 8,
882 .phy.dsi.vm_timing.vfp = 6,
883 .phy.dsi.vm_timing.vbp = 6,
884};
885#endif
886
887#ifdef CONFIG_PANEL_SIL9022
888struct hdmi_platform_data touchbook_rev4_hdmi_data = {
889#ifdef CONFIG_PM
890 .set_min_bus_tput = omap_pm_set_min_bus_tput,
891 .set_max_mpu_wakeup_lat = omap_pm_set_max_mpu_wakeup_lat,
892#endif
893};
894
895static struct omap_dss_device touchbook_rev4_hdmi_device = {
896 .type = OMAP_DISPLAY_TYPE_DPI,
897 .name = "hdmi",
898 .driver_name = "hdmi_panel",
899 .phy.dpi.data_lines = 24,
900 .dev = {
901 .platform_data = &touchbook_rev4_hdmi_data,
902 },
903};
904#endif
905
906static struct omap_dss_device *touchbook_rev4_dss_devices[] = {
907#ifdef CONFIG_PANEL_LH350H01
908 &touchbook_rev4_mid_device,
909#endif
910#ifdef CONFIG_PANEL_SIL9022
911 &touchbook_rev4_hdmi_device,
912#endif
913 &touchbook_rev4_dvi_device,
914};
915
916static struct omap_dss_board_info touchbook_rev4_dss_data = {
917 .num_devices = ARRAY_SIZE(touchbook_rev4_dss_devices),
918 .devices = touchbook_rev4_dss_devices,
919 .default_device = &touchbook_rev4_dvi_device,
920};
921
922static struct platform_device touchbook_rev4_dss_device = {
923 .name = "omapdss",
924 .id = -1,
925 .dev = {
926 .platform_data = &touchbook_rev4_dss_data,
927 },
928};
929
930static struct regulator_consumer_supply touchbook_rev4_vdac_supply = {
931 .supply = "vdda_dac",
932 .dev = &touchbook_rev4_dss_device.dev,
933};
934
935static struct regulator_consumer_supply touchbook_rev4_vdvi_supply = {
936 .supply = "vdds_dsi",
937 .dev = &touchbook_rev4_dss_device.dev,
938};
939
940static void __init touchbook_rev4_display_init(void)
941{
942 int r;
943
944 r = gpio_request(touchbook_rev4_dvi_device.reset_gpio, "DVI reset");
945 if (r < 0) {
946 printk(KERN_ERR "Unable to get DVI reset GPIO\n");
947 return;
948 }
949
950 gpio_direction_output(touchbook_rev4_dvi_device.reset_gpio, 0);
951
952#ifdef CONFIG_PANEL_LH350H01
953 r = gpio_request(touchbook_rev4_mid_device.reset_gpio, "MID reset");
954 if (r < 0) {
955 printk(KERN_ERR "Unable to get MID reset GPIO\n");
956 return;
957 }
958
959 gpio_direction_output(touchbook_rev4_mid_device.reset_gpio, 0);
960#endif
961}
962
963static struct twl4030_hsmmc_info touchbook_rev4_mmc[] = {
964 {
965 .mmc = 1,
966 .wires = 8,
967 },
968 {} /* Terminator */
969};
970
971static struct regulator_consumer_supply touchbook_rev4_vmmc1_supply = {
972 .supply = "vmmc",
973};
974
975static struct regulator_consumer_supply touchbook_rev4_vsim_supply = {
976 .supply = "vmmc_aux",
977};
978
979static struct gpio_led gpio_leds[];
980
981static int touchbook_rev4_twl_gpio_setup(struct device *dev,
982 unsigned gpio, unsigned ngpio)
983{
984 /* gpio + 0 is "mmc0_cd" (input/IRQ) */
985 touchbook_rev4_mmc[0].gpio_cd = gpio + 0;
986 twl4030_mmc_init(touchbook_rev4_mmc);
987
988 /* link regulators to MMC adapters */
989 touchbook_rev4_vmmc1_supply.dev = touchbook_rev4_mmc[0].dev;
990 touchbook_rev4_vsim_supply.dev = touchbook_rev4_mmc[0].dev;
991
992 return 0;
993}
994
995static struct twl4030_gpio_platform_data touchbook_rev4_gpio_data = {
996 .gpio_base = OMAP_MAX_GPIO_LINES,
997 .irq_base = TWL4030_GPIO_IRQ_BASE,
998 .irq_end = TWL4030_GPIO_IRQ_END,
999 .use_leds = true,
1000 .pullups = BIT(1),
1001 .pulldowns = BIT(2) | BIT(6) | BIT(7) | BIT(8) | BIT(13) | BIT(15) | BIT(16) | BIT(17),
1002 .setup = touchbook_rev4_twl_gpio_setup,
1003};
1004
1005/* VMMC1 for MMC1 pins CMD, CLK, DAT0..DAT3 (20 mA, plus card == max 220 mA) */
1006static struct regulator_init_data touchbook_rev4_vmmc1 = {
1007 .constraints = {
1008 .min_uV = 1850000,
1009 .max_uV = 3150000,
1010 .valid_modes_mask = REGULATOR_MODE_NORMAL | REGULATOR_MODE_STANDBY,
1011 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_MODE | REGULATOR_CHANGE_STATUS,
1012 },
1013 .num_consumer_supplies = 1,
1014 .consumer_supplies = &touchbook_rev4_vmmc1_supply,
1015};
1016
1017/* VSIM for MMC1 pins DAT4..DAT7 (2 mA, plus card == max 50 mA) */
1018static struct regulator_init_data touchbook_rev4_vsim = {
1019 .constraints = {
1020 .min_uV = 1800000,
1021 .max_uV = 3000000,
1022 .valid_modes_mask = REGULATOR_MODE_NORMAL | REGULATOR_MODE_STANDBY,
1023 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_MODE | REGULATOR_CHANGE_STATUS,
1024 },
1025 .num_consumer_supplies = 1,
1026 .consumer_supplies = &touchbook_rev4_vsim_supply,
1027};
1028
1029/* VDAC for DSS driving S-Video (8 mA unloaded, max 65 mA) */
1030static struct regulator_init_data touchbook_rev4_vdac = {
1031 .constraints = {
1032 .min_uV = 1800000,
1033 .max_uV = 1800000,
1034 .valid_modes_mask = REGULATOR_MODE_NORMAL | REGULATOR_MODE_STANDBY,
1035 .valid_ops_mask = REGULATOR_CHANGE_MODE | REGULATOR_CHANGE_STATUS,
1036 },
1037 .num_consumer_supplies = 1,
1038 .consumer_supplies = &touchbook_rev4_vdac_supply,
1039};
1040
1041/* VPLL2 for digital video outputs */
1042static struct regulator_init_data touchbook_rev4_vpll2 = {
1043 .constraints = {
1044 .name = "VDVI",
1045 .min_uV = 1800000,
1046 .max_uV = 1800000,
1047 .valid_modes_mask = REGULATOR_MODE_NORMAL | REGULATOR_MODE_STANDBY,
1048 .valid_ops_mask = REGULATOR_CHANGE_MODE | REGULATOR_CHANGE_STATUS,
1049 },
1050 .num_consumer_supplies = 1,
1051 .consumer_supplies = &touchbook_rev4_vdvi_supply,
1052};
1053
1054static struct twl4030_usb_data touchbook_rev4_usb_data = {
1055 .usb_mode = T2_USB_MODE_ULPI,
1056};
1057
1058static struct twl4030_codec_audio_data touchbook_rev4_audio_data = {
1059 .audio_mclk = 26000000,
1060};
1061
1062static struct twl4030_codec_data touchbook_rev4_codec_data = {
1063 .audio_mclk = 26000000,
1064 .audio = &touchbook_rev4_audio_data,
1065};
1066
1067static struct twl4030_madc_platform_data touchbook_rev4_madc_data = {
1068 .irq_line = 1,
1069};
1070
1071static struct twl4030_bci_platform_data touchbook_rev4_bci_data = {
1072 .tblsize = 0,
1073 .no_backup_battery = 1,
1074 .manufacturer = "Always Innovating",
1075 .model_name = "Tablet 1500mAh v1.0",
1076 .technology = POWER_SUPPLY_TECHNOLOGY_LIPO,
1077 .energy_full_design = 1500,
1078};
1079
1080static struct twl4030_platform_data touchbook_rev4_twldata = {
1081 .irq_base = TWL4030_IRQ_BASE,
1082 .irq_end = TWL4030_IRQ_END,
1083
1084 /* platform_data for children goes here */
1085 .usb = &touchbook_rev4_usb_data,
1086 .gpio = &touchbook_rev4_gpio_data,
1087 .codec = &touchbook_rev4_codec_data,
1088 .madc = &touchbook_rev4_madc_data,
1089 .vmmc1 = &touchbook_rev4_vmmc1,
1090 .vsim = &touchbook_rev4_vsim,
1091 .vdac = &touchbook_rev4_vdac,
1092 .vpll2 = &touchbook_rev4_vpll2,
1093 .bci = &touchbook_rev4_bci_data,
1094};
1095
1096static struct i2c_board_info __initdata touchbook_rev4_i2c_boardinfo_1[] = {
1097 {
1098 I2C_BOARD_INFO("twl4030", 0x48),
1099 .flags = I2C_CLIENT_WAKE,
1100 .irq = INT_34XX_SYS_NIRQ,
1101 .platform_data = &touchbook_rev4_twldata,
1102 },
1103};
1104
1105static struct bq27x00_platform_data touchbook_rev4_bq27500_t_data = {
1106 .manufacturer = "Always Innovating",
1107 .model_name = "Keyboard 6000mAh v1.0",
1108 .technology = POWER_SUPPLY_TECHNOLOGY_LIPO,
1109 .energy_full_design = 6000,
1110};
1111
1112static struct chacha_platform_data touchbook_rev4_chacha_t_data = {
1113 .gpio = 13,
1114 .version = 3,
1115 .name = "Touchscreen Chacha Tablet",
1116 .minX = 128,
1117 .maxX = 17230,
1118 .minY = 55555,
1119 .maxY = 65300,
1120};
1121
1122static struct i2c_board_info __initdata touchbook_rev4_i2c_boardinfo_2[] = {
1123 {
1124 I2C_BOARD_INFO("bq27500", 0x55),
1125 .platform_data = &touchbook_rev4_bq27500_t_data,
1126 },
1127 {
1128 I2C_BOARD_INFO("chacha", 0x40),
1129 .irq = OMAP_GPIO_IRQ(13),
1130 .platform_data = &touchbook_rev4_chacha_t_data,
1131 },
1132 {
1133 I2C_BOARD_INFO("eeprom", 0x50),
1134 },
1135 {
1136 I2C_BOARD_INFO("ds1307", 0x68),
1137 },
1138};
1139
1140static struct bq27x00_platform_data touchbook_rev4_bq27500_k_data = {
1141 .manufacturer = "Always Innovating",
1142 .model_name = "Keyboard 12000mAh v1.0",
1143 .technology = POWER_SUPPLY_TECHNOLOGY_LIPO,
1144 .energy_full_design = 12000,
1145};
1146
1147static struct chacha_platform_data touchbook_rev4_chacha_m_data = {
1148 .gpio = 18,
1149 .version = 4,
1150 .name = "Touchscreen Chacha MID",
1151 .minX = 0,
1152 .maxX = 63000,
1153 .minY = 0,
1154 .maxY = 63000,
1155};
1156
1157static struct i2c_board_info __initdata touchbook_rev4_i2c_boardinfo_3[] = {
1158 {
1159 I2C_BOARD_INFO("bq27500", 0x55),
1160 .platform_data = &touchbook_rev4_bq27500_k_data,
1161 },
1162 {
1163 I2C_BOARD_INFO("chacha", 0x40),
1164 .irq = OMAP_GPIO_IRQ(18),
1165 .platform_data = &touchbook_rev4_chacha_m_data,
1166 },
1167#ifdef CONFIG_PANEL_SIL9022
1168 {
1169 I2C_BOARD_INFO(SIL9022_DRV_NAME, SI9022_I2CSLAVEADDRESS),
1170 },
1171#endif
1172};
1173
1174static struct bq27x00_platform_data touchbook_rev4_bq27500_m_data = {
1175 .manufacturer = "Always Innovating",
1176 .model_name = "Keyboard 1500mAh v1.0",
1177 .technology = POWER_SUPPLY_TECHNOLOGY_LIPO,
1178 .energy_full_design = 1500,
1179};
1180
1181static struct i2c_board_info __initdata touchbook_rev4_i2c_boardinfo_5[] = {
1182 {
1183 I2C_BOARD_INFO("bq27500", 0x55),
1184 .platform_data = &touchbook_rev4_bq27500_m_data,
1185 },
1186};
1187
1188static struct i2c_gpio_platform_data touchbook_rev4_i2c_5_data = {
1189 .sda_pin = 152,
1190 .scl_pin = 153,
1191};
1192
1193static struct platform_device touchbook_rev4_i2c_5_device = {
1194 .name = "i2c-gpio",
1195 .id = 5,
1196 .dev = {
1197 .platform_data = &touchbook_rev4_i2c_5_data,
1198 },
1199};
1200
1201static struct i2c_board_info __initdata touchbook_rev4_i2c_boardinfo_6[] = {
1202 {
1203 I2C_BOARD_INFO("eeprom", 0x50),
1204 },
1205};
1206
1207static struct i2c_gpio_platform_data touchbook_rev4_i2c_6_data = {
1208 .sda_pin = 98,
1209 .scl_pin = 97,
1210};
1211
1212static struct platform_device touchbook_rev4_i2c_6_device = {
1213 .name = "i2c-gpio",
1214 .id = 6,
1215 .dev = {
1216 .platform_data = &touchbook_rev4_i2c_6_data,
1217 },
1218};
1219
1220static int __init touchbook_rev4_i2c_init(void)
1221{
1222 int ret;
1223
1224 /* Standard OMAP3 bus */
1225 omap_register_i2c_bus(1, 2600, touchbook_rev4_i2c_boardinfo_1, ARRAY_SIZE(touchbook_rev4_i2c_boardinfo_1));
1226
1227 /* Additional TouchBook bus */
1228 omap_register_i2c_bus(2, 100, touchbook_rev4_i2c_boardinfo_2, ARRAY_SIZE(touchbook_rev4_i2c_boardinfo_2));
1229
1230 ret = gpio_request(touchbook_rev4_chacha_t_data.gpio, "chacha_t");
1231 if (ret < 0) {
1232 printk(KERN_ERR "Failed to request GPIO %d for chacha_t IRQ\n", touchbook_rev4_chacha_t_data.gpio);
1233 return 0;
1234 }
1235 gpio_direction_input(touchbook_rev4_chacha_t_data.gpio);
1236
1237 /* Additional TouchBook bus */
1238 omap_register_i2c_bus(3, 100, touchbook_rev4_i2c_boardinfo_3, ARRAY_SIZE(touchbook_rev4_i2c_boardinfo_3));
1239
1240 ret = gpio_request(touchbook_rev4_chacha_m_data.gpio, "chacha_m");
1241 if (ret < 0) {
1242 printk(KERN_ERR "Failed to request GPIO %d for chacha_m IRQ\n", touchbook_rev4_chacha_m_data.gpio);
1243 return 0;
1244 }
1245 gpio_direction_input(touchbook_rev4_chacha_m_data.gpio);
1246
1247 /* Additional TouchBook bus */
1248 platform_device_register(&touchbook_rev4_i2c_5_device);
1249 i2c_register_board_info(5, touchbook_rev4_i2c_boardinfo_5, ARRAY_SIZE(touchbook_rev4_i2c_boardinfo_5));
1250
1251 /* Additional TouchBook bus */
1252 platform_device_register(&touchbook_rev4_i2c_6_device);
1253 i2c_register_board_info(6, touchbook_rev4_i2c_boardinfo_6, ARRAY_SIZE(touchbook_rev4_i2c_boardinfo_6));
1254
1255 return 0;
1256}
1257
1258static struct gpio_led touchbook_rev4_gpio_leds[] = {
1259 {
1260 .name = "touchbook::usr0",
1261 .default_trigger = "heartbeat",
1262 .gpio = 149,
1263 },
1264 {
1265 .name = "touchbook::usr1",
1266 .default_trigger = "mmc0",
1267 .gpio = 19,
1268 },
1269};
1270
1271static struct gpio_led_platform_data touchbook_rev4_gpio_led_info = {
1272 .leds = touchbook_rev4_gpio_leds,
1273 .num_leds = ARRAY_SIZE(touchbook_rev4_gpio_leds),
1274};
1275
1276static struct platform_device touchbook_rev4_leds_gpio = {
1277 .name = "leds-gpio",
1278 .id = -1,
1279 .dev = {
1280 .platform_data = &touchbook_rev4_gpio_led_info,
1281 },
1282};
1283
1284static struct gpio_keys_button touchbook_rev4_gpio_buttons[] = {
1285 {
1286 .code = KEY_BACK,
1287 .gpio = 147,
1288 .desc = "user",
1289 .wakeup = 1,
1290 .active_low = 1,
1291 },
1292 {
1293 .code = KEY_VOLUMEDOWN,
1294 .gpio = 94,
1295 .desc = "snd_down",
1296 .wakeup = 1,
1297 },
1298 {
1299 .code = KEY_VOLUMEUP,
1300 .gpio = 95,
1301 .desc = "snd_up",
1302 .wakeup = 1,
1303 },
1304 {
1305 .code = KEY_POWER,
1306 .gpio = 144,
1307 .desc = "power",
1308 .wakeup = 1,
1309 .active_low = 1,
1310 },
1311};
1312
1313static struct gpio_keys_platform_data touchbook_rev4_gpio_key_info = {
1314 .buttons = touchbook_rev4_gpio_buttons,
1315 .nbuttons = ARRAY_SIZE(touchbook_rev4_gpio_buttons),
1316};
1317
1318static struct platform_device touchbook_rev4_keys_gpio = {
1319 .name = "gpio-keys",
1320 .id = -1,
1321 .dev = {
1322 .platform_data = &touchbook_rev4_gpio_key_info,
1323 },
1324};
1325
1326static struct platform_device __initdata *touchbook_rev4_devices[] = {
1327 &touchbook_rev4_leds_gpio,
1328 &touchbook_rev4_keys_gpio,
1329 &touchbook_rev4_dss_device,
1330};
1331
1332static void __init touchbook_rev4_flash_init(void)
1333{
1334 u8 cs = 0;
1335 u8 nandcs = GPMC_CS_NUM + 1;
1336
1337 u32 gpmc_base_add = OMAP34XX_GPMC_VIRT;
1338
1339 /* find out the chip-select on which NAND exists */
1340 while (cs < GPMC_CS_NUM) {
1341 u32 ret = 0;
1342 ret = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG1);
1343
1344 if ((ret & 0xC00) == 0x800) {
1345 printk(KERN_INFO "Found NAND on CS%d\n", cs);
1346 if (nandcs > GPMC_CS_NUM)
1347 nandcs = cs;
1348 }
1349 cs++;
1350 }
1351
1352 if (nandcs > GPMC_CS_NUM) {
1353 printk(KERN_INFO "NAND: Unable to find configuration "
1354 "in GPMC\n ");
1355 return;
1356 }
1357
1358 if (nandcs < GPMC_CS_NUM) {
1359 touchbook_rev4_nand_data.cs = nandcs;
1360 touchbook_rev4_nand_data.gpmc_cs_baseaddr = (void *)
1361 (gpmc_base_add + 0x60 + nandcs * 0x30);
1362 touchbook_rev4_nand_data.gpmc_baseaddr =
1363 (void *) (gpmc_base_add);
1364
1365 printk(KERN_INFO "Registering NAND on CS%d\n", nandcs);
1366 if (platform_device_register(&touchbook_rev4_nand_device) < 0)
1367 printk(KERN_ERR "Unable to register NAND device\n");
1368 }
1369}
1370
1371static struct ehci_hcd_omap_platform_data __initdata touchbook_rev4_ehci_pdata = {
1372
1373 .port_mode[0] = EHCI_HCD_OMAP_MODE_UNKNOWN,
1374 .port_mode[1] = EHCI_HCD_OMAP_MODE_PHY,
1375 .port_mode[2] = EHCI_HCD_OMAP_MODE_UNKNOWN,
1376
1377 .phy_reset = true,
1378 .reset_gpio_port[0] = -EINVAL,
1379 .reset_gpio_port[1] = 23,
1380 .reset_gpio_port[2] = -EINVAL
1381};
1382
1383#ifdef CONFIG_OMAP_MUX
1384static struct omap_board_mux touchbook_rev4_board_mux[] = {
1385 { .reg_offset = OMAP_MUX_TERMINATOR },
1386};
1387#else
1388#define touchbook_rev4_board_mux NULL
1389#endif
1390
1391static struct ads7846_platform_data touchbook_rev4_ads7846_config = {
1392 .x_min = 100,
1393 .y_min = 265,
1394 .x_max = 3950,
1395 .y_max = 3750,
1396 .x_plate_ohms = 40,
1397 .pressure_max = 255,
1398 .debounce_max = 10,
1399 .debounce_tol = 5,
1400 .debounce_rep = 1,
1401 .gpio_pendown = 162,
1402 .keep_vref_on = 1,
1403};
1404
1405static struct omap2_mcspi_device_config touchbook_rev4_ads7846_mcspi_config = {
1406 .turbo_mode = 0,
1407 .single_channel = 1, /* 0: slave, 1: master */
1408};
1409
1410static struct spi_board_info __initdata touchbook_rev4_spi_board_info_4[] = {
1411 {
1412 .modalias = "ads7846",
1413 .bus_num = 4,
1414 .chip_select = 0,
1415 .max_speed_hz = 1500000,
1416 .controller_data = &touchbook_rev4_ads7846_mcspi_config,
1417 .irq = OMAP_GPIO_IRQ(162),
1418 .platform_data = &touchbook_rev4_ads7846_config,
1419 }
1420};
1421
1422static void __init touchbook_rev4_ads7846_init(void)
1423{
1424 if (gpio_request(touchbook_rev4_ads7846_config.gpio_pendown, "ads7846_pen_down")) {
1425 printk(KERN_ERR "Failed to request GPIO %d for ads7846 pen down IRQ\n", touchbook_rev4_ads7846_config.gpio_pendown);
1426 return;
1427 }
1428
1429 gpio_direction_input(touchbook_rev4_ads7846_config.gpio_pendown);
1430 omap_set_gpio_debounce(touchbook_rev4_ads7846_config.gpio_pendown, 1);
1431 omap_set_gpio_debounce_time(touchbook_rev4_ads7846_config.gpio_pendown, 0xa);
1432}
1433
1434static struct mma7455l_platform_data touchbook_rev4_mma7455l_config = {
1435 .calibration_x = -4,
1436 .calibration_y = 28,
1437 .calibration_z = -28,
1438 .axis_x = ABS_X,
1439 .sign_x = -1,
1440 .axis_y = ABS_Y,
1441 .sign_y = -1,
1442 .axis_z = ABS_Z,
1443 .sign_z = -1,
1444};
1445
1446static struct omap2_mcspi_device_config touchbook_rev4_mma7455l_mcspi_config = {
1447 .turbo_mode = 0,
1448 .single_channel = 1, /* 0: slave, 1: master */
1449};
1450
1451static struct spi_board_info __initdata touchbook_rev4_spi_board_info_1[] = {
1452 {
1453 .modalias = "mma7455l",
1454 .bus_num = 1,
1455 .chip_select = 0,
1456 .max_speed_hz = 200000,
1457 .irq = OMAP_GPIO_IRQ(133),
1458 .controller_data = &touchbook_rev4_mma7455l_mcspi_config,
1459 .platform_data = &touchbook_rev4_mma7455l_config,
1460 }
1461};
1462
1463static void __init touchbook_rev4_mma7455l_init(void)
1464{
1465 int ret;
1466 int touchbook_rev4_mma7455l_gpio = 133;
1467
1468 ret = gpio_request(touchbook_rev4_mma7455l_gpio, "mma7455l");
1469 if (ret < 0) {
1470 printk(KERN_ERR "Failed to request GPIO %d for mma7455l IRQ\n", touchbook_rev4_mma7455l_gpio);
1471 return;
1472 }
1473
1474 gpio_direction_input(touchbook_rev4_mma7455l_gpio);
1475}
1476
1477static int touchbook_rev4_backlight_brightness = 50;
1478static struct omap_dm_timer *touchbook_rev4_backlight_pwm;
1479
1480static int touchbook_rev4_backlight_read(struct backlight_device *bd)
1481{
1482 return touchbook_rev4_backlight_brightness;
1483}
1484
1485static int touchbook_rev4_backlight_update(struct backlight_device *bd)
1486{
1487 int value = bd->props.brightness;
1488 touchbook_rev4_backlight_brightness = value;
1489
1490 /* Frequency calculation:
1491 - For 200Hz PWM, you want to load -164 (=> -32768Hz / 200Hz).
1492 - Minimum duty cycle for the backlight is 15%.
1493 - You have (164*0.85) => ~140 levels of brightness.
1494 */
1495
1496 /* Halve input brightness */
1497 if (!bd->props.boost)
1498 value /= 2;
1499
1500 /* For maximum brightness, just stop the timer... */
1501 if(value != bd->props.max_brightness)
1502 {
1503 /* Load the appropriate value for 200Hz PWM */
1504 u32 period = clk_get_rate(omap_dm_timer_get_fclk(touchbook_rev4_backlight_pwm)) / bd->props.pwm_fq;
1505
1506 /* Minimum duty cycle is 15% */
1507 u32 minimum = (period * bd->props.min_duty) / 100;
1508 u32 maximum = (period * 17) / 20;
1509
1510 /* Work out match value */
1511 u32 match = (maximum * value) / 100;
1512
1513 /* Start... */
1514 omap_dm_timer_set_load(touchbook_rev4_backlight_pwm, 1, 0xFFFFFFFF - period - 1);
1515 omap_dm_timer_set_match(touchbook_rev4_backlight_pwm, 1, 0xFFFFFFFF - minimum - match);
1516 omap_dm_timer_write_counter(touchbook_rev4_backlight_pwm, -1);
1517 omap_dm_timer_start(touchbook_rev4_backlight_pwm);
1518 }
1519 else
1520 omap_dm_timer_stop(touchbook_rev4_backlight_pwm);
1521
1522
1523 return 0;
1524}
1525
1526static struct backlight_ops touchbook_rev4_backlight_properties = {
1527 .get_brightness = touchbook_rev4_backlight_read,
1528 .update_status = touchbook_rev4_backlight_update,
1529};
1530
1531static void __init touchbook_rev4_backlight_init(void)
1532{
1533 static struct backlight_device *bd;
1534 int touchbook_rev4_bl_pwm_timer = 8;
1535 bd = backlight_device_register("touchbook", NULL, NULL, &touchbook_rev4_backlight_properties);
1536
1537 if(bd)
1538 {
1539 touchbook_rev4_backlight_pwm = omap_dm_timer_request_specific(touchbook_rev4_bl_pwm_timer);
1540 omap_dm_timer_enable(touchbook_rev4_backlight_pwm);
1541 omap_dm_timer_set_source(touchbook_rev4_backlight_pwm, OMAP_TIMER_SRC_SYS_CLK);
1542 omap_dm_timer_set_pwm(touchbook_rev4_backlight_pwm, 1, 1, OMAP_TIMER_TRIGGER_OVERFLOW_AND_COMPARE);
1543
1544 bd->props.max_brightness = 100;
1545 bd->props.brightness = touchbook_rev4_backlight_brightness;
1546 bd->props.boost = 0;
1547 bd->props.min_duty = 15;
1548 bd->props.pwm_fq = 200;
1549 }
1550
1551 touchbook_rev4_backlight_update(bd);
1552}
1553
1554static void touchbook_rev4_poweroff(void)
1555{
1556 int r;
1557 int touchbook_rev4_kill_power_gpio = 16;
1558
1559 r = gpio_request(touchbook_rev4_kill_power_gpio, "power reset");
1560 if (r < 0) {
1561 printk(KERN_ERR "Unable to get kill power GPIO\n");
1562 return;
1563 }
1564
1565 gpio_direction_output(touchbook_rev4_kill_power_gpio, 0);
1566}
1567
1568
1569static struct platform_device ai_remote_device = {
1570 .name = "ai_remote",
1571};
1572
1573static void __init touchbook_rev4_init(void)
1574{
1575 int r;
1576 struct platform_device *pdev;
1577
1578 printk(KERN_ERR "Touch Book rev. D*\n");
1579
1580 pm_power_off = touchbook_rev4_poweroff;
1581
1582 omap3_mux_init(touchbook_rev4_board_mux, OMAP_PACKAGE_CBB);
1583 touchbook_rev4_i2c_init();
1584 platform_add_devices(touchbook_rev4_devices, ARRAY_SIZE(touchbook_rev4_devices));
1585 omap_serial_init();
1586
1587 usb_musb_init();
1588 usb_ehci_init(&touchbook_rev4_ehci_pdata);
1589 touchbook_rev4_flash_init();
1590
1591 /* Ensure SDRC pins are mux'd for self-refresh */
1592 omap_mux_init_signal("sdrc_cke0", OMAP_PIN_OUTPUT);
1593 omap_mux_init_signal("sdrc_cke1", OMAP_PIN_OUTPUT);
1594
1595 touchbook_rev4_display_init();
1596 touchbook_rev4_backlight_init();
1597
1598 /* Touchscreen and accelerometer */
1599 spi_register_board_info(touchbook_rev4_spi_board_info_4, ARRAY_SIZE(touchbook_rev4_spi_board_info_4));
1600 spi_register_board_info(touchbook_rev4_spi_board_info_1, ARRAY_SIZE(touchbook_rev4_spi_board_info_1));
1601 touchbook_rev4_ads7846_init();
1602 touchbook_rev4_mma7455l_init();
1603
1604 /* Export AI board revision */
1605 pdev = platform_device_alloc("touchbook", 0);
1606 platform_device_add(pdev);
1607 r = device_create_file(&pdev->dev, &dev_attr_revision);
1608
1609 /* AI Remote Control */
1610 platform_device_register(&ai_remote_device);
1611}
1612
1613/*
1614###############################################################################
1615###############################################################################
1616###############################################################################
1617###############################################################################
1618###############################################################################
1619*/
1620
1621static void __init touchbook_map_io(void)
1622{
1623 omap2_set_globals_343x();
1624 omap2_map_common_io();
1625}
1626
1627static void __init touchbook_init_irq(void)
1628{
1629 if (cpu_is_omap3630())
1630 {
1631 omap2_init_common_hw(mt46h32m32lf6_sdrc_params,
1632 mt46h32m32lf6_sdrc_params,
1633 _omap37x_mpu_rate_table,
1634 _omap37x_dsp_rate_table,
1635 _omap37x_l3_rate_table);
1636 }
1637 else
1638 {
1639 omap2_init_common_hw(mt46h32m32lf6_sdrc_params,
1640 mt46h32m32lf6_sdrc_params,
1641 _omap35x_mpu_rate_table,
1642 _omap35x_dsp_rate_table,
1643 _omap35x_l3_rate_table);
1644 }
1645
1646 omap_init_irq();
1647#ifdef CONFIG_OMAP_32K_TIMER
1648 omap2_gp_clockevent_set_gptimer(12);
1649#endif
1650 omap_gpio_init();
1651}
1652
1653static void __init super_init(void)
1654{
1655 if (touchbook_revision == 4)
1656 touchbook_rev4_init();
1657 else
1658 touchbook_init();
1659}
1660
1661MACHINE_START(OMAP3_TOUCHBOOK, "OMAP3 touchbook Board")
1662 /* Maintainer: Gregoire Gentil - http://www.alwaysinnovating.com */
1663 .phys_io = 0x48000000,
1664 .io_pg_offst = ((0xd8000000) >> 18) & 0xfffc,
1665 .boot_params = 0x80000100,
1666 .map_io = touchbook_map_io,
1667 .init_irq = touchbook_init_irq,
1668 .init_machine = super_init,
1669 .timer = &omap_timer,
1670MACHINE_END
1671