2 * linux/arch/arm/mach-omap2/board-omap3touchbook.c
4 * Copyright (C) 2009 Always Innovating
6 * Modified from mach-omap2/board-omap3beagleboard.c
8 * Initial code: Grégoire Gentil, Tim Yamin
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.
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>
22 #include <linux/leds.h>
23 #include <linux/gpio.h>
24 #include <linux/input.h>
25 #include <linux/gpio_keys.h>
27 #include <linux/mtd/mtd.h>
28 #include <linux/mtd/partitions.h>
29 #include <linux/mtd/nand.h>
31 #include <mach/mcspi.h>
32 #include <linux/spi/spi.h>
33 #include <linux/spi/ads7846.h>
34 #include <linux/mma7455l.h>
36 #include <mach/dmtimer.h>
37 #include <linux/backlight.h>
39 #include <linux/regulator/machine.h>
40 #include <linux/i2c/twl4030.h>
41 #include <linux/omapfb.h>
43 #include <mach/hardware.h>
44 #include <asm/mach-types.h>
45 #include <asm/mach/arch.h>
46 #include <asm/mach/map.h>
47 #include <asm/mach/flash.h>
49 #include <mach/board.h>
51 #include <mach/common.h>
52 #include <mach/gpmc.h>
53 #include <mach/nand.h>
55 #include <mach/omap-pm.h>
56 #include <mach/clock.h>
57 #include <mach/display.h>
60 #include "twl4030-generic-scripts.h"
61 #include "mmc-twl4030.h"
63 #include "omap3-opp.h"
66 #define GPMC_CS0_BASE 0x60
67 #define GPMC_CS_SIZE 0x30
69 #define NAND_BLOCK_SIZE SZ_128K
71 #define OMAP3_AC_GPIO 136 //Int1 DRDY
72 #define OMAP3_TS_GPIO 162
73 #define OMAP3_CHACHA_GPIO 154
74 #define TB_BL_PWM_TIMER 9
75 #define TB_KILL_POWER_GPIO 168
77 unsigned int ai_revision = 2;
79 static struct mtd_partition omap3touchbook_nand_partitions[] = {
80 /* All the partition sizes are listed in terms of NAND block size */
84 .size = 4 * NAND_BLOCK_SIZE,
85 .mask_flags = MTD_WRITEABLE, /* force read-only */
89 .offset = MTDPART_OFS_APPEND, /* Offset = 0x80000 */
90 .size = 15 * NAND_BLOCK_SIZE,
91 .mask_flags = MTD_WRITEABLE, /* force read-only */
95 .offset = MTDPART_OFS_APPEND, /* Offset = 0x260000 */
96 .size = 1 * NAND_BLOCK_SIZE,
100 .offset = MTDPART_OFS_APPEND, /* Offset = 0x280000 */
101 .size = 32 * NAND_BLOCK_SIZE,
104 .name = "File System",
105 .offset = MTDPART_OFS_APPEND, /* Offset = 0x680000 */
106 .size = MTDPART_SIZ_FULL,
110 static struct omap_nand_platform_data omap3touchbook_nand_data = {
111 .options = NAND_BUSWIDTH_16,
112 .parts = omap3touchbook_nand_partitions,
113 .nr_parts = ARRAY_SIZE(omap3touchbook_nand_partitions),
114 .dma_channel = -1, /* disable DMA in OMAP NAND driver */
119 static struct resource omap3touchbook_nand_resource = {
120 .flags = IORESOURCE_MEM,
123 static struct platform_device omap3touchbook_nand_device = {
124 .name = "omap2-nand",
127 .platform_data = &omap3touchbook_nand_data,
130 .resource = &omap3touchbook_nand_resource,
133 #include "sdram-micron-mt46h32m32lf-6.h"
135 static struct omap_uart_config omap3_touchbook_uart_config __initdata = {
136 .enabled_uarts = ((1 << 0) | (1 << 1) | (1 << 2)),
139 static struct twl4030_usb_data touchbook_usb_data = {
140 .usb_mode = T2_USB_MODE_ULPI,
143 static struct twl4030_hsmmc_info mmc[] = {
152 static struct regulator_consumer_supply touchbook_vmmc1_supply = {
156 static struct regulator_consumer_supply touchbook_vsim_supply = {
157 .supply = "vmmc_aux",
160 static struct gpio_led gpio_leds[];
162 static int touchbook_twl_gpio_setup(struct device *dev,
163 unsigned gpio, unsigned ngpio)
165 /* gpio + 0 is "mmc0_cd" (input/IRQ) */
166 omap_cfg_reg(AH8_34XX_GPIO29);
167 mmc[0].gpio_cd = gpio + 0;
168 twl4030_mmc_init(mmc);
170 /* link regulators to MMC adapters */
171 touchbook_vmmc1_supply.dev = mmc[0].dev;
172 touchbook_vsim_supply.dev = mmc[0].dev;
174 /* REVISIT: need ehci-omap hooks for external VBUS
175 * power switch and overcurrent detect
178 #if 0 /* TODO: This needs to be modified to not rely on u-boot */
179 gpio_request(gpio + 1, "EHCI_nOC");
180 gpio_direction_input(gpio + 1);
182 /* TWL4030_GPIO_MAX + 0 == ledA, EHCI nEN_USB_PWR (out, active low) */
183 gpio_request(gpio + TWL4030_GPIO_MAX, "nEN_USB_PWR");
184 gpio_direction_output(gpio + TWL4030_GPIO_MAX, 1);
186 /* TWL4030_GPIO_MAX + 1 == ledB, PMU_STAT (out, active low LED) */
187 gpio_leds[2].gpio = gpio + TWL4030_GPIO_MAX + 1;
192 static struct twl4030_gpio_platform_data touchbook_gpio_data = {
193 .gpio_base = OMAP_MAX_GPIO_LINES,
194 .irq_base = TWL4030_GPIO_IRQ_BASE,
195 .irq_end = TWL4030_GPIO_IRQ_END,
198 .pulldowns = BIT(2) | BIT(6) | BIT(7) | BIT(8) | BIT(13)
199 | BIT(15) | BIT(16) | BIT(17),
200 .setup = touchbook_twl_gpio_setup,
203 static struct platform_device omap3_touchbook_lcd_device = {
204 .name = "omap3touchbook_lcd",
208 static struct regulator_consumer_supply touchbook_vdac_supply = {
210 .dev = &omap3_touchbook_lcd_device.dev,
213 static struct regulator_consumer_supply touchbook_vdvi_supply = {
215 .dev = &omap3_touchbook_lcd_device.dev,
218 /* VMMC1 for MMC1 pins CMD, CLK, DAT0..DAT3 (20 mA, plus card == max 220 mA) */
219 static struct regulator_init_data touchbook_vmmc1 = {
223 .valid_modes_mask = REGULATOR_MODE_NORMAL
224 | REGULATOR_MODE_STANDBY,
225 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE
226 | REGULATOR_CHANGE_MODE
227 | REGULATOR_CHANGE_STATUS,
229 .num_consumer_supplies = 1,
230 .consumer_supplies = &touchbook_vmmc1_supply,
233 /* VSIM for MMC1 pins DAT4..DAT7 (2 mA, plus card == max 50 mA) */
234 static struct regulator_init_data touchbook_vsim = {
238 .valid_modes_mask = REGULATOR_MODE_NORMAL
239 | REGULATOR_MODE_STANDBY,
240 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE
241 | REGULATOR_CHANGE_MODE
242 | REGULATOR_CHANGE_STATUS,
244 .num_consumer_supplies = 1,
245 .consumer_supplies = &touchbook_vsim_supply,
248 /* VDAC for DSS driving S-Video (8 mA unloaded, max 65 mA) */
249 static struct regulator_init_data touchbook_vdac = {
253 .valid_modes_mask = REGULATOR_MODE_NORMAL
254 | REGULATOR_MODE_STANDBY,
255 .valid_ops_mask = REGULATOR_CHANGE_MODE
256 | REGULATOR_CHANGE_STATUS,
258 .num_consumer_supplies = 1,
259 .consumer_supplies = &touchbook_vdac_supply,
262 /* VPLL2 for digital video outputs */
263 static struct regulator_init_data touchbook_vpll2 = {
268 .valid_modes_mask = REGULATOR_MODE_NORMAL
269 | REGULATOR_MODE_STANDBY,
270 .valid_ops_mask = REGULATOR_CHANGE_MODE
271 | REGULATOR_CHANGE_STATUS,
273 .num_consumer_supplies = 1,
274 .consumer_supplies = &touchbook_vdvi_supply,
277 static const struct twl4030_resconfig touchbook_resconfig[] = {
278 /* disable regulators that u-boot left enabled; the
279 * devices' drivers should be managing these.
281 { .resource = RES_VAUX3, }, /* not even connected! */
282 { .resource = RES_VMMC1, },
283 { .resource = RES_VSIM, },
284 { .resource = RES_VPLL2, },
285 { .resource = RES_VDAC, },
286 { .resource = RES_VUSB_1V5, },
287 { .resource = RES_VUSB_1V8, },
288 { .resource = RES_VUSB_3V1, },
292 static struct twl4030_power_data touchbook_power_data = {
293 .resource_config = touchbook_resconfig,
294 /* REVISIT can't use GENERIC3430_T2SCRIPTS_DATA;
295 * among other things, it makes reboot fail.
299 static struct twl4030_bci_platform_data touchbook_bci_data = {
301 .no_backup_battery = 1,
304 static struct twl4030_madc_platform_data touchbook_madc_data = {
308 static struct twl4030_platform_data touchbook_twldata = {
309 .irq_base = TWL4030_IRQ_BASE,
310 .irq_end = TWL4030_IRQ_END,
312 /* platform_data for children goes here */
313 .usb = &touchbook_usb_data,
314 .gpio = &touchbook_gpio_data,
315 .power = &touchbook_power_data,
316 .vmmc1 = &touchbook_vmmc1,
317 .vsim = &touchbook_vsim,
318 .vdac = &touchbook_vdac,
319 .vpll2 = &touchbook_vpll2,
322 .bci = &touchbook_bci_data,
323 .madc = &touchbook_madc_data,
326 static struct i2c_board_info __initdata touchbook_i2c_boardinfo[] = {
328 I2C_BOARD_INFO("twl4030", 0x48),
329 .flags = I2C_CLIENT_WAKE,
330 .irq = INT_34XX_SYS_NIRQ,
331 .platform_data = &touchbook_twldata,
335 static struct i2c_board_info __initdata touchBook_i2c_boardinfo[] = {
337 I2C_BOARD_INFO("bq27200", 0x55),
340 // I2C_BOARD_INFO("chacha_mt8c", 0x40),
341 // .irq = OMAP_GPIO_IRQ(OMAP3_CHACHA_GPIO),
345 static void __init omap3_touchbook_i2c_init(void)
349 /* Standard TouchBook bus */
350 omap_register_i2c_bus(1, 2600, touchbook_i2c_boardinfo,
351 ARRAY_SIZE(touchbook_i2c_boardinfo));
353 /* Additional TouchBook bus */
354 omap_register_i2c_bus(3, 100, touchBook_i2c_boardinfo,
355 ARRAY_SIZE(touchBook_i2c_boardinfo));
357 /* ret = gpio_request(OMAP3_CHACHA_GPIO, "chacha_mt8c");
359 printk(KERN_ERR "Failed to request GPIO %d for chacha_mt8c IRQ\n", OMAP3_CHACHA_GPIO);
363 gpio_direction_input(OMAP3_CHACHA_GPIO);*/
367 static void __init omap3_ads7846_init(void)
369 if (gpio_request(OMAP3_TS_GPIO, "ads7846_pen_down")) {
370 printk(KERN_ERR "Failed to request GPIO %d for "
371 "ads7846 pen down IRQ\n", OMAP3_TS_GPIO);
375 gpio_direction_input(OMAP3_TS_GPIO);
376 omap_set_gpio_debounce(OMAP3_TS_GPIO, 1);
377 omap_set_gpio_debounce_time(OMAP3_TS_GPIO, 0xa);
380 static struct ads7846_platform_data ads7846_config = {
390 .gpio_pendown = OMAP3_TS_GPIO,
394 static struct omap2_mcspi_device_config ads7846_mcspi_config = {
396 .single_channel = 1, /* 0: slave, 1: master */
399 static struct spi_board_info omap3_ads7846_spi_board_info[] __initdata = {
401 .modalias = "ads7846",
404 .max_speed_hz = 1500000,
405 .controller_data = &ads7846_mcspi_config, //(void *) 161,
406 .irq = OMAP_GPIO_IRQ(OMAP3_TS_GPIO),
407 .platform_data = &ads7846_config,
411 static void __init omap3_touchbook_init_irq(void)
413 omap2_init_common_hw(mt46h32m32lf6_sdrc_params, omap3_mpu_rate_table,
414 omap3_dsp_rate_table, omap3_l3_rate_table);
419 static struct gpio_led gpio_leds[] = {
421 .name = "touchbook::usr0",
422 .default_trigger = "heartbeat",
426 .name = "touchbook::usr1",
427 .default_trigger = "mmc0",
431 .name = "touchbook::pmu_stat",
432 .gpio = -EINVAL, /* gets replaced */
437 static struct gpio_led_platform_data gpio_led_info = {
439 .num_leds = ARRAY_SIZE(gpio_leds),
442 static struct platform_device leds_gpio = {
446 .platform_data = &gpio_led_info,
450 static struct gpio_keys_button gpio_buttons[] = {
466 static struct gpio_keys_platform_data gpio_key_info = {
467 .buttons = gpio_buttons,
468 .nbuttons = ARRAY_SIZE(gpio_buttons),
471 static struct platform_device keys_gpio = {
475 .platform_data = &gpio_key_info,
481 static int touchbook_enable_dvi(struct omap_display *display)
483 if (display->hw_config.panel_reset_gpio != -1)
484 gpio_set_value(display->hw_config.panel_reset_gpio, 1);
489 static void touchbook_disable_dvi(struct omap_display *display)
491 if (display->hw_config.panel_reset_gpio != -1)
492 gpio_set_value(display->hw_config.panel_reset_gpio, 0);
495 static struct omap_dss_display_config touchbook_display_data_dvi = {
496 .type = OMAP_DISPLAY_TYPE_DPI,
498 .panel_name = "panel-generic",
499 .u.dpi.data_lines = 24,
500 .panel_reset_gpio = 176,
501 .panel_enable = touchbook_enable_dvi,
502 .panel_disable = touchbook_disable_dvi,
506 static int touchbook_panel_enable_tv(struct omap_display *display)
508 #define ENABLE_VDAC_DEDICATED 0x03
509 #define ENABLE_VDAC_DEV_GRP 0x20
511 twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
512 ENABLE_VDAC_DEDICATED,
513 TWL4030_VDAC_DEDICATED);
514 twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
515 ENABLE_VDAC_DEV_GRP, TWL4030_VDAC_DEV_GRP);
520 static void touchbook_panel_disable_tv(struct omap_display *display)
522 twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER, 0x00,
523 TWL4030_VDAC_DEDICATED);
524 twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER, 0x00,
525 TWL4030_VDAC_DEV_GRP);
528 static struct omap_dss_display_config touchbook_display_data_tv = {
529 .type = OMAP_DISPLAY_TYPE_VENC,
531 .u.venc.type = OMAP_DSS_VENC_TYPE_SVIDEO,
532 .panel_enable = touchbook_panel_enable_tv,
533 .panel_disable = touchbook_panel_disable_tv,
536 static struct omap_dss_board_info touchbook_dss_data = {
539 &touchbook_display_data_dvi,
540 &touchbook_display_data_tv,
544 static struct platform_device touchbook_dss_device = {
548 .platform_data = &touchbook_dss_data,
552 static void __init touchbook_display_init(void)
556 r = gpio_request(touchbook_display_data_dvi.panel_reset_gpio, "DVI reset");
558 printk(KERN_ERR "Unable to get DVI reset GPIO\n");
562 gpio_direction_output(touchbook_display_data_dvi.panel_reset_gpio, 0);
565 static struct omap_board_config_kernel omap3_touchbook_config[] __initdata = {
566 { OMAP_TAG_UART, &omap3_touchbook_uart_config },
569 static struct platform_device *omap3_touchbook_devices[] __initdata = {
570 &touchbook_dss_device,
575 static void __init omap3touchbook_flash_init(void)
578 u8 nandcs = GPMC_CS_NUM + 1;
580 u32 gpmc_base_add = OMAP34XX_GPMC_VIRT;
582 /* find out the chip-select on which NAND exists */
583 while (cs < GPMC_CS_NUM) {
585 ret = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG1);
587 if ((ret & 0xC00) == 0x800) {
588 printk(KERN_INFO "Found NAND on CS%d\n", cs);
589 if (nandcs > GPMC_CS_NUM)
595 if (nandcs > GPMC_CS_NUM) {
596 printk(KERN_INFO "NAND: Unable to find configuration "
601 if (nandcs < GPMC_CS_NUM) {
602 omap3touchbook_nand_data.cs = nandcs;
603 omap3touchbook_nand_data.gpmc_cs_baseaddr = (void *)
604 (gpmc_base_add + GPMC_CS0_BASE + nandcs * GPMC_CS_SIZE);
605 omap3touchbook_nand_data.gpmc_baseaddr = (void *) (gpmc_base_add);
607 printk(KERN_INFO "Registering NAND on CS%d\n", nandcs);
608 if (platform_device_register(&omap3touchbook_nand_device) < 0)
609 printk(KERN_ERR "Unable to register NAND device\n");
613 static void __init omap3_mma7455l_init(void)
617 ret = gpio_request(OMAP3_AC_GPIO, "mma7455l");
619 printk(KERN_ERR "Failed to request GPIO %d for mma7455l IRQ\n", OMAP3_AC_GPIO);
623 gpio_direction_input(OMAP3_AC_GPIO);
626 static struct mma7455l_platform_data mma7455l_config = {
627 .calibration_x = -4, //26 for Beagleboard
628 .calibration_y = 28, //44 for Beagleboard
629 .calibration_z = -28, //26 for Beagleboard
632 static struct omap2_mcspi_device_config mma7455l_mcspi_config = {
634 .single_channel = 1, /* 0: slave, 1: master */
637 static struct spi_board_info omap3_mma7455l_spi_board_info[] __initdata = {
639 .modalias = "mma7455l",
642 .max_speed_hz = 200000,
643 .irq = OMAP_GPIO_IRQ(OMAP3_AC_GPIO),
644 .controller_data = &mma7455l_mcspi_config, //(void *) 135,
645 .platform_data = &mma7455l_config,
649 static int touchbook_backlight_brightness = 50;
650 static struct omap_dm_timer *touchbook_backlight_pwm;
652 static int touchbook_backlight_read(struct backlight_device *bd)
654 return touchbook_backlight_brightness;
657 static int touchbook_backlight_update(struct backlight_device *bd)
659 int value = bd->props.brightness;
660 touchbook_backlight_brightness = value;
662 /* Frequency calculation:
663 - For 200Hz PWM, you want to load -164 (=> -32768Hz / 200Hz).
664 - Minimum duty cycle for the backlight is 15%.
665 - You have (164*0.85) => ~140 levels of brightness.
668 /* Halve input brightness */
671 /* For maximum brightness, just stop the timer... */
672 if(value != bd->props.max_brightness)
674 /* Load the appropriate value for 200Hz PWM */
675 u32 period = clk_get_rate(omap_dm_timer_get_fclk(touchbook_backlight_pwm)) / 200;
677 /* Minimum duty cycle is 15% */
678 u32 minimum = (period * 3) / 20;
679 u32 maximum = (period * 17) / 20;
681 /* Work out match value */
682 u32 match = (maximum * value) / 100;
685 omap_dm_timer_set_load(touchbook_backlight_pwm, 1, 0xFFFFFFFF - period - 1);
686 omap_dm_timer_set_match(touchbook_backlight_pwm, 1, 0xFFFFFFFF - minimum - match);
687 omap_dm_timer_write_counter(touchbook_backlight_pwm, -1);
688 //omap_dm_timer_stop(touchbook_backlight_pwm);
689 omap_dm_timer_start(touchbook_backlight_pwm);
692 omap_dm_timer_stop(touchbook_backlight_pwm);
698 static struct backlight_ops touchbook_backlight_properties = {
699 .get_brightness = touchbook_backlight_read,
700 .update_status = touchbook_backlight_update,
703 static void __init omap3_touchbook_backlight_init(void)
705 static struct backlight_device *bd;
706 bd = backlight_device_register("touchbook", NULL, NULL, &touchbook_backlight_properties);
710 touchbook_backlight_pwm = omap_dm_timer_request_specific(TB_BL_PWM_TIMER);
711 omap_dm_timer_enable(touchbook_backlight_pwm);
712 omap_dm_timer_set_source(touchbook_backlight_pwm, OMAP_TIMER_SRC_SYS_CLK);
713 omap_dm_timer_set_pwm(touchbook_backlight_pwm, 1, 1, OMAP_TIMER_TRIGGER_OVERFLOW_AND_COMPARE);
715 bd->props.max_brightness = 100;
716 bd->props.brightness = touchbook_backlight_brightness;
719 touchbook_backlight_update(bd);
722 static void omap3_touchbook_poweroff(void)
726 r = gpio_request(TB_KILL_POWER_GPIO, "DVI reset");
728 printk(KERN_ERR "Unable to get kill power GPIO\n");
732 gpio_direction_output(TB_KILL_POWER_GPIO, 0);
735 static int __init ai_revision_instance(char *str)
740 ai_revision = simple_strtoul(str, NULL, 10);
745 static void __init omap3_touchbook_init(void)
747 pm_power_off = omap3_touchbook_poweroff;
749 omap3_touchbook_i2c_init();
750 platform_add_devices(omap3_touchbook_devices,
751 ARRAY_SIZE(omap3_touchbook_devices));
752 omap_board_config = omap3_touchbook_config;
753 omap_board_config_size = ARRAY_SIZE(omap3_touchbook_config);
756 omap_cfg_reg(J25_34XX_GPIO170);
758 omap3touchbook_flash_init();
759 touchbook_display_init();
760 omap3_touchbook_backlight_init();
763 spi_register_board_info(omap3_ads7846_spi_board_info, ARRAY_SIZE(omap3_ads7846_spi_board_info));
764 spi_register_board_info(omap3_mma7455l_spi_board_info, ARRAY_SIZE(omap3_mma7455l_spi_board_info));
766 omap3_ads7846_init();
767 omap3_mma7455l_init();
773 static void __init omap3_touchbook_map_io(void)
775 omap2_set_globals_343x();
776 omap2_map_common_io();
779 early_param("air", ai_revision_instance);
781 MACHINE_START(OMAP3_TOUCHBOOK, "OMAP3 Touch Book")
782 /* Maintainer: Gregoire Gentil - http://www.alwaysinnovating.com */
783 .phys_io = 0x48000000,
784 .io_pg_offst = ((0xd8000000) >> 18) & 0xfffc,
785 .boot_params = 0x80000100,
786 .map_io = omap3_touchbook_map_io,
787 .init_irq = omap3_touchbook_init_irq,
788 .init_machine = omap3_touchbook_init,
789 .timer = &omap_timer,